Class: Zernio::ProductsApi

Inherits:
Object
  • Object
show all
Defined in:
lib/zernio-sdk/api/products_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ ProductsApi

Returns a new instance of ProductsApi.



19
20
21
# File 'lib/zernio-sdk/api/products_api.rb', line 19

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/zernio-sdk/api/products_api.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#get_product(account_id, product_id, opts = {}) ⇒ GetProduct200Response

Get a product Fetches a single product with its variants, options and images. productId is the platform's numeric product id from GET /v1/accounts/{accountId}/products, not a Zernio id. Supported on Shopify (platform shopify); accounts on other platforms return 400.

Parameters:

  • account_id (String)

    Connected Shopify SocialAccount id.

  • product_id (String)

    Platform-native numeric product id. Non-numeric values return 400.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



28
29
30
31
# File 'lib/zernio-sdk/api/products_api.rb', line 28

def get_product(, product_id, opts = {})
  data, _status_code, _headers = get_product_with_http_info(, product_id, opts)
  data
end

#get_product_with_http_info(account_id, product_id, opts = {}) ⇒ Array<(GetProduct200Response, Integer, Hash)>

Get a product Fetches a single product with its variants, options and images. `productId` is the platform's numeric product id from `GET /v1/accounts/accountId/products`, not a Zernio id. Supported on Shopify (platform `shopify`); accounts on other platforms return 400.

Parameters:

  • account_id (String)

    Connected Shopify SocialAccount id.

  • product_id (String)

    Platform-native numeric product id. Non-numeric values return 400.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(GetProduct200Response, Integer, Hash)>)

    GetProduct200Response data, response status code and response headers



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/zernio-sdk/api/products_api.rb', line 39

