UNPKG

square-connect

Version:

JavaScript client library for the Square Connect v2 API

308 lines (259 loc) 11.3 kB
/** * Square Connect API * Client library for accessing the Square Connect APIs * * OpenAPI spec version: 2.0 * Contact: developers@squareup.com * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * * Swagger Codegen version: 2.3.0-SNAPSHOT * */ var ApiClient = require('../ApiClient'); var CreateCustomerGroupRequest = require('../model/CreateCustomerGroupRequest'); var CreateCustomerGroupResponse = require('../model/CreateCustomerGroupResponse'); var DeleteCustomerGroupResponse = require('../model/DeleteCustomerGroupResponse'); var ListCustomerGroupsResponse = require('../model/ListCustomerGroupsResponse'); var RetrieveCustomerGroupResponse = require('../model/RetrieveCustomerGroupResponse'); var UpdateCustomerGroupRequest = require('../model/UpdateCustomerGroupRequest'); var UpdateCustomerGroupResponse = require('../model/UpdateCustomerGroupResponse'); /** * CustomerGroups service. * @module api/CustomerGroupsApi */ /** * Constructs a new CustomerGroupsApi. * @alias module:api/CustomerGroupsApi * @class * @param {module:ApiClient} apiClient Optional API client implementation to use, * default to {@link module:ApiClient#instance} if unspecified. */ module.exports = function(apiClient) { this.apiClient = apiClient || ApiClient.instance; /** * CreateCustomerGroup * Creates a new customer group for a business. The request must include the `name` value of the group. * @param {module:model/CreateCustomerGroupRequest} body An object containing the fields to POST for the request. See the corresponding object definition for field details. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/CreateCustomerGroupResponse} and HTTP response */ this.createCustomerGroupWithHttpInfo = function(body) { var postBody = body; // verify the required parameter 'body' is set if (body === undefined || body === null) { throw new Error("Missing the required parameter 'body' when calling createCustomerGroup"); } var pathParams = { }; var queryParams = { }; var headerParams = { }; headerParams['Square-Version'] = '2020-12-16'; var formParams = { }; var authNames = ['oauth2']; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = CreateCustomerGroupResponse; return this.apiClient.callApi( '/v2/customers/groups', 'POST', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * CreateCustomerGroup * Creates a new customer group for a business. The request must include the `name` value of the group. * @param {module:model/CreateCustomerGroupRequest} body An object containing the fields to POST for the request. See the corresponding object definition for field details. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/CreateCustomerGroupResponse} */ this.createCustomerGroup = function(body) { return this.createCustomerGroupWithHttpInfo(body) .then(function(response_and_data) { return response_and_data.data; }); } /** * DeleteCustomerGroup * Deletes a customer group as identified by the `group_id` value. * @param {String} groupId The ID of the customer group to delete. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/DeleteCustomerGroupResponse} and HTTP response */ this.deleteCustomerGroupWithHttpInfo = function(groupId) { var postBody = null; // verify the required parameter 'groupId' is set if (groupId === undefined || groupId === null) { throw new Error("Missing the required parameter 'groupId' when calling deleteCustomerGroup"); } var pathParams = { 'group_id': groupId }; var queryParams = { }; var headerParams = { }; headerParams['Square-Version'] = '2020-12-16'; var formParams = { }; var authNames = ['oauth2']; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = DeleteCustomerGroupResponse; return this.apiClient.callApi( '/v2/customers/groups/{group_id}', 'DELETE', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * DeleteCustomerGroup * Deletes a customer group as identified by the `group_id` value. * @param {String} groupId The ID of the customer group to delete. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/DeleteCustomerGroupResponse} */ this.deleteCustomerGroup = function(groupId) { return this.deleteCustomerGroupWithHttpInfo(groupId) .then(function(response_and_data) { return response_and_data.data; }); } /** * ListCustomerGroups * Retrieves the list of customer groups of a business. * @param {Object} opts Optional parameters * @param {String} opts.cursor A pagination cursor returned by a previous call to this endpoint. Provide this to retrieve the next set of results for your original query. See the [Pagination guide](https://developer.squareup.com/docs/working-with-apis/pagination) for more information. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/ListCustomerGroupsResponse} and HTTP response */ this.listCustomerGroupsWithHttpInfo = function(opts) { opts = opts || {}; var postBody = null; var pathParams = { }; var queryParams = { 'cursor': opts['cursor'] }; var headerParams = { }; headerParams['Square-Version'] = '2020-12-16'; var formParams = { }; var authNames = ['oauth2']; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = ListCustomerGroupsResponse; return this.apiClient.callApi( '/v2/customers/groups', 'GET', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * ListCustomerGroups * Retrieves the list of customer groups of a business. * @param {Object} opts Optional parameters * @param {String} opts.cursor A pagination cursor returned by a previous call to this endpoint. Provide this to retrieve the next set of results for your original query. See the [Pagination guide](https://developer.squareup.com/docs/working-with-apis/pagination) for more information. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/ListCustomerGroupsResponse} */ this.listCustomerGroups = function(opts) { return this.listCustomerGroupsWithHttpInfo(opts) .then(function(response_and_data) { return response_and_data.data; }); } /** * RetrieveCustomerGroup * Retrieves a specific customer group as identified by the `group_id` value. * @param {String} groupId The ID of the customer group to retrieve. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/RetrieveCustomerGroupResponse} and HTTP response */ this.retrieveCustomerGroupWithHttpInfo = function(groupId) { var postBody = null; // verify the required parameter 'groupId' is set if (groupId === undefined || groupId === null) { throw new Error("Missing the required parameter 'groupId' when calling retrieveCustomerGroup"); } var pathParams = { 'group_id': groupId }; var queryParams = { }; var headerParams = { }; headerParams['Square-Version'] = '2020-12-16'; var formParams = { }; var authNames = ['oauth2']; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = RetrieveCustomerGroupResponse; return this.apiClient.callApi( '/v2/customers/groups/{group_id}', 'GET', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * RetrieveCustomerGroup * Retrieves a specific customer group as identified by the `group_id` value. * @param {String} groupId The ID of the customer group to retrieve. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/RetrieveCustomerGroupResponse} */ this.retrieveCustomerGroup = function(groupId) { return this.retrieveCustomerGroupWithHttpInfo(groupId) .then(function(response_and_data) { return response_and_data.data; }); } /** * UpdateCustomerGroup * Updates a customer group as identified by the `group_id` value. * @param {String} groupId The ID of the customer group to update. * @param {module:model/UpdateCustomerGroupRequest} body An object containing the fields to POST for the request. See the corresponding object definition for field details. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/UpdateCustomerGroupResponse} and HTTP response */ this.updateCustomerGroupWithHttpInfo = function(groupId, body) { var postBody = body; // verify the required parameter 'groupId' is set if (groupId === undefined || groupId === null) { throw new Error("Missing the required parameter 'groupId' when calling updateCustomerGroup"); } // verify the required parameter 'body' is set if (body === undefined || body === null) { throw new Error("Missing the required parameter 'body' when calling updateCustomerGroup"); } var pathParams = { 'group_id': groupId }; var queryParams = { }; var headerParams = { }; headerParams['Square-Version'] = '2020-12-16'; var formParams = { }; var authNames = ['oauth2']; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = UpdateCustomerGroupResponse; return this.apiClient.callApi( '/v2/customers/groups/{group_id}', 'PUT', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * UpdateCustomerGroup * Updates a customer group as identified by the `group_id` value. * @param {String} groupId The ID of the customer group to update. * @param {module:model/UpdateCustomerGroupRequest} body An object containing the fields to POST for the request. See the corresponding object definition for field details. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/UpdateCustomerGroupResponse} */ this.updateCustomerGroup = function(groupId, body) { return this.updateCustomerGroupWithHttpInfo(groupId, body) .then(function(response_and_data) { return response_and_data.data; }); } };