flowcommerce 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,4 @@
1
1
  dir = File.dirname(__FILE__)
2
2
 
3
- load File.join(dir, 'clients/flow_common_v0_client.rb')
4
- load File.join(dir, 'clients/flow_catalog_v0_client.rb')
5
- load File.join(dir, 'clients/flow_experience_v0_client.rb')
6
-
3
+ load File.join(dir, 'flow_commerce/flow_api_v0_client.rb')
7
4
  load File.join(dir, 'flow_commerce/client.rb')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flowcommerce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flow Commerce, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-29 00:00:00.000000000 Z
11
+ date: 2016-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -45,10 +45,8 @@ extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
47
  - README.md
48
- - lib/clients/flow_catalog_v0_client.rb
49
- - lib/clients/flow_common_v0_client.rb
50
- - lib/clients/flow_experience_v0_client.rb
51
48
  - lib/flow_commerce/client.rb
49
+ - lib/flow_commerce/flow_api_v0_client.rb
52
50
  - lib/flowcommerce.rb
53
51
  homepage: https://github.com/flowcommerce/ruby-sdk
54
52
  licenses:
@@ -1,2264 +0,0 @@
1
- # Generated by apidoc - http://www.apidoc.me
2
- # Service version: 0.0.36
3
- # apidoc:0.11.29 http://www.apidoc.me/flow/catalog/0.0.36/ruby_client
4
-
5
- require 'cgi'
6
- require 'net/http'
7
- require 'net/https'
8
- require 'uri'
9
- require 'base64'
10
-
11
- require 'date'
12
- require 'rubygems'
13
- require 'json'
14
- require 'bigdecimal'
15
-
16
- # API to the product catalog, defining the master catalog and all of the
17
- # subcatalogs used to target specific subsets of the inventory to experiences.
18
- module Io
19
- module Flow
20
- module Catalog
21
- module V0
22
-
23
- class Client
24
-
25
- module Constants
26
-
27
- BASE_URL = 'https://catalog.api.flow.io' unless defined?(Constants::BASE_URL)
28
- NAMESPACE = 'io.flow.catalog.v0' unless defined?(Constants::NAMESPACE)
29
- USER_AGENT = 'apidoc:0.11.29 http://www.apidoc.me/flow/catalog/0.0.36/ruby_client' unless defined?(Constants::USER_AGENT)
30
- VERSION = '0.0.36' unless defined?(Constants::VERSION)
31
- VERSION_MAJOR = 0 unless defined?(VERSION_MAJOR)
32
-
33
- end
34
-
35
- attr_reader :url
36
-
37
- def initialize(url, opts={})
38
- @url = HttpClient::Preconditions.assert_class('url', url, String)
39
- @authorization = HttpClient::Preconditions.assert_class_or_nil('authorization', opts.delete(:authorization), HttpClient::Authorization)
40
- @default_headers = HttpClient::Preconditions.assert_class('default_headers', opts.delete(:default_headers) || {}, Hash)
41
- HttpClient::Preconditions.assert_empty_opts(opts)
42
- HttpClient::Preconditions.check_state(url.match(/http.+/i), "URL[%s] must start with http" % url)
43
- end
44
-
45
- # Creates an instance of the client using the base url specified in the API spec.
46
- def Client.at_base_url(opts={})
47
- Client.new(Constants::BASE_URL, opts)
48
- end
49
-
50
- def request(path=nil)
51
- HttpClient::Preconditions.assert_class_or_nil('path', path, String)
52
- request = HttpClient::Request.new(URI.parse(@url + path.to_s)).with_header('User-Agent', Constants::USER_AGENT).with_header('X-Apidoc-Version', Constants::VERSION).with_header('X-Apidoc-Version-Major', Constants::VERSION_MAJOR)
53
-
54
- @default_headers.each do |key, value|
55
- request = request.with_header(key, value)
56
- end
57
-
58
- if @authorization
59
- request = request.with_auth(@authorization)
60
- end
61
-
62
- request
63
- end
64
-
65
- def attributes
66
- @attributes ||= ::Io::Flow::Catalog::V0::Clients::Attributes.new(self)
67
- end
68
-
69
- def catalogs
70
- @catalogs ||= ::Io::Flow::Catalog::V0::Clients::Catalogs.new(self)
71
- end
72
-
73
- def functions
74
- @functions ||= ::Io::Flow::Catalog::V0::Clients::Functions.new(self)
75
- end
76
-
77
- def items
78
- @items ||= ::Io::Flow::Catalog::V0::Clients::Items.new(self)
79
- end
80
-
81
- def subcatalogs
82
- @subcatalogs ||= ::Io::Flow::Catalog::V0::Clients::Subcatalogs.new(self)
83
- end
84
-
85
- def subcatalog_items
86
- @subcatalog_items ||= ::Io::Flow::Catalog::V0::Clients::SubcatalogItems.new(self)
87
- end
88
- end
89
-
90
- module Clients
91
-
92
- class Attributes
93
-
94
- def initialize(client)
95
- @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Catalog::V0::Client)
96
- end
97
-
98
- # Provides visibility into recent changes of each object, including deletion
99
- def get_versions(organization, incoming={})
100
- HttpClient::Preconditions.assert_class('organization', organization, String)
101
- opts = HttpClient::Helper.symbolize_keys(incoming)
102
- query = {
103
- :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
104
- :name => (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, Array).map { |v| HttpClient::Preconditions.assert_class('name', v, String) }),
105
- :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
106
- :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
107
- :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "journal_timestamp" : x), String)
108
- }.delete_if { |k, v| v.nil? }
109
- r = @client.request("/#{CGI.escape(organization)}/attributes/versions").with_query(query).get
110
- r.map { |x| ::Io::Flow::Catalog::V0::Models::AttributeVersion.new(x) }
111
- end
112
-
113
- # Search metadata. Always paginated.
114
- def get(organization, incoming={})
115
- HttpClient::Preconditions.assert_class('organization', organization, String)
116
- opts = HttpClient::Helper.symbolize_keys(incoming)
117
- query = {
118
- :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
119
- :name => (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, Array).map { |v| HttpClient::Preconditions.assert_class('name', v, String) }),
120
- :option => (x = opts.delete(:option); x.nil? ? nil : HttpClient::Preconditions.assert_class('option', x, Array).map { |v| HttpClient::Preconditions.assert_class('option', v, String) }),
121
- :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
122
- :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
123
- :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "name" : x), String)
124
- }.delete_if { |k, v| v.nil? }
125
- r = @client.request("/#{CGI.escape(organization)}/attributes").with_query(query).get
126
- r.map { |x| ::Io::Flow::Catalog::V0::Models::Attribute.new(x) }
127
- end
128
-
129
- # Returns information about a specific attribute.
130
- def get_by_name(organization, name)
131
- HttpClient::Preconditions.assert_class('organization', organization, String)
132
- HttpClient::Preconditions.assert_class('name', name, String)
133
- r = @client.request("/#{CGI.escape(organization)}/attributes/#{CGI.escape(name)}").get
134
- ::Io::Flow::Catalog::V0::Models::Attribute.new(r)
135
- end
136
-
137
- # Add attribute
138
- def post(organization, attribute)
139
- HttpClient::Preconditions.assert_class('organization', organization, String)
140
- HttpClient::Preconditions.assert_class('attribute', attribute, ::Io::Flow::Catalog::V0::Models::Attribute)
141
- r = @client.request("/#{CGI.escape(organization)}/attributes").with_json(attribute.to_json).post
142
- ::Io::Flow::Catalog::V0::Models::Attribute.new(r)
143
- end
144
-
145
- # Update an attribute with the specified name, creating if it does not exist.
146
- def put_by_name(organization, name, attribute)
147
- HttpClient::Preconditions.assert_class('organization', organization, String)
148
- HttpClient::Preconditions.assert_class('name', name, String)
149
- HttpClient::Preconditions.assert_class('attribute', attribute, ::Io::Flow::Catalog::V0::Models::Attribute)
150
- r = @client.request("/#{CGI.escape(organization)}/attributes/#{CGI.escape(name)}").with_json(attribute.to_json).put
151
- ::Io::Flow::Catalog::V0::Models::Attribute.new(r)
152
- end
153
-
154
- # Delete an attribute with this name
155
- def delete_by_name(organization, name)
156
- HttpClient::Preconditions.assert_class('organization', organization, String)
157
- HttpClient::Preconditions.assert_class('name', name, String)
158
- r = @client.request("/#{CGI.escape(organization)}/attributes/#{CGI.escape(name)}").delete
159
- nil
160
- end
161
-
162
- end
163
-
164
- class Catalogs
165
-
166
- def initialize(client)
167
- @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Catalog::V0::Client)
168
- end
169
-
170
- # Returns information about a specific catalog.
171
- def get_catalog(organization)
172
- HttpClient::Preconditions.assert_class('organization', organization, String)
173
- r = @client.request("/#{CGI.escape(organization)}/catalog").get
174
- ::Io::Flow::Catalog::V0::Models::Catalog.new(r)
175
- end
176
-
177
- end
178
-
179
- class Functions
180
-
181
- def initialize(client)
182
- @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Catalog::V0::Client)
183
- end
184
-
185
- # Provides visibility into recent changes of each object, including deletion
186
- def get_versions(organization, incoming={})
187
- HttpClient::Preconditions.assert_class('organization', organization, String)
188
- opts = HttpClient::Helper.symbolize_keys(incoming)
189
- query = {
190
- :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
191
- :key => (x = opts.delete(:key); x.nil? ? nil : HttpClient::Preconditions.assert_class('key', x, Array).map { |v| HttpClient::Preconditions.assert_class('key', v, String) }),
192
- :name => (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, Array).map { |v| HttpClient::Preconditions.assert_class('name', v, String) }),
193
- :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
194
- :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
195
- :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "journal_timestamp" : x), String)
196
- }.delete_if { |k, v| v.nil? }
197
- r = @client.request("/#{CGI.escape(organization)}/functions/versions").with_query(query).get
198
- r.map { |x| ::Io::Flow::Catalog::V0::Models::FunctionVersion.new(x) }
199
- end
200
-
201
- # Search functions. Always paginated.
202
- def get(organization, incoming={})
203
- HttpClient::Preconditions.assert_class('organization', organization, String)
204
- opts = HttpClient::Helper.symbolize_keys(incoming)
205
- query = {
206
- :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
207
- :key => (x = opts.delete(:key); x.nil? ? nil : HttpClient::Preconditions.assert_class('key', x, Array).map { |v| HttpClient::Preconditions.assert_class('key', v, String) }),
208
- :name => (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, Array).map { |v| HttpClient::Preconditions.assert_class('name', v, String) }),
209
- :position => (x = opts.delete(:position); x.nil? ? nil : HttpClient::Preconditions.assert_class('position', x, Array).map { |v| HttpClient::Preconditions.assert_class('position', v, Integer) }),
210
- :subcatalog => (x = opts.delete(:subcatalog); x.nil? ? nil : HttpClient::Preconditions.assert_class('subcatalog', x, Array).map { |v| HttpClient::Preconditions.assert_class('subcatalog', v, String) }),
211
- :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
212
- :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
213
- :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "name" : x), String)
214
- }.delete_if { |k, v| v.nil? }
215
- r = @client.request("/#{CGI.escape(organization)}/functions").with_query(query).get
216
- r.map { |x| ::Io::Flow::Catalog::V0::Models::Function.new(x) }
217
- end
218
-
219
- # Returns information about a specific function.
220
- def get_by_key(organization, key)
221
- HttpClient::Preconditions.assert_class('organization', organization, String)
222
- HttpClient::Preconditions.assert_class('key', key, String)
223
- r = @client.request("/#{CGI.escape(organization)}/functions/#{CGI.escape(key)}").get
224
- ::Io::Flow::Catalog::V0::Models::Function.new(r)
225
- end
226
-
227
- # Add function
228
- def post(organization, function_form)
229
- HttpClient::Preconditions.assert_class('organization', organization, String)
230
- HttpClient::Preconditions.assert_class('function_form', function_form, ::Io::Flow::Catalog::V0::Models::FunctionForm)
231
- r = @client.request("/#{CGI.escape(organization)}/functions").with_json(function_form.to_json).post
232
- ::Io::Flow::Catalog::V0::Models::Function.new(r)
233
- end
234
-
235
- # Update function with the specified key, creating if it does not exist.
236
- def put_by_key(organization, key, function_form)
237
- HttpClient::Preconditions.assert_class('organization', organization, String)
238
- HttpClient::Preconditions.assert_class('key', key, String)
239
- HttpClient::Preconditions.assert_class('function_form', function_form, ::Io::Flow::Catalog::V0::Models::FunctionForm)
240
- r = @client.request("/#{CGI.escape(organization)}/functions/#{CGI.escape(key)}").with_json(function_form.to_json).put
241
- ::Io::Flow::Catalog::V0::Models::Function.new(r)
242
- end
243
-
244
- # Delete the function with this key
245
- def delete_by_key(organization, key)
246
- HttpClient::Preconditions.assert_class('organization', organization, String)
247
- HttpClient::Preconditions.assert_class('key', key, String)
248
- r = @client.request("/#{CGI.escape(organization)}/functions/#{CGI.escape(key)}").delete
249
- nil
250
- end
251
-
252
- end
253
-
254
- class Items
255
-
256
- def initialize(client)
257
- @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Catalog::V0::Client)
258
- end
259
-
260
- # Provides visibility into recent changes of each object, including deletion
261
- def get_versions(organization, incoming={})
262
- HttpClient::Preconditions.assert_class('organization', organization, String)
263
- opts = HttpClient::Helper.symbolize_keys(incoming)
264
- query = {
265
- :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
266
- :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
267
- :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
268
- :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
269
- :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "journal_timestamp" : x), String)
270
- }.delete_if { |k, v| v.nil? }
271
- r = @client.request("/#{CGI.escape(organization)}/catalog/items/versions").with_query(query).get
272
- r.map { |x| ::Io::Flow::Catalog::V0::Models::ItemVersion.new(x) }
273
- end
274
-
275
- # Search items. Always paginated.
276
- def get(organization, incoming={})
277
- HttpClient::Preconditions.assert_class('organization', organization, String)
278
- opts = HttpClient::Helper.symbolize_keys(incoming)
279
- query = {
280
- :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
281
- :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
282
- :query => (x = opts.delete(:query); x.nil? ? nil : HttpClient::Preconditions.assert_class('query', x, String)),
283
- :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
284
- :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
285
- :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "name" : x), String)
286
- }.delete_if { |k, v| v.nil? }
287
- r = @client.request("/#{CGI.escape(organization)}/catalog/items").with_query(query).get
288
- r.map { |x| ::Io::Flow::Catalog::V0::Models::Item.new(x) }
289
- end
290
-
291
- # Returns information about a specific item.
292
- def get_by_number(organization, number)
293
- HttpClient::Preconditions.assert_class('organization', organization, String)
294
- HttpClient::Preconditions.assert_class('number', number, String)
295
- r = @client.request("/#{CGI.escape(organization)}/catalog/items/#{CGI.escape(number)}").get
296
- ::Io::Flow::Catalog::V0::Models::Item.new(r)
297
- end
298
-
299
- # Add catalog item(s)
300
- def post(organization, item_form)
301
- HttpClient::Preconditions.assert_class('organization', organization, String)
302
- HttpClient::Preconditions.assert_class('item_form', item_form, ::Io::Flow::Catalog::V0::Models::ItemForm)
303
- r = @client.request("/#{CGI.escape(organization)}/catalog/items").with_json(item_form.to_json).post
304
- ::Io::Flow::Catalog::V0::Models::Item.new(r)
305
- end
306
-
307
- # Update item with the specified number, creating if it does not exist.
308
- def put_by_number(organization, number, item_form)
309
- HttpClient::Preconditions.assert_class('organization', organization, String)
310
- HttpClient::Preconditions.assert_class('number', number, String)
311
- HttpClient::Preconditions.assert_class('item_form', item_form, ::Io::Flow::Catalog::V0::Models::ItemForm)
312
- r = @client.request("/#{CGI.escape(organization)}/catalog/items/#{CGI.escape(number)}").with_json(item_form.to_json).put
313
- ::Io::Flow::Catalog::V0::Models::Item.new(r)
314
- end
315
-
316
- # Delete the item with this number
317
- def delete_by_number(organization, number)
318
- HttpClient::Preconditions.assert_class('organization', organization, String)
319
- HttpClient::Preconditions.assert_class('number', number, String)
320
- r = @client.request("/#{CGI.escape(organization)}/catalog/items/#{CGI.escape(number)}").delete
321
- nil
322
- end
323
-
324
- end
325
-
326
- class Subcatalogs
327
-
328
- def initialize(client)
329
- @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Catalog::V0::Client)
330
- end
331
-
332
- # Provides visibility into recent changes of each object, including deletion
333
- def get_versions(organization, incoming={})
334
- HttpClient::Preconditions.assert_class('organization', organization, String)
335
- opts = HttpClient::Helper.symbolize_keys(incoming)
336
- query = {
337
- :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
338
- :key => (x = opts.delete(:key); x.nil? ? nil : HttpClient::Preconditions.assert_class('key', x, Array).map { |v| HttpClient::Preconditions.assert_class('key', v, String) }),
339
- :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
340
- :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
341
- :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "journal_timestamp" : x), String)
342
- }.delete_if { |k, v| v.nil? }
343
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/versions").with_query(query).get
344
- r.map { |x| ::Io::Flow::Catalog::V0::Models::SubcatalogVersion.new(x) }
345
- end
346
-
347
- # Search subcatalogs. Always paginated.
348
- def get(organization, incoming={})
349
- HttpClient::Preconditions.assert_class('organization', organization, String)
350
- opts = HttpClient::Helper.symbolize_keys(incoming)
351
- query = {
352
- :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
353
- :key => (x = opts.delete(:key); x.nil? ? nil : HttpClient::Preconditions.assert_class('key', x, Array).map { |v| HttpClient::Preconditions.assert_class('key', v, String) }),
354
- :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
355
- :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
356
- :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-created_at" : x), String)
357
- }.delete_if { |k, v| v.nil? }
358
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs").with_query(query).get
359
- r.map { |x| ::Io::Flow::Catalog::V0::Models::Subcatalog.new(x) }
360
- end
361
-
362
- # Returns information about a specific subcatalog.
363
- def get_by_key(organization, key)
364
- HttpClient::Preconditions.assert_class('organization', organization, String)
365
- HttpClient::Preconditions.assert_class('key', key, String)
366
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/#{CGI.escape(key)}").get
367
- ::Io::Flow::Catalog::V0::Models::Subcatalog.new(r)
368
- end
369
-
370
- # Add subcatalog
371
- def post(organization, subcatalog_form)
372
- HttpClient::Preconditions.assert_class('organization', organization, String)
373
- HttpClient::Preconditions.assert_class('subcatalog_form', subcatalog_form, ::Io::Flow::Catalog::V0::Models::SubcatalogForm)
374
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs").with_json(subcatalog_form.to_json).post
375
- ::Io::Flow::Catalog::V0::Models::Subcatalog.new(r)
376
- end
377
-
378
- # Update subcatalog with the specified key, creating if it does not exist.
379
- def put_by_key(organization, key, subcatalog_form)
380
- HttpClient::Preconditions.assert_class('organization', organization, String)
381
- HttpClient::Preconditions.assert_class('key', key, String)
382
- HttpClient::Preconditions.assert_class('subcatalog_form', subcatalog_form, ::Io::Flow::Catalog::V0::Models::SubcatalogForm)
383
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/#{CGI.escape(key)}").with_json(subcatalog_form.to_json).put
384
- ::Io::Flow::Catalog::V0::Models::Subcatalog.new(r)
385
- end
386
-
387
- # Delete the subcatalog with this key
388
- def delete_by_key(organization, key)
389
- HttpClient::Preconditions.assert_class('organization', organization, String)
390
- HttpClient::Preconditions.assert_class('key', key, String)
391
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/#{CGI.escape(key)}").delete
392
- nil
393
- end
394
-
395
- # Returns information about a specific subcatalog's settings.
396
- def get_settings_by_key(organization, key)
397
- HttpClient::Preconditions.assert_class('organization', organization, String)
398
- HttpClient::Preconditions.assert_class('key', key, String)
399
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/#{CGI.escape(key)}/settings").get
400
- ::Io::Flow::Catalog::V0::Models::SubcatalogSettings.new(r)
401
- end
402
-
403
- # Update subcatalog settings for the specified subcatalog.
404
- def put_settings_by_key(organization, key, subcatalog_settings_form)
405
- HttpClient::Preconditions.assert_class('organization', organization, String)
406
- HttpClient::Preconditions.assert_class('key', key, String)
407
- HttpClient::Preconditions.assert_class('subcatalog_settings_form', subcatalog_settings_form, ::Io::Flow::Catalog::V0::Models::SubcatalogSettingsForm)
408
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/#{CGI.escape(key)}/settings").with_json(subcatalog_settings_form.to_json).put
409
- ::Io::Flow::Catalog::V0::Models::SubcatalogSettings.new(r)
410
- end
411
-
412
- # Sync subcatalog
413
- def post_events_by_key_and_event(organization, key, event, hash)
414
- HttpClient::Preconditions.assert_class('organization', organization, String)
415
- HttpClient::Preconditions.assert_class('key', key, String)
416
- HttpClient::Preconditions.assert_class('event', event, String)
417
- HttpClient::Preconditions.assert_class('hash', hash, Hash)
418
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/#{CGI.escape(key)}/events/#{CGI.escape(event)}").with_json(hash.to_json).post
419
- nil
420
- end
421
-
422
- end
423
-
424
- class SubcatalogItems
425
-
426
- def initialize(client)
427
- @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Catalog::V0::Client)
428
- end
429
-
430
- # Provides visibility into recent changes of each object, including deletion
431
- def get_versions(organization, subcatalog, incoming={})
432
- HttpClient::Preconditions.assert_class('organization', organization, String)
433
- HttpClient::Preconditions.assert_class('subcatalog', subcatalog, String)
434
- opts = HttpClient::Helper.symbolize_keys(incoming)
435
- query = {
436
- :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
437
- :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
438
- :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
439
- :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
440
- :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "journal_timestamp" : x), String)
441
- }.delete_if { |k, v| v.nil? }
442
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/#{CGI.escape(subcatalog)}/items/versions").with_query(query).get
443
- r.map { |x| ::Io::Flow::Catalog::V0::Models::SubcatalogVersion.new(x) }
444
- end
445
-
446
- # Search subcatalog items. Always paginated.
447
- def get(organization, subcatalog, incoming={})
448
- HttpClient::Preconditions.assert_class('organization', organization, String)
449
- HttpClient::Preconditions.assert_class('subcatalog', subcatalog, String)
450
- opts = HttpClient::Helper.symbolize_keys(incoming)
451
- query = {
452
- :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
453
- :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
454
- :query => (x = opts.delete(:query); x.nil? ? nil : HttpClient::Preconditions.assert_class('query', x, String)),
455
- :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
456
- :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
457
- :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "name" : x), String)
458
- }.delete_if { |k, v| v.nil? }
459
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/#{CGI.escape(subcatalog)}/items").with_query(query).get
460
- r.map { |x| ::Io::Flow::Catalog::V0::Models::Item.new(x) }
461
- end
462
-
463
- # Returns information about specific subcatalog items.
464
- def get_by_number(organization, subcatalog, number)
465
- HttpClient::Preconditions.assert_class('organization', organization, String)
466
- HttpClient::Preconditions.assert_class('subcatalog', subcatalog, String)
467
- HttpClient::Preconditions.assert_class('number', number, String)
468
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/#{CGI.escape(subcatalog)}/items/#{CGI.escape(number)}").get
469
- ::Io::Flow::Catalog::V0::Models::Item.new(r)
470
- end
471
-
472
- # Add subcatalog item
473
- def post(organization, subcatalog, item_form)
474
- HttpClient::Preconditions.assert_class('organization', organization, String)
475
- HttpClient::Preconditions.assert_class('subcatalog', subcatalog, String)
476
- HttpClient::Preconditions.assert_class('item_form', item_form, ::Io::Flow::Catalog::V0::Models::ItemForm)
477
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/#{CGI.escape(subcatalog)}/items").with_json(item_form.to_json).post
478
- ::Io::Flow::Catalog::V0::Models::Item.new(r)
479
- end
480
-
481
- # Update subcatalog item with the specified number, creating if it does not
482
- # exist.
483
- def put_by_number(organization, subcatalog, number, item_form)
484
- HttpClient::Preconditions.assert_class('organization', organization, String)
485
- HttpClient::Preconditions.assert_class('subcatalog', subcatalog, String)
486
- HttpClient::Preconditions.assert_class('number', number, String)
487
- HttpClient::Preconditions.assert_class('item_form', item_form, ::Io::Flow::Catalog::V0::Models::ItemForm)
488
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/#{CGI.escape(subcatalog)}/items/#{CGI.escape(number)}").with_json(item_form.to_json).put
489
- ::Io::Flow::Catalog::V0::Models::Item.new(r)
490
- end
491
-
492
- # Delete the subcatalog item with this number
493
- def delete_by_number(organization, subcatalog, number)
494
- HttpClient::Preconditions.assert_class('organization', organization, String)
495
- HttpClient::Preconditions.assert_class('subcatalog', subcatalog, String)
496
- HttpClient::Preconditions.assert_class('number', number, String)
497
- r = @client.request("/#{CGI.escape(organization)}/catalog/subcatalogs/#{CGI.escape(subcatalog)}/items/#{CGI.escape(number)}").delete
498
- nil
499
- end
500
-
501
- end
502
-
503
- end
504
-
505
- module Models
506
-
507
- # Cost variation used to calculate localized prices
508
- class Adjustment
509
-
510
- module Types
511
- MARGIN = 'margin' unless defined?(MARGIN)
512
- ROUNDING = 'rounding' unless defined?(ROUNDING)
513
- end
514
-
515
- def initialize(incoming={})
516
- opts = HttpClient::Helper.symbolize_keys(incoming)
517
- HttpClient::Preconditions.require_keys(opts, [:name], 'Adjustment')
518
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
519
- end
520
-
521
- def to_hash
522
- subtype_to_hash.merge(:discriminator => @name)
523
- end
524
-
525
- def Adjustment.from_json(hash)
526
- HttpClient::Preconditions.assert_class('hash', hash, Hash)
527
- case HttpClient::Helper.symbolize_keys(hash)[:discriminator]
528
- when Types::MARGIN; Margin.new(hash)
529
- when Types::ROUNDING; Rounding.new(hash)
530
- else AdjustmentUndefinedType.new(:name => union_type_name)
531
- end
532
- end
533
-
534
- end
535
-
536
- class AdjustmentUndefinedType < Adjustment
537
-
538
- attr_reader :name
539
-
540
- def initialize(incoming={})
541
- super(:name => 'undefined_type')
542
- opts = HttpClient::Helper.symbolize_keys(incoming)
543
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
544
- end
545
-
546
- def subtype_to_hash
547
- raise 'Unable to serialize undefined type to json'
548
- end
549
-
550
- def copy(incoming={})
551
- raise 'Operation not supported for undefined type'
552
- end
553
-
554
- def to_hash
555
- raise 'Operation not supported for undefined type'
556
- end
557
-
558
- end
559
-
560
- # A function can be represented with just it's ID, or the entire model
561
- class ExpandableFunction
562
-
563
- module Types
564
- FUNCTION = 'function' unless defined?(FUNCTION)
565
- FUNCTION_REFERENCE = 'function_reference' unless defined?(FUNCTION_REFERENCE)
566
- end
567
-
568
- def initialize(incoming={})
569
- opts = HttpClient::Helper.symbolize_keys(incoming)
570
- HttpClient::Preconditions.require_keys(opts, [:name], 'ExpandableFunction')
571
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
572
- end
573
-
574
- def to_hash
575
- subtype_to_hash.merge(:discriminator => @name)
576
- end
577
-
578
- def ExpandableFunction.from_json(hash)
579
- HttpClient::Preconditions.assert_class('hash', hash, Hash)
580
- case HttpClient::Helper.symbolize_keys(hash)[:discriminator]
581
- when Types::FUNCTION; Function.new(hash)
582
- when Types::FUNCTION_REFERENCE; FunctionReference.new(hash)
583
- else ExpandableFunctionUndefinedType.new(:name => union_type_name)
584
- end
585
- end
586
-
587
- end
588
-
589
- class ExpandableFunctionUndefinedType < ExpandableFunction
590
-
591
- attr_reader :name
592
-
593
- def initialize(incoming={})
594
- super(:name => 'undefined_type')
595
- opts = HttpClient::Helper.symbolize_keys(incoming)
596
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
597
- end
598
-
599
- def subtype_to_hash
600
- raise 'Unable to serialize undefined type to json'
601
- end
602
-
603
- def copy(incoming={})
604
- raise 'Operation not supported for undefined type'
605
- end
606
-
607
- def to_hash
608
- raise 'Operation not supported for undefined type'
609
- end
610
-
611
- end
612
-
613
- # A subcatalog can be represented with just it's ID, or the entire model
614
- class ExpandableSubcatalog
615
-
616
- module Types
617
- SUBCATALOG = 'subcatalog' unless defined?(SUBCATALOG)
618
- SUBCATALOG_REFERENCE = 'subcatalog_reference' unless defined?(SUBCATALOG_REFERENCE)
619
- end
620
-
621
- def initialize(incoming={})
622
- opts = HttpClient::Helper.symbolize_keys(incoming)
623
- HttpClient::Preconditions.require_keys(opts, [:name], 'ExpandableSubcatalog')
624
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
625
- end
626
-
627
- def to_hash
628
- subtype_to_hash.merge(:discriminator => @name)
629
- end
630
-
631
- def ExpandableSubcatalog.from_json(hash)
632
- HttpClient::Preconditions.assert_class('hash', hash, Hash)
633
- case HttpClient::Helper.symbolize_keys(hash)[:discriminator]
634
- when Types::SUBCATALOG; Subcatalog.new(hash)
635
- when Types::SUBCATALOG_REFERENCE; SubcatalogReference.new(hash)
636
- else ExpandableSubcatalogUndefinedType.new(:name => union_type_name)
637
- end
638
- end
639
-
640
- end
641
-
642
- class ExpandableSubcatalogUndefinedType < ExpandableSubcatalog
643
-
644
- attr_reader :name
645
-
646
- def initialize(incoming={})
647
- super(:name => 'undefined_type')
648
- opts = HttpClient::Helper.symbolize_keys(incoming)
649
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
650
- end
651
-
652
- def subtype_to_hash
653
- raise 'Unable to serialize undefined type to json'
654
- end
655
-
656
- def copy(incoming={})
657
- raise 'Operation not supported for undefined type'
658
- end
659
-
660
- def to_hash
661
- raise 'Operation not supported for undefined type'
662
- end
663
-
664
- end
665
-
666
- class AdjustmentType
667
-
668
- attr_reader :value
669
-
670
- def initialize(value)
671
- @value = HttpClient::Preconditions.assert_class('value', value, String)
672
- end
673
-
674
- # Returns the instance of AdjustmentType for this value, creating a new instance for an unknown value
675
- def AdjustmentType.apply(value)
676
- if value.instance_of?(AdjustmentType)
677
- value
678
- else
679
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
680
- value.nil? ? nil : (from_string(value) || AdjustmentType.new(value))
681
- end
682
- end
683
-
684
- # Returns the instance of AdjustmentType for this value, or nil if not found
685
- def AdjustmentType.from_string(value)
686
- HttpClient::Preconditions.assert_class('value', value, String)
687
- AdjustmentType.ALL.find { |v| v.value == value }
688
- end
689
-
690
- def AdjustmentType.ALL
691
- @@all ||= [AdjustmentType.fixed_margin, AdjustmentType.percent_margin, AdjustmentType.round]
692
- end
693
-
694
- def AdjustmentType.fixed_margin
695
- @@_fixed_margin ||= AdjustmentType.new('fixed_margin')
696
- end
697
-
698
- def AdjustmentType.percent_margin
699
- @@_percent_margin ||= AdjustmentType.new('percent_margin')
700
- end
701
-
702
- def AdjustmentType.round
703
- @@_round ||= AdjustmentType.new('round')
704
- end
705
-
706
- def to_hash
707
- value
708
- end
709
-
710
- end
711
-
712
- class DeliveredDuty
713
-
714
- attr_reader :value
715
-
716
- def initialize(value)
717
- @value = HttpClient::Preconditions.assert_class('value', value, String)
718
- end
719
-
720
- # Returns the instance of DeliveredDuty for this value, creating a new instance for an unknown value
721
- def DeliveredDuty.apply(value)
722
- if value.instance_of?(DeliveredDuty)
723
- value
724
- else
725
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
726
- value.nil? ? nil : (from_string(value) || DeliveredDuty.new(value))
727
- end
728
- end
729
-
730
- # Returns the instance of DeliveredDuty for this value, or nil if not found
731
- def DeliveredDuty.from_string(value)
732
- HttpClient::Preconditions.assert_class('value', value, String)
733
- DeliveredDuty.ALL.find { |v| v.value == value }
734
- end
735
-
736
- def DeliveredDuty.ALL
737
- @@all ||= [DeliveredDuty.paid, DeliveredDuty.unpaid]
738
- end
739
-
740
- def DeliveredDuty.paid
741
- @@_paid ||= DeliveredDuty.new('paid')
742
- end
743
-
744
- def DeliveredDuty.unpaid
745
- @@_unpaid ||= DeliveredDuty.new('unpaid')
746
- end
747
-
748
- def to_hash
749
- value
750
- end
751
-
752
- end
753
-
754
- class Levy
755
-
756
- attr_reader :value
757
-
758
- def initialize(value)
759
- @value = HttpClient::Preconditions.assert_class('value', value, String)
760
- end
761
-
762
- # Returns the instance of Levy for this value, creating a new instance for an unknown value
763
- def Levy.apply(value)
764
- if value.instance_of?(Levy)
765
- value
766
- else
767
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
768
- value.nil? ? nil : (from_string(value) || Levy.new(value))
769
- end
770
- end
771
-
772
- # Returns the instance of Levy for this value, or nil if not found
773
- def Levy.from_string(value)
774
- HttpClient::Preconditions.assert_class('value', value, String)
775
- Levy.ALL.find { |v| v.value == value }
776
- end
777
-
778
- def Levy.ALL
779
- @@all ||= [Levy.duty, Levy.shipping, Levy.vat]
780
- end
781
-
782
- def Levy.duty
783
- @@_duty ||= Levy.new('duty')
784
- end
785
-
786
- def Levy.shipping
787
- @@_shipping ||= Levy.new('shipping')
788
- end
789
-
790
- # Value-Added Tax
791
- def Levy.vat
792
- @@_vat ||= Levy.new('vat')
793
- end
794
-
795
- def to_hash
796
- value
797
- end
798
-
799
- end
800
-
801
- class RoundingMethod
802
-
803
- attr_reader :value
804
-
805
- def initialize(value)
806
- @value = HttpClient::Preconditions.assert_class('value', value, String)
807
- end
808
-
809
- # Returns the instance of RoundingMethod for this value, creating a new instance for an unknown value
810
- def RoundingMethod.apply(value)
811
- if value.instance_of?(RoundingMethod)
812
- value
813
- else
814
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
815
- value.nil? ? nil : (from_string(value) || RoundingMethod.new(value))
816
- end
817
- end
818
-
819
- # Returns the instance of RoundingMethod for this value, or nil if not found
820
- def RoundingMethod.from_string(value)
821
- HttpClient::Preconditions.assert_class('value', value, String)
822
- RoundingMethod.ALL.find { |v| v.value == value }
823
- end
824
-
825
- def RoundingMethod.ALL
826
- @@all ||= [RoundingMethod.up, RoundingMethod.down, RoundingMethod.nearest]
827
- end
828
-
829
- # Round up to the specified rounding.value
830
- def RoundingMethod.up
831
- @@_up ||= RoundingMethod.new('up')
832
- end
833
-
834
- # Round down to the specified rounding.value
835
- def RoundingMethod.down
836
- @@_down ||= RoundingMethod.new('down')
837
- end
838
-
839
- # Round to the nearest specified rounding.value. If equidistant, will round up.
840
- def RoundingMethod.nearest
841
- @@_nearest ||= RoundingMethod.new('nearest')
842
- end
843
-
844
- def to_hash
845
- value
846
- end
847
-
848
- end
849
-
850
- class UpdatePolicy
851
-
852
- attr_reader :value
853
-
854
- def initialize(value)
855
- @value = HttpClient::Preconditions.assert_class('value', value, String)
856
- end
857
-
858
- # Returns the instance of UpdatePolicy for this value, creating a new instance for an unknown value
859
- def UpdatePolicy.apply(value)
860
- if value.instance_of?(UpdatePolicy)
861
- value
862
- else
863
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
864
- value.nil? ? nil : (from_string(value) || UpdatePolicy.new(value))
865
- end
866
- end
867
-
868
- # Returns the instance of UpdatePolicy for this value, or nil if not found
869
- def UpdatePolicy.from_string(value)
870
- HttpClient::Preconditions.assert_class('value', value, String)
871
- UpdatePolicy.ALL.find { |v| v.value == value }
872
- end
873
-
874
- def UpdatePolicy.ALL
875
- @@all ||= [UpdatePolicy.auto, UpdatePolicy.queue, UpdatePolicy.discard]
876
- end
877
-
878
- def UpdatePolicy.auto
879
- @@_auto ||= UpdatePolicy.new('auto')
880
- end
881
-
882
- # Queue item update for approval.
883
- def UpdatePolicy.queue
884
- @@_queue ||= UpdatePolicy.new('queue')
885
- end
886
-
887
- def UpdatePolicy.discard
888
- @@_discard ||= UpdatePolicy.new('discard')
889
- end
890
-
891
- def to_hash
892
- value
893
- end
894
-
895
- end
896
-
897
- # An attribute represents applicable item data made available on specific UI
898
- # elements (e.g. require 'Brand')
899
- class Attribute
900
-
901
- attr_reader :name, :options, :label
902
-
903
- def initialize(incoming={})
904
- opts = HttpClient::Helper.symbolize_keys(incoming)
905
- HttpClient::Preconditions.require_keys(opts, [:name, :options], 'Attribute')
906
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
907
- @options = (x = opts.delete(:options); x.is_a?(::Io::Flow::Catalog::V0::Models::Options) ? x : ::Io::Flow::Catalog::V0::Models::Options.new(x))
908
- @label = (x = opts.delete(:label); x.nil? ? nil : HttpClient::Preconditions.assert_class('label', x, String))
909
- end
910
-
911
- def to_json
912
- JSON.dump(to_hash)
913
- end
914
-
915
- def copy(incoming={})
916
- Attribute.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
917
- end
918
-
919
- def to_hash
920
- {
921
- :name => name,
922
- :options => options.to_hash,
923
- :label => label
924
- }
925
- end
926
-
927
- end
928
-
929
- # Attribtue metadata represents additional item data not configured in other top
930
- # level fields
931
- class AttributeMetadata
932
-
933
- attr_reader :key, :value
934
-
935
- def initialize(incoming={})
936
- opts = HttpClient::Helper.symbolize_keys(incoming)
937
- HttpClient::Preconditions.require_keys(opts, [:key, :value], 'AttributeMetadata')
938
- @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
939
- @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), String)
940
- end
941
-
942
- def to_json
943
- JSON.dump(to_hash)
944
- end
945
-
946
- def copy(incoming={})
947
- AttributeMetadata.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
948
- end
949
-
950
- def to_hash
951
- {
952
- :key => key,
953
- :value => value
954
- }
955
- end
956
-
957
- end
958
-
959
- # Retrieve journaled history of an attribute
960
- class AttributeVersion
961
-
962
- attr_reader :id, :timestamp, :type, :attribute
963
-
964
- def initialize(incoming={})
965
- opts = HttpClient::Helper.symbolize_keys(incoming)
966
- HttpClient::Preconditions.require_keys(opts, [:id, :timestamp, :type, :attribute], 'AttributeVersion')
967
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
968
- @timestamp = HttpClient::Preconditions.assert_class('timestamp', HttpClient::Helper.to_date_time_iso8601(opts.delete(:timestamp)), DateTime)
969
- @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Common::V0::Models::ChangeType) ? x : ::Io::Flow::Common::V0::Models::ChangeType.apply(x))
970
- @attribute = (x = opts.delete(:attribute); x.is_a?(::Io::Flow::Catalog::V0::Models::Attribute) ? x : ::Io::Flow::Catalog::V0::Models::Attribute.new(x))
971
- end
972
-
973
- def to_json
974
- JSON.dump(to_hash)
975
- end
976
-
977
- def copy(incoming={})
978
- AttributeVersion.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
979
- end
980
-
981
- def to_hash
982
- {
983
- :id => id,
984
- :timestamp => timestamp,
985
- :type => type.value,
986
- :attribute => attribute.to_hash
987
- }
988
- end
989
-
990
- end
991
-
992
- class Catalog
993
-
994
- attr_reader :id
995
-
996
- def initialize(incoming={})
997
- opts = HttpClient::Helper.symbolize_keys(incoming)
998
- HttpClient::Preconditions.require_keys(opts, [:id], 'Catalog')
999
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1000
- end
1001
-
1002
- def to_json
1003
- JSON.dump(to_hash)
1004
- end
1005
-
1006
- def copy(incoming={})
1007
- Catalog.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1008
- end
1009
-
1010
- def to_hash
1011
- {
1012
- :id => id
1013
- }
1014
- end
1015
-
1016
- end
1017
-
1018
- class CatalogVersion
1019
-
1020
- attr_reader :id, :timestamp, :type, :catalog
1021
-
1022
- def initialize(incoming={})
1023
- opts = HttpClient::Helper.symbolize_keys(incoming)
1024
- HttpClient::Preconditions.require_keys(opts, [:id, :timestamp, :type, :catalog], 'CatalogVersion')
1025
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1026
- @timestamp = HttpClient::Preconditions.assert_class('timestamp', HttpClient::Helper.to_date_time_iso8601(opts.delete(:timestamp)), DateTime)
1027
- @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Common::V0::Models::ChangeType) ? x : ::Io::Flow::Common::V0::Models::ChangeType.apply(x))
1028
- @catalog = (x = opts.delete(:catalog); x.is_a?(::Io::Flow::Catalog::V0::Models::Catalog) ? x : ::Io::Flow::Catalog::V0::Models::Catalog.new(x))
1029
- end
1030
-
1031
- def to_json
1032
- JSON.dump(to_hash)
1033
- end
1034
-
1035
- def copy(incoming={})
1036
- CatalogVersion.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1037
- end
1038
-
1039
- def to_hash
1040
- {
1041
- :id => id,
1042
- :timestamp => timestamp,
1043
- :type => type.value,
1044
- :catalog => catalog.to_hash
1045
- }
1046
- end
1047
-
1048
- end
1049
-
1050
- # Flow internal model containing an item's origin and classified harmonization
1051
- # code (6 digit)
1052
- class Flow
1053
-
1054
- attr_reader :origin, :function, :hs6
1055
-
1056
- def initialize(incoming={})
1057
- opts = HttpClient::Helper.symbolize_keys(incoming)
1058
- @origin = (x = opts.delete(:origin); x.nil? ? nil : HttpClient::Preconditions.assert_class('origin', x, String))
1059
- @function = (x = opts.delete(:function); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::ExpandableFunction) ? x : ::Io::Flow::Catalog::V0::Models::ExpandableFunction.from_json(x)))
1060
- @hs6 = (x = opts.delete(:hs6); x.nil? ? nil : HttpClient::Preconditions.assert_class('hs6', x, String))
1061
- end
1062
-
1063
- def to_json
1064
- JSON.dump(to_hash)
1065
- end
1066
-
1067
- def copy(incoming={})
1068
- Flow.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1069
- end
1070
-
1071
- def to_hash
1072
- {
1073
- :origin => origin,
1074
- :function => function.nil? ? nil : function.to_hash,
1075
- :hs6 => hs6
1076
- }
1077
- end
1078
-
1079
- end
1080
-
1081
- # Prioritized calculation yielding a localized price (also allows for custom
1082
- # defined price function)
1083
- class Function < ExpandableFunction
1084
-
1085
- attr_reader :id, :subcatalog_id, :key, :name, :position, :presets, :code, :q
1086
-
1087
- def initialize(incoming={})
1088
- super(:name => ExpandableFunction::Types::FUNCTION)
1089
- opts = HttpClient::Helper.symbolize_keys(incoming)
1090
- HttpClient::Preconditions.require_keys(opts, [:id, :subcatalog_id, :key, :name, :position, :presets, :code], 'Function')
1091
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1092
- @subcatalog_id = HttpClient::Preconditions.assert_class('subcatalog_id', opts.delete(:subcatalog_id), String)
1093
- @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
1094
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
1095
- @position = HttpClient::Preconditions.assert_class('position', opts.delete(:position), Integer)
1096
- @presets = (x = opts.delete(:presets); x.is_a?(::Io::Flow::Catalog::V0::Models::Presets) ? x : ::Io::Flow::Catalog::V0::Models::Presets.new(x))
1097
- @code = HttpClient::Preconditions.assert_class('code', opts.delete(:code), String)
1098
- @q = (x = opts.delete(:q); x.nil? ? nil : HttpClient::Preconditions.assert_class('q', x, String))
1099
- end
1100
-
1101
- def to_json
1102
- JSON.dump(to_hash)
1103
- end
1104
-
1105
- def copy(incoming={})
1106
- Function.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1107
- end
1108
-
1109
- def subtype_to_hash
1110
- {
1111
- :id => id,
1112
- :subcatalog_id => subcatalog_id,
1113
- :key => key,
1114
- :name => name,
1115
- :position => position,
1116
- :presets => presets.to_hash,
1117
- :code => code,
1118
- :q => q
1119
- }
1120
- end
1121
-
1122
- end
1123
-
1124
- class FunctionForm
1125
-
1126
- attr_reader :name, :subcatalog_id, :q, :presets, :code, :position
1127
-
1128
- def initialize(incoming={})
1129
- opts = HttpClient::Helper.symbolize_keys(incoming)
1130
- HttpClient::Preconditions.require_keys(opts, [:name, :subcatalog_id], 'FunctionForm')
1131
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
1132
- @subcatalog_id = HttpClient::Preconditions.assert_class('subcatalog_id', opts.delete(:subcatalog_id), String)
1133
- @q = (x = opts.delete(:q); x.nil? ? nil : HttpClient::Preconditions.assert_class('q', x, String))
1134
- @presets = (x = opts.delete(:presets); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::Presets) ? x : ::Io::Flow::Catalog::V0::Models::Presets.new(x)))
1135
- @code = (x = opts.delete(:code); x.nil? ? nil : HttpClient::Preconditions.assert_class('code', x, String))
1136
- @position = (x = opts.delete(:position); x.nil? ? nil : HttpClient::Preconditions.assert_class('position', x, Integer))
1137
- end
1138
-
1139
- def to_json
1140
- JSON.dump(to_hash)
1141
- end
1142
-
1143
- def copy(incoming={})
1144
- FunctionForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1145
- end
1146
-
1147
- def to_hash
1148
- {
1149
- :name => name,
1150
- :subcatalog_id => subcatalog_id,
1151
- :q => q,
1152
- :presets => presets.nil? ? nil : presets.to_hash,
1153
- :code => code,
1154
- :position => position
1155
- }
1156
- end
1157
-
1158
- end
1159
-
1160
- class FunctionReference < ExpandableFunction
1161
-
1162
- attr_reader :id
1163
-
1164
- def initialize(incoming={})
1165
- super(:name => ExpandableFunction::Types::FUNCTION_REFERENCE)
1166
- opts = HttpClient::Helper.symbolize_keys(incoming)
1167
- HttpClient::Preconditions.require_keys(opts, [:id], 'FunctionReference')
1168
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1169
- end
1170
-
1171
- def to_json
1172
- JSON.dump(to_hash)
1173
- end
1174
-
1175
- def copy(incoming={})
1176
- FunctionReference.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1177
- end
1178
-
1179
- def subtype_to_hash
1180
- {
1181
- :id => id
1182
- }
1183
- end
1184
-
1185
- end
1186
-
1187
- class FunctionSummary
1188
-
1189
- attr_reader :id, :name
1190
-
1191
- def initialize(incoming={})
1192
- opts = HttpClient::Helper.symbolize_keys(incoming)
1193
- HttpClient::Preconditions.require_keys(opts, [:id, :name], 'FunctionSummary')
1194
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1195
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
1196
- end
1197
-
1198
- def to_json
1199
- JSON.dump(to_hash)
1200
- end
1201
-
1202
- def copy(incoming={})
1203
- FunctionSummary.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1204
- end
1205
-
1206
- def to_hash
1207
- {
1208
- :id => id,
1209
- :name => name
1210
- }
1211
- end
1212
-
1213
- end
1214
-
1215
- class FunctionVersion
1216
-
1217
- attr_reader :id, :timestamp, :type, :function
1218
-
1219
- def initialize(incoming={})
1220
- opts = HttpClient::Helper.symbolize_keys(incoming)
1221
- HttpClient::Preconditions.require_keys(opts, [:id, :timestamp, :type, :function], 'FunctionVersion')
1222
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1223
- @timestamp = HttpClient::Preconditions.assert_class('timestamp', HttpClient::Helper.to_date_time_iso8601(opts.delete(:timestamp)), DateTime)
1224
- @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Common::V0::Models::ChangeType) ? x : ::Io::Flow::Common::V0::Models::ChangeType.apply(x))
1225
- @function = (x = opts.delete(:function); x.is_a?(::Io::Flow::Catalog::V0::Models::Function) ? x : ::Io::Flow::Catalog::V0::Models::Function.new(x))
1226
- end
1227
-
1228
- def to_json
1229
- JSON.dump(to_hash)
1230
- end
1231
-
1232
- def copy(incoming={})
1233
- FunctionVersion.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1234
- end
1235
-
1236
- def to_hash
1237
- {
1238
- :id => id,
1239
- :timestamp => timestamp,
1240
- :type => type.value,
1241
- :function => function.to_hash
1242
- }
1243
- end
1244
-
1245
- end
1246
-
1247
- # The URL to an image, with optional tags. Flow Commerce primarily uses images
1248
- # to enhance the administrative tools (e.g. showing an item image in console)
1249
- class Image
1250
-
1251
- attr_reader :url, :tags
1252
-
1253
- def initialize(incoming={})
1254
- opts = HttpClient::Helper.symbolize_keys(incoming)
1255
- HttpClient::Preconditions.require_keys(opts, [:url], 'Image')
1256
- @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String)
1257
- @tags = HttpClient::Preconditions.assert_class('tags', (x = opts.delete(:tags); x.nil? ? [] : x), Array).map { |v| HttpClient::Preconditions.assert_class('tags', v, String) }
1258
- end
1259
-
1260
- def to_json
1261
- JSON.dump(to_hash)
1262
- end
1263
-
1264
- def copy(incoming={})
1265
- Image.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1266
- end
1267
-
1268
- def to_hash
1269
- {
1270
- :url => url,
1271
- :tags => tags
1272
- }
1273
- end
1274
-
1275
- end
1276
-
1277
- # Image form defines the data needed to create an image
1278
- class ImageForm
1279
-
1280
- attr_reader :url, :tags
1281
-
1282
- def initialize(incoming={})
1283
- opts = HttpClient::Helper.symbolize_keys(incoming)
1284
- HttpClient::Preconditions.require_keys(opts, [:url], 'ImageForm')
1285
- @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String)
1286
- @tags = (x = opts.delete(:tags); x.nil? ? nil : HttpClient::Preconditions.assert_class('tags', x, Array).map { |v| HttpClient::Preconditions.assert_class('tags', v, String) })
1287
- end
1288
-
1289
- def to_json
1290
- JSON.dump(to_hash)
1291
- end
1292
-
1293
- def copy(incoming={})
1294
- ImageForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1295
- end
1296
-
1297
- def to_hash
1298
- {
1299
- :url => url,
1300
- :tags => tags.nil? ? nil : tags
1301
- }
1302
- end
1303
-
1304
- end
1305
-
1306
- # The Flow item defines a specific item that can be purchased by a consumer. For
1307
- # many clients, this will map to a Sku.
1308
- class Item
1309
-
1310
- attr_reader :id, :number, :locale, :name, :currency, :price, :categories, :description, :attributes, :dimensions, :images, :flow, :local
1311
-
1312
- def initialize(incoming={})
1313
- opts = HttpClient::Helper.symbolize_keys(incoming)
1314
- HttpClient::Preconditions.require_keys(opts, [:id, :number, :locale, :name, :currency, :price], 'Item')
1315
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1316
- @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), String)
1317
- @locale = HttpClient::Preconditions.assert_class('locale', opts.delete(:locale), String)
1318
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
1319
- @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
1320
- @price = (x = opts.delete(:price); x.is_a?(::Io::Flow::Catalog::V0::Models::Price) ? x : ::Io::Flow::Catalog::V0::Models::Price.new(x))
1321
- @categories = HttpClient::Preconditions.assert_class('categories', (x = opts.delete(:categories); x.nil? ? [] : x), Array).map { |v| HttpClient::Preconditions.assert_class('categories', v, String) }
1322
- @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String))
1323
- @attributes = HttpClient::Preconditions.assert_class('attributes', (x = opts.delete(:attributes); x.nil? ? [] : x), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Catalog::V0::Models::AttributeMetadata) ? x : ::Io::Flow::Catalog::V0::Models::AttributeMetadata.new(x)) }
1324
- @dimensions = HttpClient::Preconditions.assert_class('dimensions', (x = opts.delete(:dimensions); x.nil? ? [] : x), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Common::V0::Models::Dimension) ? x : ::Io::Flow::Common::V0::Models::Dimension.new(x)) }
1325
- @images = HttpClient::Preconditions.assert_class('images', (x = opts.delete(:images); x.nil? ? [] : x), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Catalog::V0::Models::Image) ? x : ::Io::Flow::Catalog::V0::Models::Image.new(x)) }
1326
- @flow = (x = opts.delete(:flow); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::Flow) ? x : ::Io::Flow::Catalog::V0::Models::Flow.new(x)))
1327
- @local = (x = opts.delete(:local); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::Local) ? x : ::Io::Flow::Catalog::V0::Models::Local.new(x)))
1328
- end
1329
-
1330
- def to_json
1331
- JSON.dump(to_hash)
1332
- end
1333
-
1334
- def copy(incoming={})
1335
- Item.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1336
- end
1337
-
1338
- def to_hash
1339
- {
1340
- :id => id,
1341
- :number => number,
1342
- :locale => locale,
1343
- :name => name,
1344
- :currency => currency,
1345
- :price => price.to_hash,
1346
- :categories => categories,
1347
- :description => description,
1348
- :attributes => attributes.map { |o| o.to_hash },
1349
- :dimensions => dimensions.map { |o| o.to_hash },
1350
- :images => images.map { |o| o.to_hash },
1351
- :flow => flow.nil? ? nil : flow.to_hash,
1352
- :local => local.nil? ? nil : local.to_hash
1353
- }
1354
- end
1355
-
1356
- end
1357
-
1358
- # The item form defines the data required to create an item.
1359
- class ItemForm
1360
-
1361
- attr_reader :number, :locale, :name, :currency, :price, :categories, :description, :attributes, :dimensions, :images
1362
-
1363
- def initialize(incoming={})
1364
- opts = HttpClient::Helper.symbolize_keys(incoming)
1365
- HttpClient::Preconditions.require_keys(opts, [:number, :locale, :name, :currency, :price], 'ItemForm')
1366
- @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), String)
1367
- @locale = HttpClient::Preconditions.assert_class('locale', opts.delete(:locale), String)
1368
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
1369
- @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
1370
- @price = HttpClient::Preconditions.assert_class('price', opts.delete(:price), Numeric)
1371
- @categories = (x = opts.delete(:categories); x.nil? ? nil : HttpClient::Preconditions.assert_class('categories', x, Array).map { |v| HttpClient::Preconditions.assert_class('categories', v, String) })
1372
- @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String))
1373
- @attributes = (x = opts.delete(:attributes); x.nil? ? nil : HttpClient::Preconditions.assert_class('attributes', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::Catalog::V0::Models::AttributeMetadata) ? x : ::Io::Flow::Catalog::V0::Models::AttributeMetadata.new(x)) })
1374
- @dimensions = (x = opts.delete(:dimensions); x.nil? ? nil : HttpClient::Preconditions.assert_class('dimensions', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::Common::V0::Models::Dimension) ? x : ::Io::Flow::Common::V0::Models::Dimension.new(x)) })
1375
- @images = (x = opts.delete(:images); x.nil? ? nil : HttpClient::Preconditions.assert_class('images', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::Catalog::V0::Models::ImageForm) ? x : ::Io::Flow::Catalog::V0::Models::ImageForm.new(x)) })
1376
- end
1377
-
1378
- def to_json
1379
- JSON.dump(to_hash)
1380
- end
1381
-
1382
- def copy(incoming={})
1383
- ItemForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1384
- end
1385
-
1386
- def to_hash
1387
- {
1388
- :number => number,
1389
- :locale => locale,
1390
- :name => name,
1391
- :currency => currency,
1392
- :price => price,
1393
- :categories => categories.nil? ? nil : categories,
1394
- :description => description,
1395
- :attributes => attributes.nil? ? nil : attributes.map { |o| o.to_hash },
1396
- :dimensions => dimensions.nil? ? nil : dimensions.map { |o| o.to_hash },
1397
- :images => images.nil? ? nil : images.map { |o| o.to_hash }
1398
- }
1399
- end
1400
-
1401
- end
1402
-
1403
- class ItemVersion
1404
-
1405
- attr_reader :id, :timestamp, :type, :item
1406
-
1407
- def initialize(incoming={})
1408
- opts = HttpClient::Helper.symbolize_keys(incoming)
1409
- HttpClient::Preconditions.require_keys(opts, [:id, :timestamp, :type, :item], 'ItemVersion')
1410
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1411
- @timestamp = HttpClient::Preconditions.assert_class('timestamp', HttpClient::Helper.to_date_time_iso8601(opts.delete(:timestamp)), DateTime)
1412
- @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Common::V0::Models::ChangeType) ? x : ::Io::Flow::Common::V0::Models::ChangeType.apply(x))
1413
- @item = (x = opts.delete(:item); x.is_a?(::Io::Flow::Catalog::V0::Models::Item) ? x : ::Io::Flow::Catalog::V0::Models::Item.new(x))
1414
- end
1415
-
1416
- def to_json
1417
- JSON.dump(to_hash)
1418
- end
1419
-
1420
- def copy(incoming={})
1421
- ItemVersion.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1422
- end
1423
-
1424
- def to_hash
1425
- {
1426
- :id => id,
1427
- :timestamp => timestamp,
1428
- :type => type.value,
1429
- :item => item.to_hash
1430
- }
1431
- end
1432
-
1433
- end
1434
-
1435
- class Local
1436
-
1437
- attr_reader :prices
1438
-
1439
- def initialize(incoming={})
1440
- opts = HttpClient::Helper.symbolize_keys(incoming)
1441
- HttpClient::Preconditions.require_keys(opts, [:prices], 'Local')
1442
- @prices = HttpClient::Preconditions.assert_class('prices', opts.delete(:prices), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Catalog::V0::Models::LocalizedPrice) ? x : ::Io::Flow::Catalog::V0::Models::LocalizedPrice.new(x)) }
1443
- end
1444
-
1445
- def to_json
1446
- JSON.dump(to_hash)
1447
- end
1448
-
1449
- def copy(incoming={})
1450
- Local.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1451
- end
1452
-
1453
- def to_hash
1454
- {
1455
- :prices => prices.map { |o| o.to_hash }
1456
- }
1457
- end
1458
-
1459
- end
1460
-
1461
- class LocalizedPrice
1462
-
1463
- attr_reader :key, :currency, :amount, :label
1464
-
1465
- def initialize(incoming={})
1466
- opts = HttpClient::Helper.symbolize_keys(incoming)
1467
- HttpClient::Preconditions.require_keys(opts, [:key, :currency, :amount, :label], 'LocalizedPrice')
1468
- @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
1469
- @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
1470
- @amount = HttpClient::Preconditions.assert_class('amount', opts.delete(:amount), Numeric)
1471
- @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String)
1472
- end
1473
-
1474
- def to_json
1475
- JSON.dump(to_hash)
1476
- end
1477
-
1478
- def copy(incoming={})
1479
- LocalizedPrice.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1480
- end
1481
-
1482
- def to_hash
1483
- {
1484
- :key => key,
1485
- :currency => currency,
1486
- :amount => amount,
1487
- :label => label
1488
- }
1489
- end
1490
-
1491
- end
1492
-
1493
- class Margin < Adjustment
1494
-
1495
- attr_reader :name, :value
1496
-
1497
- def initialize(incoming={})
1498
- super(:name => Adjustment::Types::MARGIN)
1499
- opts = HttpClient::Helper.symbolize_keys(incoming)
1500
- HttpClient::Preconditions.require_keys(opts, [:name, :value], 'Margin')
1501
- @name = (x = opts.delete(:name); x.is_a?(::Io::Flow::Catalog::V0::Models::AdjustmentType) ? x : ::Io::Flow::Catalog::V0::Models::AdjustmentType.apply(x))
1502
- @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), Numeric)
1503
- end
1504
-
1505
- def to_json
1506
- JSON.dump(to_hash)
1507
- end
1508
-
1509
- def copy(incoming={})
1510
- Margin.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1511
- end
1512
-
1513
- def subtype_to_hash
1514
- {
1515
- :name => name.value,
1516
- :value => value
1517
- }
1518
- end
1519
-
1520
- end
1521
-
1522
- # Flags to indicate whether a feature is enabled/disabled on a particular model
1523
- # (e.g. show/do not show attribute as a column in harmonization table view of
1524
- # items)
1525
- class Options
1526
-
1527
- attr_reader :show_in_catalog, :show_in_harmonization
1528
-
1529
- def initialize(incoming={})
1530
- opts = HttpClient::Helper.symbolize_keys(incoming)
1531
- @show_in_catalog = HttpClient::Preconditions.assert_boolean('show_in_catalog', (x = opts.delete(:show_in_catalog); x.nil? ? false : x))
1532
- @show_in_harmonization = HttpClient::Preconditions.assert_boolean('show_in_harmonization', (x = opts.delete(:show_in_harmonization); x.nil? ? false : x))
1533
- end
1534
-
1535
- def to_json
1536
- JSON.dump(to_hash)
1537
- end
1538
-
1539
- def copy(incoming={})
1540
- Options.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1541
- end
1542
-
1543
- def to_hash
1544
- {
1545
- :show_in_catalog => show_in_catalog,
1546
- :show_in_harmonization => show_in_harmonization
1547
- }
1548
- end
1549
-
1550
- end
1551
-
1552
- # Presentation for UI that is used to generate a localized price function
1553
- class Presets
1554
-
1555
- attr_reader :adjustments, :levies
1556
-
1557
- def initialize(incoming={})
1558
- opts = HttpClient::Helper.symbolize_keys(incoming)
1559
- @adjustments = HttpClient::Preconditions.assert_class('adjustments', (x = opts.delete(:adjustments); x.nil? ? [] : x), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Catalog::V0::Models::Adjustment) ? x : ::Io::Flow::Catalog::V0::Models::Adjustment.from_json(x)) }
1560
- @levies = HttpClient::Preconditions.assert_class('levies', (x = opts.delete(:levies); x.nil? ? [] : x), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Catalog::V0::Models::Levy) ? x : ::Io::Flow::Catalog::V0::Models::Levy.apply(x)) }
1561
- end
1562
-
1563
- def to_json
1564
- JSON.dump(to_hash)
1565
- end
1566
-
1567
- def copy(incoming={})
1568
- Presets.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1569
- end
1570
-
1571
- def to_hash
1572
- {
1573
- :adjustments => adjustments.map { |o| o.to_hash },
1574
- :levies => levies.map { |o| o.value }
1575
- }
1576
- end
1577
-
1578
- end
1579
-
1580
- class Price
1581
-
1582
- attr_reader :amount, :label
1583
-
1584
- def initialize(incoming={})
1585
- opts = HttpClient::Helper.symbolize_keys(incoming)
1586
- HttpClient::Preconditions.require_keys(opts, [:amount, :label], 'Price')
1587
- @amount = HttpClient::Preconditions.assert_class('amount', opts.delete(:amount), Numeric)
1588
- @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String)
1589
- end
1590
-
1591
- def to_json
1592
- JSON.dump(to_hash)
1593
- end
1594
-
1595
- def copy(incoming={})
1596
- Price.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1597
- end
1598
-
1599
- def to_hash
1600
- {
1601
- :amount => amount,
1602
- :label => label
1603
- }
1604
- end
1605
-
1606
- end
1607
-
1608
- class Rounding < Adjustment
1609
-
1610
- attr_reader :name, :rounding_method, :value
1611
-
1612
- def initialize(incoming={})
1613
- super(:name => Adjustment::Types::ROUNDING)
1614
- opts = HttpClient::Helper.symbolize_keys(incoming)
1615
- HttpClient::Preconditions.require_keys(opts, [:name, :rounding_method, :value], 'Rounding')
1616
- @name = (x = opts.delete(:name); x.is_a?(::Io::Flow::Catalog::V0::Models::AdjustmentType) ? x : ::Io::Flow::Catalog::V0::Models::AdjustmentType.apply(x))
1617
- @rounding_method = (x = opts.delete(:rounding_method); x.is_a?(::Io::Flow::Catalog::V0::Models::RoundingMethod) ? x : ::Io::Flow::Catalog::V0::Models::RoundingMethod.apply(x))
1618
- @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), Numeric)
1619
- end
1620
-
1621
- def to_json
1622
- JSON.dump(to_hash)
1623
- end
1624
-
1625
- def copy(incoming={})
1626
- Rounding.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1627
- end
1628
-
1629
- def subtype_to_hash
1630
- {
1631
- :name => name.value,
1632
- :rounding_method => rounding_method.value,
1633
- :value => value
1634
- }
1635
- end
1636
-
1637
- end
1638
-
1639
- # A configuration with custom query to select a subset of master catalog items
1640
- # for a localized experience
1641
- class Subcatalog < ExpandableSubcatalog
1642
-
1643
- attr_reader :id, :catalog, :country, :key, :settings, :query
1644
-
1645
- def initialize(incoming={})
1646
- super(:name => ExpandableSubcatalog::Types::SUBCATALOG)
1647
- opts = HttpClient::Helper.symbolize_keys(incoming)
1648
- HttpClient::Preconditions.require_keys(opts, [:id, :catalog, :country, :key, :settings], 'Subcatalog')
1649
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1650
- @catalog = (x = opts.delete(:catalog); x.is_a?(::Io::Flow::Catalog::V0::Models::Catalog) ? x : ::Io::Flow::Catalog::V0::Models::Catalog.new(x))
1651
- @country = HttpClient::Preconditions.assert_class('country', opts.delete(:country), String)
1652
- @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
1653
- @settings = (x = opts.delete(:settings); x.is_a?(::Io::Flow::Catalog::V0::Models::SubcatalogSettings) ? x : ::Io::Flow::Catalog::V0::Models::SubcatalogSettings.new(x))
1654
- @query = (x = opts.delete(:query); x.nil? ? nil : HttpClient::Preconditions.assert_class('query', x, String))
1655
- end
1656
-
1657
- def to_json
1658
- JSON.dump(to_hash)
1659
- end
1660
-
1661
- def copy(incoming={})
1662
- Subcatalog.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1663
- end
1664
-
1665
- def subtype_to_hash
1666
- {
1667
- :id => id,
1668
- :catalog => catalog.to_hash,
1669
- :country => country,
1670
- :key => key,
1671
- :settings => settings.to_hash,
1672
- :query => query
1673
- }
1674
- end
1675
-
1676
- end
1677
-
1678
- class SubcatalogForm
1679
-
1680
- attr_reader :country, :key, :query, :settings
1681
-
1682
- def initialize(incoming={})
1683
- opts = HttpClient::Helper.symbolize_keys(incoming)
1684
- HttpClient::Preconditions.require_keys(opts, [:country], 'SubcatalogForm')
1685
- @country = HttpClient::Preconditions.assert_class('country', opts.delete(:country), String)
1686
- @key = (x = opts.delete(:key); x.nil? ? nil : HttpClient::Preconditions.assert_class('key', x, String))
1687
- @query = (x = opts.delete(:query); x.nil? ? nil : HttpClient::Preconditions.assert_class('query', x, String))
1688
- @settings = (x = opts.delete(:settings); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::SubcatalogSettingsForm) ? x : ::Io::Flow::Catalog::V0::Models::SubcatalogSettingsForm.new(x)))
1689
- end
1690
-
1691
- def to_json
1692
- JSON.dump(to_hash)
1693
- end
1694
-
1695
- def copy(incoming={})
1696
- SubcatalogForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1697
- end
1698
-
1699
- def to_hash
1700
- {
1701
- :country => country,
1702
- :key => key,
1703
- :query => query,
1704
- :settings => settings.nil? ? nil : settings.to_hash
1705
- }
1706
- end
1707
-
1708
- end
1709
-
1710
- class SubcatalogItem
1711
-
1712
- attr_reader :id
1713
-
1714
- def initialize(incoming={})
1715
- opts = HttpClient::Helper.symbolize_keys(incoming)
1716
- HttpClient::Preconditions.require_keys(opts, [:id], 'SubcatalogItem')
1717
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1718
- end
1719
-
1720
- def to_json
1721
- JSON.dump(to_hash)
1722
- end
1723
-
1724
- def copy(incoming={})
1725
- SubcatalogItem.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1726
- end
1727
-
1728
- def to_hash
1729
- {
1730
- :id => id
1731
- }
1732
- end
1733
-
1734
- end
1735
-
1736
- class SubcatalogReference < ExpandableSubcatalog
1737
-
1738
- attr_reader :id
1739
-
1740
- def initialize(incoming={})
1741
- super(:name => ExpandableSubcatalog::Types::SUBCATALOG_REFERENCE)
1742
- opts = HttpClient::Helper.symbolize_keys(incoming)
1743
- HttpClient::Preconditions.require_keys(opts, [:id], 'SubcatalogReference')
1744
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1745
- end
1746
-
1747
- def to_json
1748
- JSON.dump(to_hash)
1749
- end
1750
-
1751
- def copy(incoming={})
1752
- SubcatalogReference.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1753
- end
1754
-
1755
- def subtype_to_hash
1756
- {
1757
- :id => id
1758
- }
1759
- end
1760
-
1761
- end
1762
-
1763
- class SubcatalogSettings
1764
-
1765
- attr_reader :update_policy
1766
-
1767
- def initialize(incoming={})
1768
- opts = HttpClient::Helper.symbolize_keys(incoming)
1769
- @update_policy = (x = (x = opts.delete(:update_policy); x.nil? ? "auto" : x); x.is_a?(::Io::Flow::Catalog::V0::Models::UpdatePolicy) ? x : ::Io::Flow::Catalog::V0::Models::UpdatePolicy.apply(x))
1770
- end
1771
-
1772
- def to_json
1773
- JSON.dump(to_hash)
1774
- end
1775
-
1776
- def copy(incoming={})
1777
- SubcatalogSettings.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1778
- end
1779
-
1780
- def to_hash
1781
- {
1782
- :update_policy => update_policy.value
1783
- }
1784
- end
1785
-
1786
- end
1787
-
1788
- class SubcatalogSettingsForm
1789
-
1790
- attr_reader :update_policy
1791
-
1792
- def initialize(incoming={})
1793
- opts = HttpClient::Helper.symbolize_keys(incoming)
1794
- @update_policy = (x = opts.delete(:update_policy); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::UpdatePolicy) ? x : ::Io::Flow::Catalog::V0::Models::UpdatePolicy.apply(x)))
1795
- end
1796
-
1797
- def to_json
1798
- JSON.dump(to_hash)
1799
- end
1800
-
1801
- def copy(incoming={})
1802
- SubcatalogSettingsForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1803
- end
1804
-
1805
- def to_hash
1806
- {
1807
- :update_policy => update_policy.nil? ? nil : update_policy.value
1808
- }
1809
- end
1810
-
1811
- end
1812
-
1813
- class SubcatalogVersion
1814
-
1815
- attr_reader :id, :timestamp, :type, :subcatalog
1816
-
1817
- def initialize(incoming={})
1818
- opts = HttpClient::Helper.symbolize_keys(incoming)
1819
- HttpClient::Preconditions.require_keys(opts, [:id, :timestamp, :type, :subcatalog], 'SubcatalogVersion')
1820
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1821
- @timestamp = HttpClient::Preconditions.assert_class('timestamp', HttpClient::Helper.to_date_time_iso8601(opts.delete(:timestamp)), DateTime)
1822
- @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Common::V0::Models::ChangeType) ? x : ::Io::Flow::Common::V0::Models::ChangeType.apply(x))
1823
- @subcatalog = (x = opts.delete(:subcatalog); x.is_a?(::Io::Flow::Catalog::V0::Models::Subcatalog) ? x : ::Io::Flow::Catalog::V0::Models::Subcatalog.new(x))
1824
- end
1825
-
1826
- def to_json
1827
- JSON.dump(to_hash)
1828
- end
1829
-
1830
- def copy(incoming={})
1831
- SubcatalogVersion.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1832
- end
1833
-
1834
- def to_hash
1835
- {
1836
- :id => id,
1837
- :timestamp => timestamp,
1838
- :type => type.value,
1839
- :subcatalog => subcatalog.to_hash
1840
- }
1841
- end
1842
-
1843
- end
1844
-
1845
- end
1846
-
1847
- # ===== END OF SERVICE DEFINITION =====
1848
- module HttpClient
1849
-
1850
- class Request
1851
-
1852
- def initialize(uri)
1853
- @uri = Preconditions.assert_class('uri', uri, URI)
1854
- @params = nil
1855
- @body = nil
1856
- @auth = nil
1857
- @headers = {}
1858
- @header_keys_lower_case = []
1859
- end
1860
-
1861
- def with_header(name, value)
1862
- Preconditions.check_not_blank('name', name, "Header name is required")
1863
- Preconditions.check_not_blank('value', value, "Header value is required")
1864
- Preconditions.check_state(!@headers.has_key?(name),
1865
- "Duplicate header named[%s]" % name)
1866
- @headers[name] = value
1867
- @header_keys_lower_case << name.downcase
1868
- self
1869
- end
1870
-
1871
- def with_auth(auth)
1872
- Preconditions.assert_class('auth', auth, HttpClient::Authorization)
1873
- Preconditions.check_state(@auth.nil?, "auth previously set")
1874
-
1875
- if auth.scheme.name == AuthScheme::BASIC.name
1876
- @auth = auth
1877
- else
1878
- raise "Auth Scheme[#{auth.scheme.name}] not supported"
1879
- end
1880
- self
1881
- end
1882
-
1883
- def with_query(params)
1884
- Preconditions.assert_class('params', params, Hash)
1885
- Preconditions.check_state(@params.nil?, "Already have query parameters")
1886
- @params = params
1887
- self
1888
- end
1889
-
1890
- # Wrapper to set Content-Type header to application/json and set
1891
- # the provided json document as the body
1892
- def with_json(json)
1893
- @headers['Content-Type'] ||= 'application/json; charset=UTF-8'
1894
- with_body(json)
1895
- end
1896
-
1897
- def with_body(body)
1898
- Preconditions.check_not_blank('body', body)
1899
- @body = body
1900
- self
1901
- end
1902
-
1903
- # Creates a new Net:HTTP client. The client returned should be
1904
- # fully configured to make a request.
1905
- def new_http_client
1906
- client = Net::HTTP.new(@uri.host, @uri.port)
1907
- if @uri.scheme == "https"
1908
- configure_ssl(client)
1909
- end
1910
- client
1911
- end
1912
-
1913
- # If HTTPS is required, this method accepts an HTTP Client and configures SSL
1914
- def configure_ssl(http)
1915
- Preconditions.assert_class('http', http, Net::HTTP)
1916
- http.use_ssl = true
1917
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
1918
- http.cert_store = OpenSSL::X509::Store.new
1919
- http.cert_store.set_default_paths
1920
- end
1921
-
1922
- def get(&block)
1923
- do_request(Net::HTTP::Get, &block)
1924
- end
1925
-
1926
- def delete(&block)
1927
- do_request(Net::HTTP::Delete, &block)
1928
- end
1929
-
1930
- def options(&block)
1931
- do_request(Net::HTTP::Options, &block)
1932
- end
1933
-
1934
- def post(&block)
1935
- do_request(Net::HTTP::Post, &block)
1936
- end
1937
-
1938
- def put(&block)
1939
- do_request(Net::HTTP::Put, &block)
1940
- end
1941
-
1942
- class PATCH < Net::HTTP::Put
1943
- METHOD = "PATCH"
1944
- end
1945
-
1946
- def patch(&block)
1947
- do_request(PATCH, &block)
1948
- end
1949
-
1950
- def do_request(klass)
1951
- Preconditions.assert_class('klass', klass, Class)
1952
-
1953
- uri = @uri.to_s
1954
- if q = to_query(@params)
1955
- uri += "?%s" % q
1956
- end
1957
-
1958
- request = klass.send(:new, uri)
1959
-
1960
- curl = ['curl']
1961
- if klass != Net::HTTP::Get
1962
- curl << "-X%s" % klass.name.split("::").last.upcase
1963
- end
1964
-
1965
- if @body
1966
- # DEBUG path = "/tmp/rest_client.tmp"
1967
- # DEBUG File.open(path, "w") { |os| os << @body.to_s }
1968
- # DEBUG curl << "-d@%s" % path
1969
- request.body = @body
1970
- end
1971
-
1972
- if @auth
1973
- curl << "-u \"%s:%s\"" % [@auth.username, @auth.password]
1974
- Preconditions.check_state(!@header_keys_lower_case.include?("authorization"),
1975
- "Cannot specify both an Authorization header and an auth instance")
1976
- user_pass = "%s:%s" % [@auth.username, @auth.password]
1977
- encoded = Base64.encode64(user_pass).to_s.split("\n").map(&:strip).join
1978
- request.add_field("Authorization", "Basic %s" % encoded)
1979
- end
1980
-
1981
- @headers.each { |key, value|
1982
- curl << "-H \"%s: %s\"" % [key, value]
1983
- request.add_field(key, value)
1984
- }
1985
-
1986
- curl << "'%s'" % uri
1987
- # DEBUG puts curl.join(" ")
1988
-
1989
- raw_response = http_request(request)
1990
- response = raw_response.to_s == "" ? nil : JSON.parse(raw_response)
1991
-
1992
- if block_given?
1993
- yield response
1994
- else
1995
- response
1996
- end
1997
- end
1998
-
1999
- private
2000
- def to_query(params={})
2001
- parts = (params || {}).map { |k,v|
2002
- if v.respond_to?(:each)
2003
- v.map { |el| "%s=%s" % [k, CGI.escape(el.to_s)] }
2004
- else
2005
- "%s=%s" % [k, CGI.escape(v.to_s)]
2006
- end
2007
- }
2008
- parts.empty? ? nil : parts.join("&")
2009
- end
2010
-
2011
- def http_request(request)
2012
- response = begin
2013
- new_http_client.request(request)
2014
- rescue SocketError => e
2015
- raise Exception.new("Error accessing uri[#{@uri}]: #{e}")
2016
- end
2017
-
2018
- case response
2019
- when Net::HTTPSuccess
2020
- response.body
2021
- else
2022
- body = response.body rescue nil
2023
- raise HttpClient::ServerError.new(response.code.to_i, response.message, :body => body, :uri => @uri.to_s)
2024
- end
2025
- end
2026
- end
2027
-
2028
- class ServerError < StandardError
2029
-
2030
- attr_reader :code, :details, :body, :uri
2031
-
2032
- def initialize(code, details, incoming={})
2033
- opts = HttpClient::Helper.symbolize_keys(incoming)
2034
- @code = HttpClient::Preconditions.assert_class('code', code, Integer)
2035
- @details = HttpClient::Preconditions.assert_class('details', details, String)
2036
- @body = HttpClient::Preconditions.assert_class_or_nil('body', opts.delete(:body), String)
2037
- @uri = HttpClient::Preconditions.assert_class_or_nil('uri', opts.delete(:uri), String)
2038
- HttpClient::Preconditions.assert_empty_opts(opts)
2039
- super(self.message)
2040
- end
2041
-
2042
- def message
2043
- m = "%s %s" % [@code, @details]
2044
- if @body
2045
- m << ": %s" % @body
2046
- end
2047
- m
2048
- end
2049
-
2050
- def body_json
2051
- JSON.parse(@body)
2052
- end
2053
-
2054
- end
2055
-
2056
- class PreconditionException < Exception
2057
-
2058
- attr_reader :message
2059
-
2060
- def initialize(message)
2061
- super(message)
2062
- @message = message
2063
- end
2064
-
2065
- end
2066
-
2067
- module Preconditions
2068
-
2069
- def Preconditions.check_argument(expression, error_message=nil)
2070
- if !expression
2071
- raise PreconditionException.new(error_message || "check_argument failed")
2072
- end
2073
- nil
2074
- end
2075
-
2076
- def Preconditions.check_state(expression, error_message=nil)
2077
- if !expression
2078
- raise PreconditionException.new(error_message || "check_state failed")
2079
- end
2080
- nil
2081
- end
2082
-
2083
- def Preconditions.check_not_nil(field_name, reference, error_message=nil)
2084
- if reference.nil?
2085
- raise PreconditionException.new(error_message || "argument for %s cannot be nil" % field_name)
2086
- end
2087
- reference
2088
- end
2089
-
2090
- def Preconditions.check_not_blank(field_name, reference, error_message=nil)
2091
- if reference.to_s.strip == ""
2092
- raise PreconditionException.new(error_message || "argument for %s cannot be blank" % field_name)
2093
- end
2094
- reference
2095
- end
2096
-
2097
- # Throws an error if opts is not empty. Useful when parsing
2098
- # arguments to a function
2099
- def Preconditions.assert_empty_opts(opts)
2100
- if !opts.empty?
2101
- raise PreconditionException.new("Invalid opts: #{opts.keys.inspect}\n#{opts.inspect}")
2102
- end
2103
- end
2104
-
2105
- # Requires that the provided hash has the specified keys.
2106
- # @param fields A list of symbols
2107
- def Preconditions.require_keys(hash, fields, error_prefix=nil)
2108
- missing = fields.select { |f| !hash.has_key?(f) }
2109
- if !missing.empty?
2110
- msg = "Missing required fields: " + missing.join(", ")
2111
- raise PreconditionException.new(error_prefix.empty? ? msg : "#{error_prefix}: #{msg}")
2112
- end
2113
- end
2114
-
2115
- # Asserts that value is not nill and is_?(klass). Returns
2116
- # value. Common use is
2117
- #
2118
- # amount = Preconditions.assert_class('amount', amount, BigDecimal)
2119
- def Preconditions.assert_class(field_name, value, klass)
2120
- Preconditions.check_not_nil('field_name', field_name)
2121
- Preconditions.check_not_nil('klass', klass)
2122
- Preconditions.check_not_nil('value', value, "Value for %s cannot be nil. Expected an instance of class %s" % [field_name, klass.name])
2123
- Preconditions.check_state(value.is_a?(klass),
2124
- "Value for #{field_name} is of type[#{value.class}] - class[#{klass}] is required. value[#{value.inspect.to_s}]")
2125
- value
2126
- end
2127
-
2128
- def Preconditions.assert_class_or_nil(field_name, value, klass)
2129
- if !value.nil?
2130
- Preconditions.assert_class(field_name, value, klass)
2131
- end
2132
- end
2133
-
2134
- def Preconditions.assert_boolean(field_name, value)
2135
- Preconditions.check_not_nil('field_name', field_name)
2136
- Preconditions.check_not_nil('value', value, "Value for %s cannot be nil. Expected an instance of TrueClass or FalseClass" % field_name)
2137
- Preconditions.check_state(value.is_a?(TrueClass) || value.is_a?(FalseClass),
2138
- "Value for #{field_name} is of type[#{value.class}] - class[TrueClass or FalseClass] is required. value[#{value.inspect.to_s}]")
2139
- value
2140
- end
2141
-
2142
- def Preconditions.assert_boolean_or_nil(field_name, value)
2143
- if !value.nil?
2144
- Preconditions.assert_boolean(field_name, value)
2145
- end
2146
- end
2147
-
2148
- def Preconditions.assert_collection_of_class(field_name, values, klass)
2149
- Preconditions.assert_class(field_name, values, Array)
2150
- values.each { |v| Preconditions.assert_class(field_name, v, klass) }
2151
- end
2152
-
2153
- def Preconditions.assert_hash_of_class(field_name, hash, klass)
2154
- Preconditions.assert_class(field_name, hash, Hash)
2155
- values.each { |k, v| Preconditions.assert_class(field_name, v, klass) }
2156
- end
2157
-
2158
- end
2159
-
2160
- class AuthScheme
2161
-
2162
- attr_reader :name
2163
-
2164
- def initialize(name)
2165
- @name = HttpClient::Preconditions.check_not_blank('name', name)
2166
- end
2167
-
2168
- BASIC = AuthScheme.new("basic") unless defined?(BASIC)
2169
-
2170
- end
2171
-
2172
- class Authorization
2173
-
2174
- attr_reader :scheme, :username, :password
2175
-
2176
- def initialize(scheme, username, opts={})
2177
- @scheme = HttpClient::Preconditions.assert_class('schema', scheme, AuthScheme)
2178
- @username = HttpClient::Preconditions.check_not_blank('username', username, "username is required")
2179
- @password = HttpClient::Preconditions.assert_class_or_nil('password', opts.delete(:password), String)
2180
- HttpClient::Preconditions.assert_empty_opts(opts)
2181
- end
2182
-
2183
- def Authorization.basic(username, password=nil)
2184
- Authorization.new(AuthScheme::BASIC, username, :password => password)
2185
- end
2186
-
2187
- end
2188
-
2189
- module Helper
2190
-
2191
- def Helper.symbolize_keys(hash)
2192
- Preconditions.assert_class('hash', hash, Hash)
2193
- new_hash = {}
2194
- hash.each { |k, v|
2195
- new_hash[k.to_sym] = v
2196
- }
2197
- new_hash
2198
- end
2199
-
2200
- def Helper.to_big_decimal(value)
2201
- value ? BigDecimal.new(value.to_s) : nil
2202
- end
2203
-
2204
- def Helper.to_object(value)
2205
- value ? JSON.parse(value) : nil
2206
- end
2207
-
2208
- def Helper.to_uuid(value)
2209
- Preconditions.check_state(value.nil? || value.match(/^\w\w\w\w\w\w\w\w\-\w\w\w\w\-\w\w\w\w\-\w\w\w\w\-\w\w\w\w\w\w\w\w\w\w\w\w$/),
2210
- "Invalid guid[%s]" % value)
2211
- value
2212
- end
2213
-
2214
- def Helper.to_date_iso8601(value)
2215
- if value.is_a?(Date)
2216
- value
2217
- elsif value
2218
- Date.parse(value.to_s)
2219
- else
2220
- nil
2221
- end
2222
- end
2223
-
2224
- def Helper.to_date_time_iso8601(value)
2225
- if value.is_a?(DateTime)
2226
- value
2227
- elsif value
2228
- DateTime.parse(value.to_s)
2229
- else
2230
- nil
2231
- end
2232
- end
2233
-
2234
- def Helper.date_iso8601_to_string(value)
2235
- value.nil? ? nil : value.strftime('%Y-%m-%d')
2236
- end
2237
-
2238
- def Helper.date_time_iso8601_to_string(value)
2239
- value.nil? ? nil : value.strftime('%Y-%m-%dT%H:%M:%S%z')
2240
- end
2241
-
2242
- TRUE_STRINGS = ['t', 'true', 'y', 'yes', 'on', '1', 'trueclass'] unless defined?(TRUE_STRINGS)
2243
- FALSE_STRINGS = ['f', 'false', 'n', 'no', 'off', '0', 'falseclass'] unless defined?(FALSE_STRINGS)
2244
-
2245
- def Helper.to_boolean(field_name, value)
2246
- string = value.to_s.strip.downcase
2247
- if TRUE_STRINGS.include?(string)
2248
- true
2249
- elsif FALSE_STRINGS.include?(string)
2250
- false
2251
- elsif string != ""
2252
- raise PreconditionException.new("Unsupported boolean value[#{string}]. For true, must be one of: #{TRUE_STRINGS.inspect}. For false, must be one of: #{FALSE_STRINGS.inspect}")
2253
- else
2254
- nil
2255
- end
2256
- end
2257
-
2258
- end
2259
-
2260
- end
2261
- end
2262
- end
2263
- end
2264
- end