flowcommerce 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 570243d812d3c483da4005057b58212e2929a7ae
4
+ data.tar.gz: d938fc2f031f75fc3c9a354e95f2807dd5430519
5
+ SHA512:
6
+ metadata.gz: b2eec06f709ef8ae3b9939b6f23cc4cfa124bb3e40353cf67217a74557b762fe2cb2718af40b794ad7a203e4827a7b2971d862c1c6cb69bd42e50d8866962612
7
+ data.tar.gz: 72dd2f5bc441eb7bed210f9871fd695733dfcc3a66d24cb63ce80de2f20d617fba65a45b10710015336d0209eaefc2cb01af085543e687128f12b4841807adb6
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # flow-ruby
2
+
3
+ Native ruby client to the Flow API (https://api.flow.io)
4
+
5
+ ## Installation
6
+
7
+ gem install 'flowcommerce'
8
+
9
+
10
+ ## Usage
11
+
12
+ require 'flowcommerce'
13
+
14
+ org = "demo"
15
+
16
+ client = FlowCommerce.client("api token")
17
+
18
+ catalog = client.catalogs.get_catalog(org)
19
+
20
+ items = client.view_items.get(org, "canada", :limit => 10, :offset => 0)
21
+ puts "# items in view: %s" % items.size
22
+
23
+
24
+ ## Example
25
+
26
+ See example.rb for a working example
27
+
28
+
29
+ ## Documentation
30
+
31
+ The full API is documented at http://apidoc.me/flow/catalog/latest
32
+
33
+ Also look at
34
+ https://github.com/flowcommerce/ruby-sdk/blob/master/lib/clients/flow_catalog_v0_client.rb
35
+ for the complete Ruby implementation of the API.
@@ -0,0 +1,1672 @@
1
+ # Generated by apidoc - http://www.apidoc.me
2
+ # Service version: 0.0.11
3
+ # apidoc:0.11.17 http://www.apidoc.me/flow/catalog/0.0.11/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
+ module Io
17
+ module Flow
18
+ module Catalog
19
+ module V0
20
+
21
+ class Client
22
+
23
+ module Constants
24
+
25
+ BASE_URL = 'https://catalog.api.flow.io' unless defined?(Constants::BASE_URL)
26
+ NAMESPACE = 'io.flow.catalog.v0' unless defined?(Constants::NAMESPACE)
27
+ USER_AGENT = 'apidoc:0.11.17 http://www.apidoc.me/flow/catalog/0.0.11/ruby_client' unless defined?(Constants::USER_AGENT)
28
+ VERSION = '0.0.11' unless defined?(Constants::VERSION)
29
+ VERSION_MAJOR = 0 unless defined?(VERSION_MAJOR)
30
+
31
+ end
32
+
33
+ attr_reader :url
34
+
35
+ def initialize(url, opts={})
36
+ @url = HttpClient::Preconditions.assert_class('url', url, String)
37
+ @authorization = HttpClient::Preconditions.assert_class_or_nil('authorization', opts.delete(:authorization), HttpClient::Authorization)
38
+ @default_headers = HttpClient::Preconditions.assert_class('default_headers', opts.delete(:default_headers) || {}, Hash)
39
+ HttpClient::Preconditions.assert_empty_opts(opts)
40
+ HttpClient::Preconditions.check_state(url.match(/http.+/i), "URL[%s] must start with http" % url)
41
+ end
42
+
43
+ # Creates an instance of the client using the base url specified in the API spec.
44
+ def Client.at_base_url(opts={})
45
+ Client.new(Constants::BASE_URL, opts)
46
+ end
47
+
48
+ def request(path=nil)
49
+ HttpClient::Preconditions.assert_class_or_nil('path', path, String)
50
+ 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)
51
+
52
+ @default_headers.each do |key, value|
53
+ request = request.with_header(key, value)
54
+ end
55
+
56
+ if @authorization
57
+ request = request.with_auth(@authorization)
58
+ end
59
+
60
+ request
61
+ end
62
+
63
+ def catalogs
64
+ @catalogs ||= ::Io::Flow::Catalog::V0::Clients::Catalogs.new(self)
65
+ end
66
+
67
+ def catalog_items
68
+ @catalog_items ||= ::Io::Flow::Catalog::V0::Clients::CatalogItems.new(self)
69
+ end
70
+
71
+ def healthchecks
72
+ @healthchecks ||= ::Io::Flow::Catalog::V0::Clients::Healthchecks.new(self)
73
+ end
74
+
75
+ def views
76
+ @views ||= ::Io::Flow::Catalog::V0::Clients::Views.new(self)
77
+ end
78
+
79
+ def view_items
80
+ @view_items ||= ::Io::Flow::Catalog::V0::Clients::ViewItems.new(self)
81
+ end
82
+ end
83
+
84
+ module Clients
85
+
86
+ class Catalogs
87
+
88
+ def initialize(client)
89
+ @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Catalog::V0::Client)
90
+ end
91
+
92
+ # Returns information about a specific catalog.
93
+ def get_catalog(organization)
94
+ HttpClient::Preconditions.assert_class('organization', organization, String)
95
+ r = @client.request("/#{CGI.escape(organization)}/catalog").get
96
+ ::Io::Flow::Catalog::V0::Models::Catalog.new(r)
97
+ end
98
+
99
+ end
100
+
101
+ class CatalogItems
102
+
103
+ def initialize(client)
104
+ @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Catalog::V0::Client)
105
+ end
106
+
107
+ # Provides visibility into recent changes of each object, including deletion
108
+ def get_versions(organization, incoming={})
109
+ HttpClient::Preconditions.assert_class('organization', organization, String)
110
+ opts = HttpClient::Helper.symbolize_keys(incoming)
111
+ query = {
112
+ :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
113
+ :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
114
+ :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
115
+ :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
116
+ :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "journal_timestamp" : x), String)
117
+ }.delete_if { |k, v| v.nil? }
118
+ r = @client.request("/#{CGI.escape(organization)}/catalog/items/versions").with_query(query).get
119
+ r.map { |x| ::Io::Flow::Catalog::V0::Models::ItemVersion.new(x) }
120
+ end
121
+
122
+ # Search items. Always paginated.
123
+ def get(organization, incoming={})
124
+ HttpClient::Preconditions.assert_class('organization', organization, String)
125
+ opts = HttpClient::Helper.symbolize_keys(incoming)
126
+ query = {
127
+ :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
128
+ :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
129
+ :query => (x = opts.delete(:query); x.nil? ? nil : HttpClient::Preconditions.assert_class('query', x, String)),
130
+ :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
131
+ :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
132
+ :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-created_at" : x), String)
133
+ }.delete_if { |k, v| v.nil? }
134
+ r = @client.request("/#{CGI.escape(organization)}/catalog/items").with_query(query).get
135
+ r.map { |x| ::Io::Flow::Catalog::V0::Models::Item.new(x) }
136
+ end
137
+
138
+ # Returns information about a specific item.
139
+ def get_by_id(organization, id)
140
+ HttpClient::Preconditions.assert_class('organization', organization, String)
141
+ HttpClient::Preconditions.assert_class('id', id, String)
142
+ r = @client.request("/#{CGI.escape(organization)}/catalog/items/#{CGI.escape(id)}").get
143
+ ::Io::Flow::Catalog::V0::Models::Item.new(r)
144
+ end
145
+
146
+ # Add catalog item(s)
147
+ def post(organization, item_form)
148
+ HttpClient::Preconditions.assert_class('organization', organization, String)
149
+ HttpClient::Preconditions.assert_class('item_form', item_form, ::Io::Flow::Catalog::V0::Models::ItemForm)
150
+ r = @client.request("/#{CGI.escape(organization)}/catalog/items").with_json(item_form.to_json).post
151
+ ::Io::Flow::Catalog::V0::Models::Item.new(r)
152
+ end
153
+
154
+ # Update item with the specified id, creating if it does not exist.
155
+ def put_by_id(organization, id, item_form)
156
+ HttpClient::Preconditions.assert_class('organization', organization, String)
157
+ HttpClient::Preconditions.assert_class('id', id, String)
158
+ HttpClient::Preconditions.assert_class('item_form', item_form, ::Io::Flow::Catalog::V0::Models::ItemForm)
159
+ r = @client.request("/#{CGI.escape(organization)}/catalog/items/#{CGI.escape(id)}").with_json(item_form.to_json).put
160
+ ::Io::Flow::Catalog::V0::Models::Item.new(r)
161
+ end
162
+
163
+ # Delete the item with this id
164
+ def delete_by_id(organization, id)
165
+ HttpClient::Preconditions.assert_class('organization', organization, String)
166
+ HttpClient::Preconditions.assert_class('id', id, String)
167
+ r = @client.request("/#{CGI.escape(organization)}/catalog/items/#{CGI.escape(id)}").delete
168
+ nil
169
+ end
170
+
171
+ end
172
+
173
+ class Healthchecks
174
+
175
+ def initialize(client)
176
+ @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Catalog::V0::Client)
177
+ end
178
+
179
+ def get_healthcheck
180
+ r = @client.request("/_internal_/healthcheck").get
181
+ ::Io::Flow::Common::V0::Models::Healthcheck.new(r)
182
+ end
183
+
184
+ end
185
+
186
+ class Views
187
+
188
+ def initialize(client)
189
+ @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Catalog::V0::Client)
190
+ end
191
+
192
+ # Provides visibility into recent changes of each object, including deletion
193
+ def get_versions(organization, incoming={})
194
+ HttpClient::Preconditions.assert_class('organization', organization, String)
195
+ opts = HttpClient::Helper.symbolize_keys(incoming)
196
+ query = {
197
+ :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
198
+ :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
199
+ :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
200
+ :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "journal_timestamp" : x), String)
201
+ }.delete_if { |k, v| v.nil? }
202
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views/versions").with_query(query).get
203
+ r.map { |x| ::Io::Flow::Catalog::V0::Models::ViewVersion.new(x) }
204
+ end
205
+
206
+ # Search views. Always paginated.
207
+ def get(organization, incoming={})
208
+ HttpClient::Preconditions.assert_class('organization', organization, String)
209
+ opts = HttpClient::Helper.symbolize_keys(incoming)
210
+ query = {
211
+ :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
212
+ :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
213
+ :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
214
+ :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-created_at" : x), String)
215
+ }.delete_if { |k, v| v.nil? }
216
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views").with_query(query).get
217
+ r.map { |x| ::Io::Flow::Catalog::V0::Models::View.new(x) }
218
+ end
219
+
220
+ # Returns information about a specific view.
221
+ def get_by_id(organization, id)
222
+ HttpClient::Preconditions.assert_class('organization', organization, String)
223
+ HttpClient::Preconditions.assert_class('id', id, String)
224
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views/#{CGI.escape(id)}").get
225
+ ::Io::Flow::Catalog::V0::Models::View.new(r)
226
+ end
227
+
228
+ # Add view
229
+ def post(organization, view_form)
230
+ HttpClient::Preconditions.assert_class('organization', organization, String)
231
+ HttpClient::Preconditions.assert_class('view_form', view_form, ::Io::Flow::Catalog::V0::Models::ViewForm)
232
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views").with_json(view_form.to_json).post
233
+ ::Io::Flow::Catalog::V0::Models::View.new(r)
234
+ end
235
+
236
+ # Update view with the specified id, creating if it does not exist.
237
+ def put_by_id(organization, id, view_form)
238
+ HttpClient::Preconditions.assert_class('organization', organization, String)
239
+ HttpClient::Preconditions.assert_class('id', id, String)
240
+ HttpClient::Preconditions.assert_class('view_form', view_form, ::Io::Flow::Catalog::V0::Models::ViewForm)
241
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views/#{CGI.escape(id)}").with_json(view_form.to_json).put
242
+ ::Io::Flow::Catalog::V0::Models::View.new(r)
243
+ end
244
+
245
+ # Delete the view with this id
246
+ def delete_by_id(organization, id)
247
+ HttpClient::Preconditions.assert_class('organization', organization, String)
248
+ HttpClient::Preconditions.assert_class('id', id, String)
249
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views/#{CGI.escape(id)}").delete
250
+ nil
251
+ end
252
+
253
+ # Returns information about a specific view's settings.
254
+ def get_settings_by_id(organization, id)
255
+ HttpClient::Preconditions.assert_class('organization', organization, String)
256
+ HttpClient::Preconditions.assert_class('id', id, String)
257
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views/#{CGI.escape(id)}/settings").get
258
+ ::Io::Flow::Catalog::V0::Models::ViewSettings.new(r)
259
+ end
260
+
261
+ # Update view settings for the specified view.
262
+ def put_settings_by_id(organization, id, view_settings_form)
263
+ HttpClient::Preconditions.assert_class('organization', organization, String)
264
+ HttpClient::Preconditions.assert_class('id', id, String)
265
+ HttpClient::Preconditions.assert_class('view_settings_form', view_settings_form, ::Io::Flow::Catalog::V0::Models::ViewSettingsForm)
266
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views/#{CGI.escape(id)}/settings").with_json(view_settings_form.to_json).put
267
+ ::Io::Flow::Catalog::V0::Models::ViewSettings.new(r)
268
+ end
269
+
270
+ end
271
+
272
+ class ViewItems
273
+
274
+ def initialize(client)
275
+ @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Catalog::V0::Client)
276
+ end
277
+
278
+ # Provides visibility into recent changes of each object, including deletion
279
+ def get_versions(organization, view, incoming={})
280
+ HttpClient::Preconditions.assert_class('organization', organization, String)
281
+ HttpClient::Preconditions.assert_class('view', view, String)
282
+ opts = HttpClient::Helper.symbolize_keys(incoming)
283
+ query = {
284
+ :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
285
+ :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
286
+ :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
287
+ :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
288
+ :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "journal_timestamp" : x), String)
289
+ }.delete_if { |k, v| v.nil? }
290
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views/#{CGI.escape(view)}/items/versions").with_query(query).get
291
+ r.map { |x| ::Io::Flow::Catalog::V0::Models::ViewVersion.new(x) }
292
+ end
293
+
294
+ # Search view items. Always paginated.
295
+ def get(organization, view, incoming={})
296
+ HttpClient::Preconditions.assert_class('organization', organization, String)
297
+ HttpClient::Preconditions.assert_class('view', view, String)
298
+ opts = HttpClient::Helper.symbolize_keys(incoming)
299
+ query = {
300
+ :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
301
+ :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
302
+ :query => (x = opts.delete(:query); x.nil? ? nil : HttpClient::Preconditions.assert_class('query', x, String)),
303
+ :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
304
+ :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
305
+ :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-created_at" : x), String)
306
+ }.delete_if { |k, v| v.nil? }
307
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views/#{CGI.escape(view)}/items").with_query(query).get
308
+ r.map { |x| ::Io::Flow::Catalog::V0::Models::Item.new(x) }
309
+ end
310
+
311
+ # Returns information about specific view items.
312
+ def get_by_id(organization, view, id)
313
+ HttpClient::Preconditions.assert_class('organization', organization, String)
314
+ HttpClient::Preconditions.assert_class('view', view, String)
315
+ HttpClient::Preconditions.assert_class('id', id, String)
316
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views/#{CGI.escape(view)}/items/#{CGI.escape(id)}").get
317
+ ::Io::Flow::Catalog::V0::Models::Item.new(r)
318
+ end
319
+
320
+ # Add view item
321
+ def post(organization, view, item_form)
322
+ HttpClient::Preconditions.assert_class('organization', organization, String)
323
+ HttpClient::Preconditions.assert_class('view', view, String)
324
+ HttpClient::Preconditions.assert_class('item_form', item_form, ::Io::Flow::Catalog::V0::Models::ItemForm)
325
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views/#{CGI.escape(view)}/items").with_json(item_form.to_json).post
326
+ ::Io::Flow::Catalog::V0::Models::View.new(r)
327
+ end
328
+
329
+ # Update view item with the specified id, creating if it does not exist.
330
+ def put_by_id(organization, view, id, item_form)
331
+ HttpClient::Preconditions.assert_class('organization', organization, String)
332
+ HttpClient::Preconditions.assert_class('view', view, String)
333
+ HttpClient::Preconditions.assert_class('id', id, String)
334
+ HttpClient::Preconditions.assert_class('item_form', item_form, ::Io::Flow::Catalog::V0::Models::ItemForm)
335
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views/#{CGI.escape(view)}/items/#{CGI.escape(id)}").with_json(item_form.to_json).put
336
+ ::Io::Flow::Catalog::V0::Models::Item.new(r)
337
+ end
338
+
339
+ # Delete the view item with this id
340
+ def delete_by_id(organization, view, id)
341
+ HttpClient::Preconditions.assert_class('organization', organization, String)
342
+ HttpClient::Preconditions.assert_class('view', view, String)
343
+ HttpClient::Preconditions.assert_class('id', id, String)
344
+ r = @client.request("/#{CGI.escape(organization)}/catalog/views/#{CGI.escape(view)}/items/#{CGI.escape(id)}").delete
345
+ nil
346
+ end
347
+
348
+ end
349
+
350
+ end
351
+
352
+ module Models
353
+
354
+ class Event
355
+
356
+ module Types
357
+ ITEM_CREATED = 'item_created' unless defined?(ITEM_CREATED)
358
+ ITEM_UPDATED = 'item_updated' unless defined?(ITEM_UPDATED)
359
+ ITEM_DELETED = 'item_deleted' unless defined?(ITEM_DELETED)
360
+ end
361
+
362
+ def initialize(incoming={})
363
+ opts = HttpClient::Helper.symbolize_keys(incoming)
364
+ HttpClient::Preconditions.require_keys(opts, [:name], 'Event')
365
+ @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
366
+ end
367
+
368
+ def to_hash
369
+ subtype_to_hash.merge(:discriminator => @name)
370
+ end
371
+
372
+ def Event.from_json(hash)
373
+ HttpClient::Preconditions.assert_class('hash', hash, Hash)
374
+ case HttpClient::Helper.symbolize_keys(hash)[:discriminator]
375
+ when Types::ITEM_CREATED; ItemCreated.new(hash)
376
+ when Types::ITEM_UPDATED; ItemUpdated.new(hash)
377
+ when Types::ITEM_DELETED; ItemDeleted.new(hash)
378
+ else EventUndefinedType.new(:name => union_type_name)
379
+ end
380
+ end
381
+
382
+ end
383
+
384
+ class EventUndefinedType < Event
385
+
386
+ attr_reader :name
387
+
388
+ def initialize(incoming={})
389
+ super(:name => 'undefined_type')
390
+ opts = HttpClient::Helper.symbolize_keys(incoming)
391
+ @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
392
+ end
393
+
394
+ def subtype_to_hash
395
+ raise 'Unable to serialize undefined type to json'
396
+ end
397
+
398
+ def copy(incoming={})
399
+ raise 'Operation not supported for undefined type'
400
+ end
401
+
402
+ def to_hash
403
+ raise 'Operation not supported for undefined type'
404
+ end
405
+
406
+ end
407
+
408
+ class UpdatePolicy
409
+
410
+ attr_reader :value
411
+
412
+ def initialize(value)
413
+ @value = HttpClient::Preconditions.assert_class('value', value, String)
414
+ end
415
+
416
+ # Returns the instance of UpdatePolicy for this value, creating a new instance for an unknown value
417
+ def UpdatePolicy.apply(value)
418
+ if value.instance_of?(UpdatePolicy)
419
+ value
420
+ else
421
+ HttpClient::Preconditions.assert_class_or_nil('value', value, String)
422
+ value.nil? ? nil : (from_string(value) || UpdatePolicy.new(value))
423
+ end
424
+ end
425
+
426
+ # Returns the instance of UpdatePolicy for this value, or nil if not found
427
+ def UpdatePolicy.from_string(value)
428
+ HttpClient::Preconditions.assert_class('value', value, String)
429
+ UpdatePolicy.ALL.find { |v| v.value == value }
430
+ end
431
+
432
+ def UpdatePolicy.ALL
433
+ @@all ||= [UpdatePolicy.auto, UpdatePolicy.queue, UpdatePolicy.discard]
434
+ end
435
+
436
+ def UpdatePolicy.auto
437
+ @@_auto ||= UpdatePolicy.new('auto')
438
+ end
439
+
440
+ # Queue item update for approval.
441
+ def UpdatePolicy.queue
442
+ @@_queue ||= UpdatePolicy.new('queue')
443
+ end
444
+
445
+ def UpdatePolicy.discard
446
+ @@_discard ||= UpdatePolicy.new('discard')
447
+ end
448
+
449
+ def to_hash
450
+ value
451
+ end
452
+
453
+ end
454
+
455
+ class Attribute
456
+
457
+ attr_reader :key, :value
458
+
459
+ def initialize(incoming={})
460
+ opts = HttpClient::Helper.symbolize_keys(incoming)
461
+ HttpClient::Preconditions.require_keys(opts, [:key, :value], 'Attribute')
462
+ @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
463
+ @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), String)
464
+ end
465
+
466
+ def to_json
467
+ JSON.dump(to_hash)
468
+ end
469
+
470
+ def copy(incoming={})
471
+ Attribute.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
472
+ end
473
+
474
+ def to_hash
475
+ {
476
+ :key => key,
477
+ :value => value
478
+ }
479
+ end
480
+
481
+ end
482
+
483
+ class Catalog
484
+
485
+ attr_reader :id
486
+
487
+ def initialize(incoming={})
488
+ opts = HttpClient::Helper.symbolize_keys(incoming)
489
+ HttpClient::Preconditions.require_keys(opts, [:id], 'Catalog')
490
+ @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
491
+ end
492
+
493
+ def to_json
494
+ JSON.dump(to_hash)
495
+ end
496
+
497
+ def copy(incoming={})
498
+ Catalog.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
499
+ end
500
+
501
+ def to_hash
502
+ {
503
+ :id => id
504
+ }
505
+ end
506
+
507
+ end
508
+
509
+ class CatalogItem
510
+
511
+ attr_reader :id, :catalog, :data
512
+
513
+ def initialize(incoming={})
514
+ opts = HttpClient::Helper.symbolize_keys(incoming)
515
+ HttpClient::Preconditions.require_keys(opts, [:id, :catalog, :data], 'CatalogItem')
516
+ @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
517
+ @catalog = (x = opts.delete(:catalog); x.is_a?(::Io::Flow::Catalog::V0::Models::Catalog) ? x : ::Io::Flow::Catalog::V0::Models::Catalog.new(x))
518
+ @data = (x = opts.delete(:data); x.is_a?(::Io::Flow::Catalog::V0::Models::Item) ? x : ::Io::Flow::Catalog::V0::Models::Item.new(x))
519
+ end
520
+
521
+ def to_json
522
+ JSON.dump(to_hash)
523
+ end
524
+
525
+ def copy(incoming={})
526
+ CatalogItem.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
527
+ end
528
+
529
+ def to_hash
530
+ {
531
+ :id => id,
532
+ :catalog => catalog.to_hash,
533
+ :data => data.to_hash
534
+ }
535
+ end
536
+
537
+ end
538
+
539
+ class CatalogVersion
540
+
541
+ attr_reader :id, :timestamp, :type, :catalog
542
+
543
+ def initialize(incoming={})
544
+ opts = HttpClient::Helper.symbolize_keys(incoming)
545
+ HttpClient::Preconditions.require_keys(opts, [:id, :timestamp, :type, :catalog], 'CatalogVersion')
546
+ @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
547
+ @timestamp = HttpClient::Preconditions.assert_class('timestamp', HttpClient::Helper.to_date_time_iso8601(opts.delete(:timestamp)), DateTime)
548
+ @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Common::V0::Models::ChangeType) ? x : ::Io::Flow::Common::V0::Models::ChangeType.apply(x))
549
+ @catalog = (x = opts.delete(:catalog); x.is_a?(::Io::Flow::Catalog::V0::Models::Catalog) ? x : ::Io::Flow::Catalog::V0::Models::Catalog.new(x))
550
+ end
551
+
552
+ def to_json
553
+ JSON.dump(to_hash)
554
+ end
555
+
556
+ def copy(incoming={})
557
+ CatalogVersion.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
558
+ end
559
+
560
+ def to_hash
561
+ {
562
+ :id => id,
563
+ :timestamp => timestamp,
564
+ :type => type.value,
565
+ :catalog => catalog.to_hash
566
+ }
567
+ end
568
+
569
+ end
570
+
571
+ class Codes
572
+
573
+ attr_reader :harmonized
574
+
575
+ def initialize(incoming={})
576
+ opts = HttpClient::Helper.symbolize_keys(incoming)
577
+ @harmonized = (x = opts.delete(:harmonized); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::Harmonized) ? x : ::Io::Flow::Catalog::V0::Models::Harmonized.new(x)))
578
+ end
579
+
580
+ def to_json
581
+ JSON.dump(to_hash)
582
+ end
583
+
584
+ def copy(incoming={})
585
+ Codes.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
586
+ end
587
+
588
+ def to_hash
589
+ {
590
+ :harmonized => harmonized.nil? ? nil : harmonized.to_hash
591
+ }
592
+ end
593
+
594
+ end
595
+
596
+ class Content
597
+
598
+ attr_reader :dimensions, :locale, :price, :title, :brand, :categories, :description, :images, :policies
599
+
600
+ def initialize(incoming={})
601
+ opts = HttpClient::Helper.symbolize_keys(incoming)
602
+ HttpClient::Preconditions.require_keys(opts, [:dimensions, :locale, :price], 'Content')
603
+ @dimensions = (x = opts.delete(:dimensions); x.is_a?(::Io::Flow::Catalog::V0::Models::Dimensions) ? x : ::Io::Flow::Catalog::V0::Models::Dimensions.new(x))
604
+ @locale = (x = opts.delete(:locale); x.is_a?(::Io::Flow::Catalog::V0::Models::Locale) ? x : ::Io::Flow::Catalog::V0::Models::Locale.new(x))
605
+ @price = (x = opts.delete(:price); x.is_a?(::Io::Flow::Catalog::V0::Models::Price) ? x : ::Io::Flow::Catalog::V0::Models::Price.new(x))
606
+ @title = HttpClient::Preconditions.assert_class('title', (x = opts.delete(:title); x.nil? ? "XXXX" : x), String)
607
+ @brand = (x = opts.delete(:brand); x.nil? ? nil : HttpClient::Preconditions.assert_class('brand', x, String))
608
+ @categories = HttpClient::Preconditions.assert_class('categories', (x = opts.delete(:categories); x.nil? ? [] : x), Array).map { |v| HttpClient::Preconditions.assert_class('categories', v, String) }
609
+ @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String))
610
+ @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::Image) ? x : ::Io::Flow::Catalog::V0::Models::Image.new(x)) })
611
+ @policies = (x = opts.delete(:policies); x.nil? ? nil : HttpClient::Preconditions.assert_class('policies', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::Catalog::V0::Models::Policy) ? x : ::Io::Flow::Catalog::V0::Models::Policy.new(x)) })
612
+ end
613
+
614
+ def to_json
615
+ JSON.dump(to_hash)
616
+ end
617
+
618
+ def copy(incoming={})
619
+ Content.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
620
+ end
621
+
622
+ def to_hash
623
+ {
624
+ :dimensions => dimensions.to_hash,
625
+ :locale => locale.to_hash,
626
+ :price => price.to_hash,
627
+ :title => title,
628
+ :brand => brand,
629
+ :categories => categories,
630
+ :description => description,
631
+ :images => images.nil? ? nil : images.map { |o| o.to_hash },
632
+ :policies => policies.nil? ? nil : policies.map { |o| o.to_hash }
633
+ }
634
+ end
635
+
636
+ end
637
+
638
+ class Dimension
639
+
640
+ attr_reader :units, :value
641
+
642
+ def initialize(incoming={})
643
+ opts = HttpClient::Helper.symbolize_keys(incoming)
644
+ HttpClient::Preconditions.require_keys(opts, [:units, :value], 'Dimension')
645
+ @units = (x = opts.delete(:units); x.is_a?(::Io::Flow::Common::V0::Models::UnitOfMeasurement) ? x : ::Io::Flow::Common::V0::Models::UnitOfMeasurement.apply(x))
646
+ @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), String)
647
+ end
648
+
649
+ def to_json
650
+ JSON.dump(to_hash)
651
+ end
652
+
653
+ def copy(incoming={})
654
+ Dimension.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
655
+ end
656
+
657
+ def to_hash
658
+ {
659
+ :units => units.value,
660
+ :value => value
661
+ }
662
+ end
663
+
664
+ end
665
+
666
+ class DimensionSpecification
667
+
668
+ attr_reader :depth, :length, :weight, :width
669
+
670
+ def initialize(incoming={})
671
+ opts = HttpClient::Helper.symbolize_keys(incoming)
672
+ @depth = (x = opts.delete(:depth); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::Dimension) ? x : ::Io::Flow::Catalog::V0::Models::Dimension.new(x)))
673
+ @length = (x = opts.delete(:length); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::Dimension) ? x : ::Io::Flow::Catalog::V0::Models::Dimension.new(x)))
674
+ @weight = (x = opts.delete(:weight); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::Dimension) ? x : ::Io::Flow::Catalog::V0::Models::Dimension.new(x)))
675
+ @width = (x = opts.delete(:width); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::Dimension) ? x : ::Io::Flow::Catalog::V0::Models::Dimension.new(x)))
676
+ end
677
+
678
+ def to_json
679
+ JSON.dump(to_hash)
680
+ end
681
+
682
+ def copy(incoming={})
683
+ DimensionSpecification.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
684
+ end
685
+
686
+ def to_hash
687
+ {
688
+ :depth => depth.nil? ? nil : depth.to_hash,
689
+ :length => length.nil? ? nil : length.to_hash,
690
+ :weight => weight.nil? ? nil : weight.to_hash,
691
+ :width => width.nil? ? nil : width.to_hash
692
+ }
693
+ end
694
+
695
+ end
696
+
697
+ class Dimensions
698
+
699
+ attr_reader :physical, :shipping
700
+
701
+ def initialize(incoming={})
702
+ opts = HttpClient::Helper.symbolize_keys(incoming)
703
+ @physical = (x = opts.delete(:physical); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::DimensionSpecification) ? x : ::Io::Flow::Catalog::V0::Models::DimensionSpecification.new(x)))
704
+ @shipping = (x = opts.delete(:shipping); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Catalog::V0::Models::DimensionSpecification) ? x : ::Io::Flow::Catalog::V0::Models::DimensionSpecification.new(x)))
705
+ end
706
+
707
+ def to_json
708
+ JSON.dump(to_hash)
709
+ end
710
+
711
+ def copy(incoming={})
712
+ Dimensions.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
713
+ end
714
+
715
+ def to_hash
716
+ {
717
+ :physical => physical.nil? ? nil : physical.to_hash,
718
+ :shipping => shipping.nil? ? nil : shipping.to_hash
719
+ }
720
+ end
721
+
722
+ end
723
+
724
+ class Harmonized
725
+
726
+ attr_reader :hs6, :hs10
727
+
728
+ def initialize(incoming={})
729
+ opts = HttpClient::Helper.symbolize_keys(incoming)
730
+ @hs6 = (x = opts.delete(:hs6); x.nil? ? nil : HttpClient::Preconditions.assert_class('hs6', x, String))
731
+ @hs10 = (x = opts.delete(:hs10); x.nil? ? nil : HttpClient::Preconditions.assert_class('hs10', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::Catalog::V0::Models::HarmonizedGeo) ? x : ::Io::Flow::Catalog::V0::Models::HarmonizedGeo.new(x)) })
732
+ end
733
+
734
+ def to_json
735
+ JSON.dump(to_hash)
736
+ end
737
+
738
+ def copy(incoming={})
739
+ Harmonized.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
740
+ end
741
+
742
+ def to_hash
743
+ {
744
+ :hs6 => hs6,
745
+ :hs10 => hs10.nil? ? nil : hs10.map { |o| o.to_hash }
746
+ }
747
+ end
748
+
749
+ end
750
+
751
+ class HarmonizedGeo
752
+
753
+ attr_reader :code, :from, :to
754
+
755
+ def initialize(incoming={})
756
+ opts = HttpClient::Helper.symbolize_keys(incoming)
757
+ @code = (x = opts.delete(:code); x.nil? ? nil : HttpClient::Preconditions.assert_class('code', x, String))
758
+ @from = (x = opts.delete(:from); x.nil? ? nil : HttpClient::Preconditions.assert_class('from', x, String))
759
+ @to = (x = opts.delete(:to); x.nil? ? nil : HttpClient::Preconditions.assert_class('to', x, String))
760
+ end
761
+
762
+ def to_json
763
+ JSON.dump(to_hash)
764
+ end
765
+
766
+ def copy(incoming={})
767
+ HarmonizedGeo.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
768
+ end
769
+
770
+ def to_hash
771
+ {
772
+ :code => code,
773
+ :from => from,
774
+ :to => to
775
+ }
776
+ end
777
+
778
+ end
779
+
780
+ class Image
781
+
782
+ attr_reader :tags, :url
783
+
784
+ def initialize(incoming={})
785
+ opts = HttpClient::Helper.symbolize_keys(incoming)
786
+ HttpClient::Preconditions.require_keys(opts, [:url], 'Image')
787
+ @tags = HttpClient::Preconditions.assert_class('tags', (x = opts.delete(:tags); x.nil? ? [] : x), Array).map { |v| HttpClient::Preconditions.assert_class('tags', v, String) }
788
+ @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String)
789
+ end
790
+
791
+ def to_json
792
+ JSON.dump(to_hash)
793
+ end
794
+
795
+ def copy(incoming={})
796
+ Image.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
797
+ end
798
+
799
+ def to_hash
800
+ {
801
+ :tags => tags,
802
+ :url => url
803
+ }
804
+ end
805
+
806
+ end
807
+
808
+ class Item
809
+
810
+ attr_reader :id, :number, :attributes, :codes, :content, :metadata
811
+
812
+ def initialize(incoming={})
813
+ opts = HttpClient::Helper.symbolize_keys(incoming)
814
+ HttpClient::Preconditions.require_keys(opts, [:id, :number, :codes, :content, :metadata], 'Item')
815
+ @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
816
+ @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), String)
817
+ @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::Attribute) ? x : ::Io::Flow::Catalog::V0::Models::Attribute.new(x)) }
818
+ @codes = (x = opts.delete(:codes); x.is_a?(::Io::Flow::Catalog::V0::Models::Codes) ? x : ::Io::Flow::Catalog::V0::Models::Codes.new(x))
819
+ @content = HttpClient::Preconditions.assert_class('content', opts.delete(:content), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Catalog::V0::Models::Content) ? x : ::Io::Flow::Catalog::V0::Models::Content.new(x)) }
820
+ @metadata = HttpClient::Preconditions.assert_class('metadata', opts.delete(:metadata), Hash).inject({}) { |h, d| h[d[0]] = HttpClient::Preconditions.assert_class('metadata', d[1], String); h }
821
+ end
822
+
823
+ def to_json
824
+ JSON.dump(to_hash)
825
+ end
826
+
827
+ def copy(incoming={})
828
+ Item.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
829
+ end
830
+
831
+ def to_hash
832
+ {
833
+ :id => id,
834
+ :number => number,
835
+ :attributes => attributes.map { |o| o.to_hash },
836
+ :codes => codes.to_hash,
837
+ :content => content.map { |o| o.to_hash },
838
+ :metadata => metadata
839
+ }
840
+ end
841
+
842
+ end
843
+
844
+ class ItemCreated < Event
845
+
846
+ attr_reader :id
847
+
848
+ def initialize(incoming={})
849
+ super(:name => Event::Types::ITEM_CREATED)
850
+ opts = HttpClient::Helper.symbolize_keys(incoming)
851
+ HttpClient::Preconditions.require_keys(opts, [:id], 'ItemCreated')
852
+ @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
853
+ end
854
+
855
+ def to_json
856
+ JSON.dump(to_hash)
857
+ end
858
+
859
+ def copy(incoming={})
860
+ ItemCreated.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
861
+ end
862
+
863
+ def subtype_to_hash
864
+ {
865
+ :id => id
866
+ }
867
+ end
868
+
869
+ end
870
+
871
+ class ItemDeleted < Event
872
+
873
+ attr_reader :id
874
+
875
+ def initialize(incoming={})
876
+ super(:name => Event::Types::ITEM_DELETED)
877
+ opts = HttpClient::Helper.symbolize_keys(incoming)
878
+ HttpClient::Preconditions.require_keys(opts, [:id], 'ItemDeleted')
879
+ @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
880
+ end
881
+
882
+ def to_json
883
+ JSON.dump(to_hash)
884
+ end
885
+
886
+ def copy(incoming={})
887
+ ItemDeleted.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
888
+ end
889
+
890
+ def subtype_to_hash
891
+ {
892
+ :id => id
893
+ }
894
+ end
895
+
896
+ end
897
+
898
+ class ItemForm
899
+
900
+ attr_reader :attributes, :codes, :content, :metadata, :number
901
+
902
+ def initialize(incoming={})
903
+ opts = HttpClient::Helper.symbolize_keys(incoming)
904
+ HttpClient::Preconditions.require_keys(opts, [:codes, :content, :metadata, :number], 'ItemForm')
905
+ @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::Attribute) ? x : ::Io::Flow::Catalog::V0::Models::Attribute.new(x)) }
906
+ @codes = (x = opts.delete(:codes); x.is_a?(::Io::Flow::Catalog::V0::Models::Codes) ? x : ::Io::Flow::Catalog::V0::Models::Codes.new(x))
907
+ @content = HttpClient::Preconditions.assert_class('content', opts.delete(:content), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Catalog::V0::Models::Content) ? x : ::Io::Flow::Catalog::V0::Models::Content.new(x)) }
908
+ @metadata = HttpClient::Preconditions.assert_class('metadata', opts.delete(:metadata), Hash).inject({}) { |h, d| h[d[0]] = HttpClient::Preconditions.assert_class('metadata', d[1], String); h }
909
+ @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), String)
910
+ end
911
+
912
+ def to_json
913
+ JSON.dump(to_hash)
914
+ end
915
+
916
+ def copy(incoming={})
917
+ ItemForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
918
+ end
919
+
920
+ def to_hash
921
+ {
922
+ :attributes => attributes.map { |o| o.to_hash },
923
+ :codes => codes.to_hash,
924
+ :content => content.map { |o| o.to_hash },
925
+ :metadata => metadata,
926
+ :number => number
927
+ }
928
+ end
929
+
930
+ end
931
+
932
+ class ItemUpdated < Event
933
+
934
+ attr_reader :id
935
+
936
+ def initialize(incoming={})
937
+ super(:name => Event::Types::ITEM_UPDATED)
938
+ opts = HttpClient::Helper.symbolize_keys(incoming)
939
+ HttpClient::Preconditions.require_keys(opts, [:id], 'ItemUpdated')
940
+ @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
941
+ end
942
+
943
+ def to_json
944
+ JSON.dump(to_hash)
945
+ end
946
+
947
+ def copy(incoming={})
948
+ ItemUpdated.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
949
+ end
950
+
951
+ def subtype_to_hash
952
+ {
953
+ :id => id
954
+ }
955
+ end
956
+
957
+ end
958
+
959
+ class ItemVersion
960
+
961
+ attr_reader :id, :timestamp, :type, :item
962
+
963
+ def initialize(incoming={})
964
+ opts = HttpClient::Helper.symbolize_keys(incoming)
965
+ HttpClient::Preconditions.require_keys(opts, [:id, :timestamp, :type, :item], 'ItemVersion')
966
+ @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
967
+ @timestamp = HttpClient::Preconditions.assert_class('timestamp', HttpClient::Helper.to_date_time_iso8601(opts.delete(:timestamp)), DateTime)
968
+ @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Common::V0::Models::ChangeType) ? x : ::Io::Flow::Common::V0::Models::ChangeType.apply(x))
969
+ @item = (x = opts.delete(:item); x.is_a?(::Io::Flow::Catalog::V0::Models::Item) ? x : ::Io::Flow::Catalog::V0::Models::Item.new(x))
970
+ end
971
+
972
+ def to_json
973
+ JSON.dump(to_hash)
974
+ end
975
+
976
+ def copy(incoming={})
977
+ ItemVersion.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
978
+ end
979
+
980
+ def to_hash
981
+ {
982
+ :id => id,
983
+ :timestamp => timestamp,
984
+ :type => type.value,
985
+ :item => item.to_hash
986
+ }
987
+ end
988
+
989
+ end
990
+
991
+ class Locale
992
+
993
+ attr_reader :country, :language
994
+
995
+ def initialize(incoming={})
996
+ opts = HttpClient::Helper.symbolize_keys(incoming)
997
+ @country = (x = opts.delete(:country); x.nil? ? nil : HttpClient::Preconditions.assert_class('country', x, String))
998
+ @language = (x = opts.delete(:language); x.nil? ? nil : HttpClient::Preconditions.assert_class('language', x, String))
999
+ end
1000
+
1001
+ def to_json
1002
+ JSON.dump(to_hash)
1003
+ end
1004
+
1005
+ def copy(incoming={})
1006
+ Locale.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1007
+ end
1008
+
1009
+ def to_hash
1010
+ {
1011
+ :country => country,
1012
+ :language => language
1013
+ }
1014
+ end
1015
+
1016
+ end
1017
+
1018
+ class Policy
1019
+
1020
+ attr_reader :id
1021
+
1022
+ def initialize(incoming={})
1023
+ opts = HttpClient::Helper.symbolize_keys(incoming)
1024
+ HttpClient::Preconditions.require_keys(opts, [:id], 'Policy')
1025
+ @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1026
+ end
1027
+
1028
+ def to_json
1029
+ JSON.dump(to_hash)
1030
+ end
1031
+
1032
+ def copy(incoming={})
1033
+ Policy.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1034
+ end
1035
+
1036
+ def to_hash
1037
+ {
1038
+ :id => id
1039
+ }
1040
+ end
1041
+
1042
+ end
1043
+
1044
+ class Price
1045
+
1046
+ attr_reader :current, :msrp
1047
+
1048
+ def initialize(incoming={})
1049
+ opts = HttpClient::Helper.symbolize_keys(incoming)
1050
+ @current = (x = opts.delete(:current); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Common::V0::Models::Price) ? x : ::Io::Flow::Common::V0::Models::Price.new(x)))
1051
+ @msrp = (x = opts.delete(:msrp); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Common::V0::Models::Price) ? x : ::Io::Flow::Common::V0::Models::Price.new(x)))
1052
+ end
1053
+
1054
+ def to_json
1055
+ JSON.dump(to_hash)
1056
+ end
1057
+
1058
+ def copy(incoming={})
1059
+ Price.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1060
+ end
1061
+
1062
+ def to_hash
1063
+ {
1064
+ :current => current.nil? ? nil : current.to_hash,
1065
+ :msrp => msrp.nil? ? nil : msrp.to_hash
1066
+ }
1067
+ end
1068
+
1069
+ end
1070
+
1071
+ class View
1072
+
1073
+ attr_reader :id, :catalog, :key, :countries, :currency, :query, :settings
1074
+
1075
+ def initialize(incoming={})
1076
+ opts = HttpClient::Helper.symbolize_keys(incoming)
1077
+ HttpClient::Preconditions.require_keys(opts, [:id, :catalog, :key, :countries, :currency, :query, :settings], 'View')
1078
+ @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1079
+ @catalog = (x = opts.delete(:catalog); x.is_a?(::Io::Flow::Catalog::V0::Models::Catalog) ? x : ::Io::Flow::Catalog::V0::Models::Catalog.new(x))
1080
+ @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
1081
+ @countries = HttpClient::Preconditions.assert_class('countries', opts.delete(:countries), Array).map { |v| HttpClient::Preconditions.assert_class('countries', v, String) }
1082
+ @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
1083
+ @query = HttpClient::Preconditions.assert_class('query', opts.delete(:query), String)
1084
+ @settings = (x = opts.delete(:settings); x.is_a?(::Io::Flow::Catalog::V0::Models::ViewSettings) ? x : ::Io::Flow::Catalog::V0::Models::ViewSettings.new(x))
1085
+ end
1086
+
1087
+ def to_json
1088
+ JSON.dump(to_hash)
1089
+ end
1090
+
1091
+ def copy(incoming={})
1092
+ View.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1093
+ end
1094
+
1095
+ def to_hash
1096
+ {
1097
+ :id => id,
1098
+ :catalog => catalog.to_hash,
1099
+ :key => key,
1100
+ :countries => countries,
1101
+ :currency => currency,
1102
+ :query => query,
1103
+ :settings => settings.to_hash
1104
+ }
1105
+ end
1106
+
1107
+ end
1108
+
1109
+ class ViewForm
1110
+
1111
+ attr_reader :key, :countries, :currency, :query, :settings
1112
+
1113
+ def initialize(incoming={})
1114
+ opts = HttpClient::Helper.symbolize_keys(incoming)
1115
+ HttpClient::Preconditions.require_keys(opts, [:key, :countries, :currency, :query, :settings], 'ViewForm')
1116
+ @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
1117
+ @countries = HttpClient::Preconditions.assert_class('countries', opts.delete(:countries), Array).map { |v| HttpClient::Preconditions.assert_class('countries', v, String) }
1118
+ @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
1119
+ @query = HttpClient::Preconditions.assert_class('query', opts.delete(:query), String)
1120
+ @settings = (x = opts.delete(:settings); x.is_a?(::Io::Flow::Catalog::V0::Models::ViewSettingsForm) ? x : ::Io::Flow::Catalog::V0::Models::ViewSettingsForm.new(x))
1121
+ end
1122
+
1123
+ def to_json
1124
+ JSON.dump(to_hash)
1125
+ end
1126
+
1127
+ def copy(incoming={})
1128
+ ViewForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1129
+ end
1130
+
1131
+ def to_hash
1132
+ {
1133
+ :key => key,
1134
+ :countries => countries,
1135
+ :currency => currency,
1136
+ :query => query,
1137
+ :settings => settings.to_hash
1138
+ }
1139
+ end
1140
+
1141
+ end
1142
+
1143
+ class ViewItem
1144
+
1145
+ attr_reader :id, :data
1146
+
1147
+ def initialize(incoming={})
1148
+ opts = HttpClient::Helper.symbolize_keys(incoming)
1149
+ HttpClient::Preconditions.require_keys(opts, [:id, :data], 'ViewItem')
1150
+ @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1151
+ @data = (x = opts.delete(:data); x.is_a?(::Io::Flow::Catalog::V0::Models::Item) ? x : ::Io::Flow::Catalog::V0::Models::Item.new(x))
1152
+ end
1153
+
1154
+ def to_json
1155
+ JSON.dump(to_hash)
1156
+ end
1157
+
1158
+ def copy(incoming={})
1159
+ ViewItem.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1160
+ end
1161
+
1162
+ def to_hash
1163
+ {
1164
+ :id => id,
1165
+ :data => data.to_hash
1166
+ }
1167
+ end
1168
+
1169
+ end
1170
+
1171
+ class ViewSettings
1172
+
1173
+ attr_reader :update_policy
1174
+
1175
+ def initialize(incoming={})
1176
+ opts = HttpClient::Helper.symbolize_keys(incoming)
1177
+ @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))
1178
+ end
1179
+
1180
+ def to_json
1181
+ JSON.dump(to_hash)
1182
+ end
1183
+
1184
+ def copy(incoming={})
1185
+ ViewSettings.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1186
+ end
1187
+
1188
+ def to_hash
1189
+ {
1190
+ :update_policy => update_policy.value
1191
+ }
1192
+ end
1193
+
1194
+ end
1195
+
1196
+ class ViewSettingsForm
1197
+
1198
+ attr_reader :update_policy
1199
+
1200
+ def initialize(incoming={})
1201
+ opts = HttpClient::Helper.symbolize_keys(incoming)
1202
+ @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)))
1203
+ end
1204
+
1205
+ def to_json
1206
+ JSON.dump(to_hash)
1207
+ end
1208
+
1209
+ def copy(incoming={})
1210
+ ViewSettingsForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1211
+ end
1212
+
1213
+ def to_hash
1214
+ {
1215
+ :update_policy => update_policy.nil? ? nil : update_policy.value
1216
+ }
1217
+ end
1218
+
1219
+ end
1220
+
1221
+ class ViewVersion
1222
+
1223
+ attr_reader :id, :timestamp, :type, :view
1224
+
1225
+ def initialize(incoming={})
1226
+ opts = HttpClient::Helper.symbolize_keys(incoming)
1227
+ HttpClient::Preconditions.require_keys(opts, [:id, :timestamp, :type, :view], 'ViewVersion')
1228
+ @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1229
+ @timestamp = HttpClient::Preconditions.assert_class('timestamp', HttpClient::Helper.to_date_time_iso8601(opts.delete(:timestamp)), DateTime)
1230
+ @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Common::V0::Models::ChangeType) ? x : ::Io::Flow::Common::V0::Models::ChangeType.apply(x))
1231
+ @view = (x = opts.delete(:view); x.is_a?(::Io::Flow::Catalog::V0::Models::View) ? x : ::Io::Flow::Catalog::V0::Models::View.new(x))
1232
+ end
1233
+
1234
+ def to_json
1235
+ JSON.dump(to_hash)
1236
+ end
1237
+
1238
+ def copy(incoming={})
1239
+ ViewVersion.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1240
+ end
1241
+
1242
+ def to_hash
1243
+ {
1244
+ :id => id,
1245
+ :timestamp => timestamp,
1246
+ :type => type.value,
1247
+ :view => view.to_hash
1248
+ }
1249
+ end
1250
+
1251
+ end
1252
+
1253
+ end
1254
+
1255
+ # ===== END OF SERVICE DEFINITION =====
1256
+ module HttpClient
1257
+
1258
+ class Request
1259
+
1260
+ def initialize(uri)
1261
+ @uri = Preconditions.assert_class('uri', uri, URI)
1262
+ @params = nil
1263
+ @body = nil
1264
+ @auth = nil
1265
+ @headers = {}
1266
+ @header_keys_lower_case = []
1267
+ end
1268
+
1269
+ def with_header(name, value)
1270
+ Preconditions.check_not_blank('name', name, "Header name is required")
1271
+ Preconditions.check_not_blank('value', value, "Header value is required")
1272
+ Preconditions.check_state(!@headers.has_key?(name),
1273
+ "Duplicate header named[%s]" % name)
1274
+ @headers[name] = value
1275
+ @header_keys_lower_case << name.downcase
1276
+ self
1277
+ end
1278
+
1279
+ def with_auth(auth)
1280
+ Preconditions.assert_class('auth', auth, HttpClient::Authorization)
1281
+ Preconditions.check_state(@auth.nil?, "auth previously set")
1282
+
1283
+ if auth.scheme.name == AuthScheme::BASIC.name
1284
+ @auth = auth
1285
+ else
1286
+ raise "Auth Scheme[#{auth.scheme.name}] not supported"
1287
+ end
1288
+ self
1289
+ end
1290
+
1291
+ def with_query(params)
1292
+ Preconditions.assert_class('params', params, Hash)
1293
+ Preconditions.check_state(@params.nil?, "Already have query parameters")
1294
+ @params = params
1295
+ self
1296
+ end
1297
+
1298
+ # Wrapper to set Content-Type header to application/json and set
1299
+ # the provided json document as the body
1300
+ def with_json(json)
1301
+ @headers['Content-Type'] ||= 'application/json; charset=UTF-8'
1302
+ with_body(json)
1303
+ end
1304
+
1305
+ def with_body(body)
1306
+ Preconditions.check_not_blank('body', body)
1307
+ @body = body
1308
+ self
1309
+ end
1310
+
1311
+ # Creates a new Net:HTTP client. The client returned should be
1312
+ # fully configured to make a request.
1313
+ def new_http_client
1314
+ client = Net::HTTP.new(@uri.host, @uri.port)
1315
+ if @uri.scheme == "https"
1316
+ configure_ssl(client)
1317
+ end
1318
+ client
1319
+ end
1320
+
1321
+ # If HTTP is required, this method accepts an HTTP Client and configures SSL
1322
+ def configure_ssl(client)
1323
+ Preconditions.assert_class('client', client, Net::HTTP)
1324
+ client.use_ssl = true
1325
+ client.verify_mode = OpenSSL::SSL::VERIFY_PEER
1326
+ client.cert_store = OpenSSL::X509::Store.new
1327
+ client.cert_store.set_default_paths
1328
+ end
1329
+
1330
+ def get(&block)
1331
+ do_request(Net::HTTP::Get, &block)
1332
+ end
1333
+
1334
+ def delete(&block)
1335
+ do_request(Net::HTTP::Delete, &block)
1336
+ end
1337
+
1338
+ def options(&block)
1339
+ do_request(Net::HTTP::Options, &block)
1340
+ end
1341
+
1342
+ def post(&block)
1343
+ do_request(Net::HTTP::Post, &block)
1344
+ end
1345
+
1346
+ def put(&block)
1347
+ do_request(Net::HTTP::Put, &block)
1348
+ end
1349
+
1350
+ class PATCH < Net::HTTP::Put
1351
+ METHOD = "PATCH"
1352
+ end
1353
+
1354
+ def patch(&block)
1355
+ do_request(PATCH, &block)
1356
+ end
1357
+
1358
+ def do_request(klass)
1359
+ Preconditions.assert_class('klass', klass, Class)
1360
+
1361
+ uri = @uri.to_s
1362
+ if q = to_query(@params)
1363
+ uri += "?%s" % q
1364
+ end
1365
+
1366
+ request = klass.send(:new, uri)
1367
+
1368
+ curl = ['curl']
1369
+ if klass != Net::HTTP::Get
1370
+ curl << "-X%s" % klass.name.split("::").last.upcase
1371
+ end
1372
+
1373
+ if @body
1374
+ # DEBUG path = "/tmp/rest_client.tmp"
1375
+ # DEBUG File.open(path, "w") { |os| os << @body.to_s }
1376
+ # DEBUG curl << "-d@%s" % path
1377
+ request.body = @body
1378
+ end
1379
+
1380
+ if @auth
1381
+ curl << "-u \"%s:%s\"" % [@auth.username, @auth.password]
1382
+ Preconditions.check_state(!@header_keys_lower_case.include?("authorization"),
1383
+ "Cannot specify both an Authorization header and an auth instance")
1384
+ user_pass = "%s:%s" % [@auth.username, @auth.password]
1385
+ encoded = Base64.encode64(user_pass).to_s.split("\n").map(&:strip).join
1386
+ request.add_field("Authorization", "Basic %s" % encoded)
1387
+ end
1388
+
1389
+ @headers.each { |key, value|
1390
+ curl << "-H \"%s: %s\"" % [key, value]
1391
+ request.add_field(key, value)
1392
+ }
1393
+
1394
+ curl << "'%s'" % uri
1395
+ # DEBUG puts curl.join(" ")
1396
+
1397
+ raw_response = http_request(request)
1398
+ response = raw_response.to_s == "" ? nil : JSON.parse(raw_response)
1399
+
1400
+ if block_given?
1401
+ yield response
1402
+ else
1403
+ response
1404
+ end
1405
+ end
1406
+
1407
+ private
1408
+ def to_query(params={})
1409
+ parts = (params || {}).map { |k,v|
1410
+ if v.respond_to?(:each)
1411
+ v.map { |el| "%s=%s" % [k, CGI.escape(el.to_s)] }
1412
+ else
1413
+ "%s=%s" % [k, CGI.escape(v.to_s)]
1414
+ end
1415
+ }
1416
+ parts.empty? ? nil : parts.join("&")
1417
+ end
1418
+
1419
+ def http_request(request)
1420
+ response = begin
1421
+ new_http_client.request(request)
1422
+ rescue SocketError => e
1423
+ raise Exception.new("Error accessing uri[#{@uri}]: #{e}")
1424
+ end
1425
+
1426
+ case response
1427
+ when Net::HTTPSuccess
1428
+ response.body
1429
+ else
1430
+ body = response.body rescue nil
1431
+ raise HttpClient::ServerError.new(response.code.to_i, response.message, :body => body, :uri => @uri.to_s)
1432
+ end
1433
+ end
1434
+ end
1435
+
1436
+ class ServerError < StandardError
1437
+
1438
+ attr_reader :code, :details, :body, :uri
1439
+
1440
+ def initialize(code, details, incoming={})
1441
+ opts = HttpClient::Helper.symbolize_keys(incoming)
1442
+ @code = HttpClient::Preconditions.assert_class('code', code, Integer)
1443
+ @details = HttpClient::Preconditions.assert_class('details', details, String)
1444
+ @body = HttpClient::Preconditions.assert_class_or_nil('body', opts.delete(:body), String)
1445
+ @uri = HttpClient::Preconditions.assert_class_or_nil('uri', opts.delete(:uri), String)
1446
+ HttpClient::Preconditions.assert_empty_opts(opts)
1447
+ super(self.message)
1448
+ end
1449
+
1450
+ def message
1451
+ m = "%s %s" % [@code, @details]
1452
+ if @body
1453
+ m << ": %s" % @body
1454
+ end
1455
+ m
1456
+ end
1457
+
1458
+ def body_json
1459
+ JSON.parse(@body)
1460
+ end
1461
+
1462
+ end
1463
+
1464
+ class PreconditionException < Exception
1465
+
1466
+ attr_reader :message
1467
+
1468
+ def initialize(message)
1469
+ super(message)
1470
+ @message = message
1471
+ end
1472
+
1473
+ end
1474
+
1475
+ module Preconditions
1476
+
1477
+ def Preconditions.check_argument(expression, error_message=nil)
1478
+ if !expression
1479
+ raise PreconditionException.new(error_message || "check_argument failed")
1480
+ end
1481
+ nil
1482
+ end
1483
+
1484
+ def Preconditions.check_state(expression, error_message=nil)
1485
+ if !expression
1486
+ raise PreconditionException.new(error_message || "check_state failed")
1487
+ end
1488
+ nil
1489
+ end
1490
+
1491
+ def Preconditions.check_not_nil(field_name, reference, error_message=nil)
1492
+ if reference.nil?
1493
+ raise PreconditionException.new(error_message || "argument for %s cannot be nil" % field_name)
1494
+ end
1495
+ reference
1496
+ end
1497
+
1498
+ def Preconditions.check_not_blank(field_name, reference, error_message=nil)
1499
+ if reference.to_s.strip == ""
1500
+ raise PreconditionException.new(error_message || "argument for %s cannot be blank" % field_name)
1501
+ end
1502
+ reference
1503
+ end
1504
+
1505
+ # Throws an error if opts is not empty. Useful when parsing
1506
+ # arguments to a function
1507
+ def Preconditions.assert_empty_opts(opts)
1508
+ if !opts.empty?
1509
+ raise PreconditionException.new("Invalid opts: #{opts.keys.inspect}\n#{opts.inspect}")
1510
+ end
1511
+ end
1512
+
1513
+ # Requires that the provided hash has the specified keys.
1514
+ # @param fields A list of symbols
1515
+ def Preconditions.require_keys(hash, fields, error_prefix=nil)
1516
+ missing = fields.select { |f| !hash.has_key?(f) }
1517
+ if !missing.empty?
1518
+ msg = "Missing required fields: " + missing.join(", ")
1519
+ raise PreconditionException.new(error_prefix.empty? ? msg : "#{error_prefix}: #{msg}")
1520
+ end
1521
+ end
1522
+
1523
+ # Asserts that value is not nill and is_?(klass). Returns
1524
+ # value. Common use is
1525
+ #
1526
+ # amount = Preconditions.assert_class('amount', amount, BigDecimal)
1527
+ def Preconditions.assert_class(field_name, value, klass)
1528
+ Preconditions.check_not_nil('field_name', field_name)
1529
+ Preconditions.check_not_nil('klass', klass)
1530
+ Preconditions.check_not_nil('value', value, "Value for %s cannot be nil. Expected an instance of class %s" % [field_name, klass.name])
1531
+ Preconditions.check_state(value.is_a?(klass),
1532
+ "Value for #{field_name} is of type[#{value.class}] - class[#{klass}] is required. value[#{value.inspect.to_s}]")
1533
+ value
1534
+ end
1535
+
1536
+ def Preconditions.assert_class_or_nil(field_name, value, klass)
1537
+ if !value.nil?
1538
+ Preconditions.assert_class(field_name, value, klass)
1539
+ end
1540
+ end
1541
+
1542
+ def Preconditions.assert_boolean(field_name, value)
1543
+ Preconditions.check_not_nil('field_name', field_name)
1544
+ Preconditions.check_not_nil('value', value, "Value for %s cannot be nil. Expected an instance of TrueClass or FalseClass" % field_name)
1545
+ Preconditions.check_state(value.is_a?(TrueClass) || value.is_a?(FalseClass),
1546
+ "Value for #{field_name} is of type[#{value.class}] - class[TrueClass or FalseClass] is required. value[#{value.inspect.to_s}]")
1547
+ value
1548
+ end
1549
+
1550
+ def Preconditions.assert_boolean_or_nil(field_name, value)
1551
+ if !value.nil?
1552
+ Preconditions.assert_boolean(field_name, value)
1553
+ end
1554
+ end
1555
+
1556
+ def Preconditions.assert_collection_of_class(field_name, values, klass)
1557
+ Preconditions.assert_class(field_name, values, Array)
1558
+ values.each { |v| Preconditions.assert_class(field_name, v, klass) }
1559
+ end
1560
+
1561
+ def Preconditions.assert_hash_of_class(field_name, hash, klass)
1562
+ Preconditions.assert_class(field_name, hash, Hash)
1563
+ values.each { |k, v| Preconditions.assert_class(field_name, v, klass) }
1564
+ end
1565
+
1566
+ end
1567
+
1568
+ class AuthScheme
1569
+
1570
+ attr_reader :name
1571
+
1572
+ def initialize(name)
1573
+ @name = HttpClient::Preconditions.check_not_blank('name', name)
1574
+ end
1575
+
1576
+ BASIC = AuthScheme.new("basic") unless defined?(BASIC)
1577
+
1578
+ end
1579
+
1580
+ class Authorization
1581
+
1582
+ attr_reader :scheme, :username, :password
1583
+
1584
+ def initialize(scheme, username, opts={})
1585
+ @scheme = HttpClient::Preconditions.assert_class('schema', scheme, AuthScheme)
1586
+ @username = HttpClient::Preconditions.check_not_blank('username', username, "username is required")
1587
+ @password = HttpClient::Preconditions.assert_class_or_nil('password', opts.delete(:password), String)
1588
+ HttpClient::Preconditions.assert_empty_opts(opts)
1589
+ end
1590
+
1591
+ def Authorization.basic(username, password=nil)
1592
+ Authorization.new(AuthScheme::BASIC, username, :password => password)
1593
+ end
1594
+
1595
+ end
1596
+
1597
+ module Helper
1598
+
1599
+ def Helper.symbolize_keys(hash)
1600
+ Preconditions.assert_class('hash', hash, Hash)
1601
+ new_hash = {}
1602
+ hash.each { |k, v|
1603
+ new_hash[k.to_sym] = v
1604
+ }
1605
+ new_hash
1606
+ end
1607
+
1608
+ def Helper.to_big_decimal(value)
1609
+ value ? BigDecimal.new(value.to_s) : nil
1610
+ end
1611
+
1612
+ def Helper.to_object(value)
1613
+ value ? JSON.parse(value) : nil
1614
+ end
1615
+
1616
+ def Helper.to_uuid(value)
1617
+ 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$/),
1618
+ "Invalid guid[%s]" % value)
1619
+ value
1620
+ end
1621
+
1622
+ def Helper.to_date_iso8601(value)
1623
+ if value.is_a?(Date)
1624
+ value
1625
+ elsif value
1626
+ Date.parse(value.to_s)
1627
+ else
1628
+ nil
1629
+ end
1630
+ end
1631
+
1632
+ def Helper.to_date_time_iso8601(value)
1633
+ if value.is_a?(DateTime)
1634
+ value
1635
+ elsif value
1636
+ DateTime.parse(value.to_s)
1637
+ else
1638
+ nil
1639
+ end
1640
+ end
1641
+
1642
+ def Helper.date_iso8601_to_string(value)
1643
+ value.nil? ? nil : value.strftime('%Y-%m-%d')
1644
+ end
1645
+
1646
+ def Helper.date_time_iso8601_to_string(value)
1647
+ value.nil? ? nil : value.strftime('%Y-%m-%dT%H:%M:%S%z')
1648
+ end
1649
+
1650
+ TRUE_STRINGS = ['t', 'true', 'y', 'yes', 'on', '1', 'trueclass'] unless defined?(TRUE_STRINGS)
1651
+ FALSE_STRINGS = ['f', 'false', 'n', 'no', 'off', '0', 'falseclass'] unless defined?(FALSE_STRINGS)
1652
+
1653
+ def Helper.to_boolean(field_name, value)
1654
+ string = value.to_s.strip.downcase
1655
+ if TRUE_STRINGS.include?(string)
1656
+ true
1657
+ elsif FALSE_STRINGS.include?(string)
1658
+ false
1659
+ elsif string != ""
1660
+ 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}")
1661
+ else
1662
+ nil
1663
+ end
1664
+ end
1665
+
1666
+ end
1667
+
1668
+ end
1669
+ end
1670
+ end
1671
+ end
1672
+ end