def get_product_with_http_info(, product_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ProductsApi.get_product ...'
  end
  # verify the required parameter 'account_id' is set
  if @api_client.config.client_side_validation && .nil?
    fail ArgumentError, "Missing the required parameter 'account_id' when calling ProductsApi.get_product"
  end
  # verify the required parameter 'product_id' is set
  if @api_client.config.client_side_validation && product_id.nil?
    fail ArgumentError, "Missing the required parameter 'product_id' when calling ProductsApi.get_product"
  end
  pattern = Regexp.new(/^\d+$/)
  if @api_client.config.client_side_validation && product_id !~ pattern
    fail ArgumentError, "invalid value for 'product_id' when calling ProductsApi.get_product, must conform to the pattern #{pattern}."
  end

  # resource path
  local_var_path = '/v1/accounts/{accountId}/products/{productId}'.sub('{' + 'accountId' + '}', CGI.escape(.to_s)).sub('{' + 'productId' + '}', CGI.escape(product_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'GetProduct200Response'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['bearerAuth']

  new_options = opts.merge(
    :operation => :"ProductsApi.get_product",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ProductsApi#get_product\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#list_products(account_id, opts = {}) ⇒ ListProducts200Response

List products Lists the products on the connected store in the platform's default order, each with its variants, options and images. Cursor-paginated: pass limit (1-50, default 20) and the cursor from a previous response's nextCursor; nextCursor is null when there are no more pages. Filter with status and/or query (the platform's product search syntax, e.g. title:*shirt* vendor:Acme tag:summer). Supported on Shopify (platform shopify); accounts on other platforms return 400. A store connected before product access was added answers 403 insufficient_permissions until the merchant reconnects it through GET /v1/connect/shopify.

Parameters:

  • account_id (String)

    Connected Shopify SocialAccount id.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :limit (Integer)

    Page size (1-50). (default to 20)

  • :cursor (String)

    Opaque cursor from a previous response. Omit for the first page.

  • :status (String)

    Only products in this status.

  • :query (String)

    Platform product search syntax, passed through verbatim (Shopify: title, vendor, product_type, tag, sku, handle, created_at, updated_at, ...).

Returns:



105
106
107
108
# File 'lib/zernio-sdk/api/products_api.rb', line 105

def list_products(, opts = {})
  data, _status_code, _headers = list_products_with_http_info(, opts)
  data
end

#list_products_with_http_info(account_id, opts = {}) ⇒ Array<(ListProducts200Response, Integer, Hash)>

List products Lists the products on the connected store in the platform's default order, each with its variants, options and images. Cursor-paginated: pass `limit` (1-50, default 20) and the `cursor` from a previous response's `nextCursor`; `nextCursor` is null when there are no more pages. Filter with `status` and/or `query` (the platform's product search syntax, e.g. `title:shirt vendor:Acme tag:summer`). Supported on Shopify (platform `shopify`); accounts on other platforms return 400. A store connected before product access was added answers 403 insufficient_permissions until the merchant reconnects it through `GET /v1/connect/shopify`.

Parameters:

  • account_id (String)

    Connected Shopify SocialAccount id.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :limit (Integer)

    Page size (1-50). (default to 20)

  • :cursor (String)

    Opaque cursor from a previous response. Omit for the first page.

  • :status (String)

    Only products in this status.

  • :query (String)

    Platform product search syntax, passed through verbatim (Shopify: title, vendor, product_type, tag, sku, handle, created_at, updated_at, ...).

Returns:

  • (Array<(ListProducts200Response, Integer, Hash)>)

    ListProducts200Response data, response status code and response headers



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/zernio-sdk/api/products_api.rb', line 119

def list_products_with_http_info(, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ProductsApi.list_products ...'
  end
  # verify the required parameter 'account_id' is set
  if @api_client.config.client_side_validation && .nil?
    fail ArgumentError, "Missing the required parameter 'account_id' when calling ProductsApi.list_products"
  end
  if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] > 50
    fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling ProductsApi.list_products, must be smaller than or equal to 50.'
  end

  if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] < 1
    fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling ProductsApi.list_products, must be greater than or equal to 1.'
  end

  allowable_values = ["active", "draft", "archived"]
  if @api_client.config.client_side_validation && opts[:'status'] && !allowable_values.include?(opts[:'status'])
    fail ArgumentError, "invalid value for \"status\", must be one of #{allowable_values}"
  end
  if @api_client.config.client_side_validation && !opts[:'query'].nil? && opts[:'query'].to_s.length > 500
    fail ArgumentError, 'invalid value for "opts[:"query"]" when calling ProductsApi.list_products, the character length must be smaller than or equal to 500.'
  end

  # resource path
  local_var_path = '/v1/accounts/{accountId}/products'.sub('{' + 'accountId' + '}', CGI.escape(.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
  query_params[:'cursor'] = opts[:'cursor'] if !opts[:'cursor'].nil?
  query_params[:'status'] = opts[:'status'] if !opts[:'status'].nil?
  query_params[:'query'] = opts[:'query'] if !opts[:'query'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'ListProducts200Response'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['bearerAuth']

  new_options = opts.merge(
    :operation => :"ProductsApi.list_products",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ProductsApi#list_products\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#update_product(account_id, product_id, update_product_request, opts = {}) ⇒ GetProduct200Response

Update a product Partial-updates a product. Send any subset of title, descriptionHtml, handle, vendor, productType, tags, status, seo and variants; at least one field is required (an empty body returns 400). tags replaces the full tag list. variants updates the price and compare-at price of the listed variant ids only; other variants are untouched, and a variant id that does not belong to the product is a 400. Responds with the product as it is after the update. Supported on Shopify (platform shopify); accounts on other platforms return 400. A store connected before product access was added answers 403 insufficient_permissions until the merchant reconnects it through GET /v1/connect/shopify.

Parameters:

  • account_id (String)

    Connected Shopify SocialAccount id.

  • product_id (String)

    Platform-native numeric product id. Non-numeric values return 400.

  • update_product_request (UpdateProductRequest)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



194
195
196
197
# File 'lib/zernio-sdk/api/products_api.rb', line 194

def update_product(, product_id, update_product_request, opts = {})
  data, _status_code, _headers = update_product_with_http_info(, product_id, update_product_request, opts)
  data
end

#update_product_with_http_info(account_id, product_id, update_product_request, opts = {}) ⇒ Array<(GetProduct200Response, Integer, Hash)>

Update a product Partial-updates a product. Send any subset of `title`, `descriptionHtml`, `handle`, `vendor`, `productType`, `tags`, `status`, `seo` and `variants`; at least one field is required (an empty body returns 400). `tags` replaces the full tag list. `variants` updates the price and compare-at price of the listed variant ids only; other variants are untouched, and a variant id that does not belong to the product is a 400. Responds with the product as it is after the update. Supported on Shopify (platform `shopify`); accounts on other platforms return 400. A store connected before product access was added answers 403 insufficient_permissions until the merchant reconnects it through `GET /v1/connect/shopify`.

Parameters:

  • account_id (String)

    Connected Shopify SocialAccount id.

  • product_id (String)

    Platform-native numeric product id. Non-numeric values return 400.

  • update_product_request (UpdateProductRequest)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(GetProduct200Response, Integer, Hash)>)

    GetProduct200Response data, response status code and response headers



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/zernio-sdk/api/products_api.rb', line 206

def update_product_with_http_info(, product_id, update_product_request, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ProductsApi.update_product ...'
  end
  # verify the required parameter 'account_id' is set
  if @api_client.config.client_side_validation && .nil?
    fail ArgumentError, "Missing the required parameter 'account_id' when calling ProductsApi.update_product"
  end
  # verify the required parameter 'product_id' is set
  if @api_client.config.client_side_validation && product_id.nil?
    fail ArgumentError, "Missing the required parameter 'product_id' when calling ProductsApi.update_product"
  end
  pattern = Regexp.new(/^\d+$/)
  if @api_client.config.client_side_validation && product_id !~ pattern
    fail ArgumentError, "invalid value for 'product_id' when calling ProductsApi.update_product, must conform to the pattern #{pattern}."
  end

  # verify the required parameter 'update_product_request' is set
  if @api_client.config.client_side_validation && update_product_request.nil?
    fail ArgumentError, "Missing the required parameter 'update_product_request' when calling ProductsApi.update_product"
  end
  # resource path
  local_var_path = '/v1/accounts/{accountId}/products/{productId}'.sub('{' + 'accountId' + '}', CGI.escape(.to_s)).sub('{' + 'productId' + '}', CGI.escape(product_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(update_product_request)

  # return_type
  return_type = opts[:debug_return_type] || 'GetProduct200Response'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['bearerAuth']

  new_options = opts.merge(
    :operation => :"ProductsApi.update_product",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:PATCH, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ProductsApi#update_product\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end