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,1762 +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/common/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
- # The Flow Commerce REST API provides full access to the global ecommerce
17
- # platform.
18
- module Io
19
- module Flow
20
- module Common
21
- module V0
22
-
23
- class Client
24
-
25
- module Constants
26
-
27
- BASE_URL = 'https://api.flow.io' unless defined?(Constants::BASE_URL)
28
- NAMESPACE = 'io.flow.common.v0' unless defined?(Constants::NAMESPACE)
29
- USER_AGENT = 'apidoc:0.11.29 http://www.apidoc.me/flow/common/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 healthchecks
66
- @healthchecks ||= ::Io::Flow::Common::V0::Clients::Healthchecks.new(self)
67
- end
68
- end
69
-
70
- module Clients
71
-
72
- class Healthchecks
73
-
74
- def initialize(client)
75
- @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Common::V0::Client)
76
- end
77
-
78
- def get_healthcheck
79
- r = @client.request("/_internal_/healthcheck").get
80
- ::Io::Flow::Common::V0::Models::Healthcheck.new(r)
81
- end
82
-
83
- end
84
-
85
- end
86
-
87
- module Models
88
-
89
- class ExpandableLocation
90
-
91
- module Types
92
- LOCATION = 'location' unless defined?(LOCATION)
93
- LOCATION_REFERENCE = 'location_reference' unless defined?(LOCATION_REFERENCE)
94
- end
95
-
96
- def initialize(incoming={})
97
- opts = HttpClient::Helper.symbolize_keys(incoming)
98
- HttpClient::Preconditions.require_keys(opts, [:name], 'ExpandableLocation')
99
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
100
- end
101
-
102
- def to_hash
103
- subtype_to_hash.merge(:discriminator => @name)
104
- end
105
-
106
- def ExpandableLocation.from_json(hash)
107
- HttpClient::Preconditions.assert_class('hash', hash, Hash)
108
- case HttpClient::Helper.symbolize_keys(hash)[:discriminator]
109
- when Types::LOCATION; Location.new(hash)
110
- when Types::LOCATION_REFERENCE; LocationReference.new(hash)
111
- else ExpandableLocationUndefinedType.new(:name => union_type_name)
112
- end
113
- end
114
-
115
- end
116
-
117
- class ExpandableLocationUndefinedType < ExpandableLocation
118
-
119
- attr_reader :name
120
-
121
- def initialize(incoming={})
122
- super(:name => 'undefined_type')
123
- opts = HttpClient::Helper.symbolize_keys(incoming)
124
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
125
- end
126
-
127
- def subtype_to_hash
128
- raise 'Unable to serialize undefined type to json'
129
- end
130
-
131
- def copy(incoming={})
132
- raise 'Operation not supported for undefined type'
133
- end
134
-
135
- def to_hash
136
- raise 'Operation not supported for undefined type'
137
- end
138
-
139
- end
140
-
141
- class ExpandableOrganization
142
-
143
- module Types
144
- ORGANIZATION = 'organization' unless defined?(ORGANIZATION)
145
- ORGANIZATION_REFERENCE = 'organization_reference' unless defined?(ORGANIZATION_REFERENCE)
146
- end
147
-
148
- def initialize(incoming={})
149
- opts = HttpClient::Helper.symbolize_keys(incoming)
150
- HttpClient::Preconditions.require_keys(opts, [:name], 'ExpandableOrganization')
151
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
152
- end
153
-
154
- def to_hash
155
- subtype_to_hash.merge(:discriminator => @name)
156
- end
157
-
158
- def ExpandableOrganization.from_json(hash)
159
- HttpClient::Preconditions.assert_class('hash', hash, Hash)
160
- case HttpClient::Helper.symbolize_keys(hash)[:discriminator]
161
- when Types::ORGANIZATION; Organization.new(hash)
162
- when Types::ORGANIZATION_REFERENCE; OrganizationReference.new(hash)
163
- else ExpandableOrganizationUndefinedType.new(:name => union_type_name)
164
- end
165
- end
166
-
167
- end
168
-
169
- class ExpandableOrganizationUndefinedType < ExpandableOrganization
170
-
171
- attr_reader :name
172
-
173
- def initialize(incoming={})
174
- super(:name => 'undefined_type')
175
- opts = HttpClient::Helper.symbolize_keys(incoming)
176
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
177
- end
178
-
179
- def subtype_to_hash
180
- raise 'Unable to serialize undefined type to json'
181
- end
182
-
183
- def copy(incoming={})
184
- raise 'Operation not supported for undefined type'
185
- end
186
-
187
- def to_hash
188
- raise 'Operation not supported for undefined type'
189
- end
190
-
191
- end
192
-
193
- class ExpandableUser
194
-
195
- module Types
196
- USER = 'user' unless defined?(USER)
197
- USER_REFERENCE = 'user_reference' unless defined?(USER_REFERENCE)
198
- end
199
-
200
- def initialize(incoming={})
201
- opts = HttpClient::Helper.symbolize_keys(incoming)
202
- HttpClient::Preconditions.require_keys(opts, [:name], 'ExpandableUser')
203
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
204
- end
205
-
206
- def to_hash
207
- subtype_to_hash.merge(:discriminator => @name)
208
- end
209
-
210
- def ExpandableUser.from_json(hash)
211
- HttpClient::Preconditions.assert_class('hash', hash, Hash)
212
- case HttpClient::Helper.symbolize_keys(hash)[:discriminator]
213
- when Types::USER; User.new(hash)
214
- when Types::USER_REFERENCE; UserReference.new(hash)
215
- else ExpandableUserUndefinedType.new(:name => union_type_name)
216
- end
217
- end
218
-
219
- end
220
-
221
- class ExpandableUserUndefinedType < ExpandableUser
222
-
223
- attr_reader :name
224
-
225
- def initialize(incoming={})
226
- super(:name => 'undefined_type')
227
- opts = HttpClient::Helper.symbolize_keys(incoming)
228
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
229
- end
230
-
231
- def subtype_to_hash
232
- raise 'Unable to serialize undefined type to json'
233
- end
234
-
235
- def copy(incoming={})
236
- raise 'Operation not supported for undefined type'
237
- end
238
-
239
- def to_hash
240
- raise 'Operation not supported for undefined type'
241
- end
242
-
243
- end
244
-
245
- class Calendar
246
-
247
- attr_reader :value
248
-
249
- def initialize(value)
250
- @value = HttpClient::Preconditions.assert_class('value', value, String)
251
- end
252
-
253
- # Returns the instance of Calendar for this value, creating a new instance for an unknown value
254
- def Calendar.apply(value)
255
- if value.instance_of?(Calendar)
256
- value
257
- else
258
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
259
- value.nil? ? nil : (from_string(value) || Calendar.new(value))
260
- end
261
- end
262
-
263
- # Returns the instance of Calendar for this value, or nil if not found
264
- def Calendar.from_string(value)
265
- HttpClient::Preconditions.assert_class('value', value, String)
266
- Calendar.ALL.find { |v| v.value == value }
267
- end
268
-
269
- def Calendar.ALL
270
- @@all ||= [Calendar.weekdays, Calendar.everyday]
271
- end
272
-
273
- # Mon - Fri
274
- def Calendar.weekdays
275
- @@_weekdays ||= Calendar.new('weekdays')
276
- end
277
-
278
- # 7 days per week
279
- def Calendar.everyday
280
- @@_everyday ||= Calendar.new('everyday')
281
- end
282
-
283
- def to_hash
284
- value
285
- end
286
-
287
- end
288
-
289
- class Capability
290
-
291
- attr_reader :value
292
-
293
- def initialize(value)
294
- @value = HttpClient::Preconditions.assert_class('value', value, String)
295
- end
296
-
297
- # Returns the instance of Capability for this value, creating a new instance for an unknown value
298
- def Capability.apply(value)
299
- if value.instance_of?(Capability)
300
- value
301
- else
302
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
303
- value.nil? ? nil : (from_string(value) || Capability.new(value))
304
- end
305
- end
306
-
307
- # Returns the instance of Capability for this value, or nil if not found
308
- def Capability.from_string(value)
309
- HttpClient::Preconditions.assert_class('value', value, String)
310
- Capability.ALL.find { |v| v.value == value }
311
- end
312
-
313
- def Capability.ALL
314
- @@all ||= [Capability.crossdock]
315
- end
316
-
317
- def Capability.crossdock
318
- @@_crossdock ||= Capability.new('crossdock')
319
- end
320
-
321
- def to_hash
322
- value
323
- end
324
-
325
- end
326
-
327
- class ChangeType
328
-
329
- attr_reader :value
330
-
331
- def initialize(value)
332
- @value = HttpClient::Preconditions.assert_class('value', value, String)
333
- end
334
-
335
- # Returns the instance of ChangeType for this value, creating a new instance for an unknown value
336
- def ChangeType.apply(value)
337
- if value.instance_of?(ChangeType)
338
- value
339
- else
340
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
341
- value.nil? ? nil : (from_string(value) || ChangeType.new(value))
342
- end
343
- end
344
-
345
- # Returns the instance of ChangeType for this value, or nil if not found
346
- def ChangeType.from_string(value)
347
- HttpClient::Preconditions.assert_class('value', value, String)
348
- ChangeType.ALL.find { |v| v.value == value }
349
- end
350
-
351
- def ChangeType.ALL
352
- @@all ||= [ChangeType.insert, ChangeType.update, ChangeType.delete]
353
- end
354
-
355
- def ChangeType.insert
356
- @@_insert ||= ChangeType.new('insert')
357
- end
358
-
359
- def ChangeType.update
360
- @@_update ||= ChangeType.new('update')
361
- end
362
-
363
- def ChangeType.delete
364
- @@_delete ||= ChangeType.new('delete')
365
- end
366
-
367
- def to_hash
368
- value
369
- end
370
-
371
- end
372
-
373
- class DimensionType
374
-
375
- attr_reader :value
376
-
377
- def initialize(value)
378
- @value = HttpClient::Preconditions.assert_class('value', value, String)
379
- end
380
-
381
- # Returns the instance of DimensionType for this value, creating a new instance for an unknown value
382
- def DimensionType.apply(value)
383
- if value.instance_of?(DimensionType)
384
- value
385
- else
386
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
387
- value.nil? ? nil : (from_string(value) || DimensionType.new(value))
388
- end
389
- end
390
-
391
- # Returns the instance of DimensionType for this value, or nil if not found
392
- def DimensionType.from_string(value)
393
- HttpClient::Preconditions.assert_class('value', value, String)
394
- DimensionType.ALL.find { |v| v.value == value }
395
- end
396
-
397
- def DimensionType.ALL
398
- @@all ||= [DimensionType.product, DimensionType.package]
399
- end
400
-
401
- # The standalone dimensions of an item.
402
- def DimensionType.product
403
- @@_product ||= DimensionType.new('product')
404
- end
405
-
406
- # The boxed dimensions of an item.
407
- def DimensionType.package
408
- @@_package ||= DimensionType.new('package')
409
- end
410
-
411
- def to_hash
412
- value
413
- end
414
-
415
- end
416
-
417
- class ExceptionType
418
-
419
- attr_reader :value
420
-
421
- def initialize(value)
422
- @value = HttpClient::Preconditions.assert_class('value', value, String)
423
- end
424
-
425
- # Returns the instance of ExceptionType for this value, creating a new instance for an unknown value
426
- def ExceptionType.apply(value)
427
- if value.instance_of?(ExceptionType)
428
- value
429
- else
430
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
431
- value.nil? ? nil : (from_string(value) || ExceptionType.new(value))
432
- end
433
- end
434
-
435
- # Returns the instance of ExceptionType for this value, or nil if not found
436
- def ExceptionType.from_string(value)
437
- HttpClient::Preconditions.assert_class('value', value, String)
438
- ExceptionType.ALL.find { |v| v.value == value }
439
- end
440
-
441
- def ExceptionType.ALL
442
- @@all ||= [ExceptionType.open, ExceptionType.closed]
443
- end
444
-
445
- def ExceptionType.open
446
- @@_open ||= ExceptionType.new('open')
447
- end
448
-
449
- def ExceptionType.closed
450
- @@_closed ||= ExceptionType.new('closed')
451
- end
452
-
453
- def to_hash
454
- value
455
- end
456
-
457
- end
458
-
459
- class HolidayCalendar
460
-
461
- attr_reader :value
462
-
463
- def initialize(value)
464
- @value = HttpClient::Preconditions.assert_class('value', value, String)
465
- end
466
-
467
- # Returns the instance of HolidayCalendar for this value, creating a new instance for an unknown value
468
- def HolidayCalendar.apply(value)
469
- if value.instance_of?(HolidayCalendar)
470
- value
471
- else
472
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
473
- value.nil? ? nil : (from_string(value) || HolidayCalendar.new(value))
474
- end
475
- end
476
-
477
- # Returns the instance of HolidayCalendar for this value, or nil if not found
478
- def HolidayCalendar.from_string(value)
479
- HttpClient::Preconditions.assert_class('value', value, String)
480
- HolidayCalendar.ALL.find { |v| v.value == value }
481
- end
482
-
483
- def HolidayCalendar.ALL
484
- @@all ||= [HolidayCalendar.us_bank_holidays, HolidayCalendar.jewish_holidays]
485
- end
486
-
487
- def HolidayCalendar.us_bank_holidays
488
- @@_us_bank_holidays ||= HolidayCalendar.new('us_bank_holidays')
489
- end
490
-
491
- def HolidayCalendar.jewish_holidays
492
- @@_jewish_holidays ||= HolidayCalendar.new('jewish_holidays')
493
- end
494
-
495
- def to_hash
496
- value
497
- end
498
-
499
- end
500
-
501
- class ScheduleExceptionStatus
502
-
503
- attr_reader :value
504
-
505
- def initialize(value)
506
- @value = HttpClient::Preconditions.assert_class('value', value, String)
507
- end
508
-
509
- # Returns the instance of ScheduleExceptionStatus for this value, creating a new instance for an unknown value
510
- def ScheduleExceptionStatus.apply(value)
511
- if value.instance_of?(ScheduleExceptionStatus)
512
- value
513
- else
514
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
515
- value.nil? ? nil : (from_string(value) || ScheduleExceptionStatus.new(value))
516
- end
517
- end
518
-
519
- # Returns the instance of ScheduleExceptionStatus for this value, or nil if not found
520
- def ScheduleExceptionStatus.from_string(value)
521
- HttpClient::Preconditions.assert_class('value', value, String)
522
- ScheduleExceptionStatus.ALL.find { |v| v.value == value }
523
- end
524
-
525
- def ScheduleExceptionStatus.ALL
526
- @@all ||= [ScheduleExceptionStatus.open, ScheduleExceptionStatus.closed]
527
- end
528
-
529
- def ScheduleExceptionStatus.open
530
- @@_open ||= ScheduleExceptionStatus.new('Open')
531
- end
532
-
533
- def ScheduleExceptionStatus.closed
534
- @@_closed ||= ScheduleExceptionStatus.new('Closed')
535
- end
536
-
537
- def to_hash
538
- value
539
- end
540
-
541
- end
542
-
543
- class SortDirection
544
-
545
- attr_reader :value
546
-
547
- def initialize(value)
548
- @value = HttpClient::Preconditions.assert_class('value', value, String)
549
- end
550
-
551
- # Returns the instance of SortDirection for this value, creating a new instance for an unknown value
552
- def SortDirection.apply(value)
553
- if value.instance_of?(SortDirection)
554
- value
555
- else
556
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
557
- value.nil? ? nil : (from_string(value) || SortDirection.new(value))
558
- end
559
- end
560
-
561
- # Returns the instance of SortDirection for this value, or nil if not found
562
- def SortDirection.from_string(value)
563
- HttpClient::Preconditions.assert_class('value', value, String)
564
- SortDirection.ALL.find { |v| v.value == value }
565
- end
566
-
567
- def SortDirection.ALL
568
- @@all ||= [SortDirection.ascending, SortDirection.descending]
569
- end
570
-
571
- def SortDirection.ascending
572
- @@_ascending ||= SortDirection.new('ascending')
573
- end
574
-
575
- def SortDirection.descending
576
- @@_descending ||= SortDirection.new('descending')
577
- end
578
-
579
- def to_hash
580
- value
581
- end
582
-
583
- end
584
-
585
- class UnitOfMeasurement
586
-
587
- attr_reader :value
588
-
589
- def initialize(value)
590
- @value = HttpClient::Preconditions.assert_class('value', value, String)
591
- end
592
-
593
- # Returns the instance of UnitOfMeasurement for this value, creating a new instance for an unknown value
594
- def UnitOfMeasurement.apply(value)
595
- if value.instance_of?(UnitOfMeasurement)
596
- value
597
- else
598
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
599
- value.nil? ? nil : (from_string(value) || UnitOfMeasurement.new(value))
600
- end
601
- end
602
-
603
- # Returns the instance of UnitOfMeasurement for this value, or nil if not found
604
- def UnitOfMeasurement.from_string(value)
605
- HttpClient::Preconditions.assert_class('value', value, String)
606
- UnitOfMeasurement.ALL.find { |v| v.value == value }
607
- end
608
-
609
- def UnitOfMeasurement.ALL
610
- @@all ||= [UnitOfMeasurement.millimeter, UnitOfMeasurement.centimeter, UnitOfMeasurement.inch, UnitOfMeasurement.foot, UnitOfMeasurement.cubic_inch, UnitOfMeasurement.cubic_meter, UnitOfMeasurement.gram, UnitOfMeasurement.kilogram, UnitOfMeasurement.meter, UnitOfMeasurement.ounce, UnitOfMeasurement.pound]
611
- end
612
-
613
- # Equivalent to MILLI(METRE).
614
- def UnitOfMeasurement.millimeter
615
- @@_millimeter ||= UnitOfMeasurement.new('millimeter')
616
- end
617
-
618
- # Equivalent to CENTI(METRE).
619
- def UnitOfMeasurement.centimeter
620
- @@_centimeter ||= UnitOfMeasurement.new('centimeter')
621
- end
622
-
623
- # A unit of length equal to 0.01004 m (standard name in).
624
- def UnitOfMeasurement.inch
625
- @@_inch ||= UnitOfMeasurement.new('inch')
626
- end
627
-
628
- # A unit of length equal to 0.3048 m (standard name ft).
629
- def UnitOfMeasurement.foot
630
- @@_foot ||= UnitOfMeasurement.new('foot')
631
- end
632
-
633
- # A unit of volume equal to one cubic inch (in³).
634
- def UnitOfMeasurement.cubic_inch
635
- @@_cubic_inch ||= UnitOfMeasurement.new('cubic_inch')
636
- end
637
-
638
- # The metric unit for volume quantities (m³).
639
- def UnitOfMeasurement.cubic_meter
640
- @@_cubic_meter ||= UnitOfMeasurement.new('cubic_meter')
641
- end
642
-
643
- # A unit of mass equal to 1 / 1000 kilogram (standard name g).
644
- def UnitOfMeasurement.gram
645
- @@_gram ||= UnitOfMeasurement.new('gram')
646
- end
647
-
648
- # The base unit for mass quantities (kg).
649
- def UnitOfMeasurement.kilogram
650
- @@_kilogram ||= UnitOfMeasurement.new('kilogram')
651
- end
652
-
653
- # The base unit for length quantities (m).
654
- def UnitOfMeasurement.meter
655
- @@_meter ||= UnitOfMeasurement.new('meter')
656
- end
657
-
658
- # A unit of mass equal to 1 / 16 POUND (standard name oz).
659
- def UnitOfMeasurement.ounce
660
- @@_ounce ||= UnitOfMeasurement.new('ounce')
661
- end
662
-
663
- # A unit of mass equal to 453.59237 grams (avoirdupois pound, standard name lb).
664
- def UnitOfMeasurement.pound
665
- @@_pound ||= UnitOfMeasurement.new('pound')
666
- end
667
-
668
- def to_hash
669
- value
670
- end
671
-
672
- end
673
-
674
- class UnitOfTime
675
-
676
- attr_reader :value
677
-
678
- def initialize(value)
679
- @value = HttpClient::Preconditions.assert_class('value', value, String)
680
- end
681
-
682
- # Returns the instance of UnitOfTime for this value, creating a new instance for an unknown value
683
- def UnitOfTime.apply(value)
684
- if value.instance_of?(UnitOfTime)
685
- value
686
- else
687
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
688
- value.nil? ? nil : (from_string(value) || UnitOfTime.new(value))
689
- end
690
- end
691
-
692
- # Returns the instance of UnitOfTime for this value, or nil if not found
693
- def UnitOfTime.from_string(value)
694
- HttpClient::Preconditions.assert_class('value', value, String)
695
- UnitOfTime.ALL.find { |v| v.value == value }
696
- end
697
-
698
- def UnitOfTime.ALL
699
- @@all ||= [UnitOfTime.day, UnitOfTime.hour, UnitOfTime.minute]
700
- end
701
-
702
- def UnitOfTime.day
703
- @@_day ||= UnitOfTime.new('day')
704
- end
705
-
706
- def UnitOfTime.hour
707
- @@_hour ||= UnitOfTime.new('hour')
708
- end
709
-
710
- def UnitOfTime.minute
711
- @@_minute ||= UnitOfTime.new('minute')
712
- end
713
-
714
- def to_hash
715
- value
716
- end
717
-
718
- end
719
-
720
- class ValueAddedService
721
-
722
- attr_reader :value
723
-
724
- def initialize(value)
725
- @value = HttpClient::Preconditions.assert_class('value', value, String)
726
- end
727
-
728
- # Returns the instance of ValueAddedService for this value, creating a new instance for an unknown value
729
- def ValueAddedService.apply(value)
730
- if value.instance_of?(ValueAddedService)
731
- value
732
- else
733
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
734
- value.nil? ? nil : (from_string(value) || ValueAddedService.new(value))
735
- end
736
- end
737
-
738
- # Returns the instance of ValueAddedService for this value, or nil if not found
739
- def ValueAddedService.from_string(value)
740
- HttpClient::Preconditions.assert_class('value', value, String)
741
- ValueAddedService.ALL.find { |v| v.value == value }
742
- end
743
-
744
- def ValueAddedService.ALL
745
- @@all ||= [ValueAddedService.hazardous_material]
746
- end
747
-
748
- # See https://en.wikipedia.org/wiki/ORM-D
749
- def ValueAddedService.hazardous_material
750
- @@_hazardous_material ||= ValueAddedService.new('Hazardous Material')
751
- end
752
-
753
- def to_hash
754
- value
755
- end
756
-
757
- end
758
-
759
- class Visibility
760
-
761
- attr_reader :value
762
-
763
- def initialize(value)
764
- @value = HttpClient::Preconditions.assert_class('value', value, String)
765
- end
766
-
767
- # Returns the instance of Visibility for this value, creating a new instance for an unknown value
768
- def Visibility.apply(value)
769
- if value.instance_of?(Visibility)
770
- value
771
- else
772
- HttpClient::Preconditions.assert_class_or_nil('value', value, String)
773
- value.nil? ? nil : (from_string(value) || Visibility.new(value))
774
- end
775
- end
776
-
777
- # Returns the instance of Visibility for this value, or nil if not found
778
- def Visibility.from_string(value)
779
- HttpClient::Preconditions.assert_class('value', value, String)
780
- Visibility.ALL.find { |v| v.value == value }
781
- end
782
-
783
- def Visibility.ALL
784
- @@all ||= [Visibility.public, Visibility.private]
785
- end
786
-
787
- def Visibility.public
788
- @@_public ||= Visibility.new('public')
789
- end
790
-
791
- def Visibility.private
792
- @@_private ||= Visibility.new('private')
793
- end
794
-
795
- def to_hash
796
- value
797
- end
798
-
799
- end
800
-
801
- # Defines structured fields for a contact person. Typically used for specifying
802
- # contact person for an account, shipment, or organization representative
803
- class Contact
804
-
805
- attr_reader :name, :email, :phone
806
-
807
- def initialize(incoming={})
808
- opts = HttpClient::Helper.symbolize_keys(incoming)
809
- HttpClient::Preconditions.require_keys(opts, [:name], 'Contact')
810
- @name = (x = opts.delete(:name); x.is_a?(::Io::Flow::Common::V0::Models::Name) ? x : ::Io::Flow::Common::V0::Models::Name.new(x))
811
- @email = (x = opts.delete(:email); x.nil? ? nil : HttpClient::Preconditions.assert_class('email', x, String))
812
- @phone = (x = opts.delete(:phone); x.nil? ? nil : HttpClient::Preconditions.assert_class('phone', x, String))
813
- end
814
-
815
- def to_json
816
- JSON.dump(to_hash)
817
- end
818
-
819
- def copy(incoming={})
820
- Contact.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
821
- end
822
-
823
- def to_hash
824
- {
825
- :name => name.to_hash,
826
- :email => email,
827
- :phone => phone
828
- }
829
- end
830
-
831
- end
832
-
833
- class DatetimeRange
834
-
835
- attr_reader :from, :to
836
-
837
- def initialize(incoming={})
838
- opts = HttpClient::Helper.symbolize_keys(incoming)
839
- HttpClient::Preconditions.require_keys(opts, [:from, :to], 'DatetimeRange')
840
- @from = HttpClient::Preconditions.assert_class('from', HttpClient::Helper.to_date_time_iso8601(opts.delete(:from)), DateTime)
841
- @to = HttpClient::Preconditions.assert_class('to', HttpClient::Helper.to_date_time_iso8601(opts.delete(:to)), DateTime)
842
- end
843
-
844
- def to_json
845
- JSON.dump(to_hash)
846
- end
847
-
848
- def copy(incoming={})
849
- DatetimeRange.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
850
- end
851
-
852
- def to_hash
853
- {
854
- :from => from,
855
- :to => to
856
- }
857
- end
858
-
859
- end
860
-
861
- class Dimension
862
-
863
- attr_reader :type, :depth, :length, :weight, :width
864
-
865
- def initialize(incoming={})
866
- opts = HttpClient::Helper.symbolize_keys(incoming)
867
- HttpClient::Preconditions.require_keys(opts, [:type], 'Dimension')
868
- @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Common::V0::Models::DimensionType) ? x : ::Io::Flow::Common::V0::Models::DimensionType.apply(x))
869
- @depth = (x = opts.delete(:depth); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Common::V0::Models::Measurement) ? x : ::Io::Flow::Common::V0::Models::Measurement.new(x)))
870
- @length = (x = opts.delete(:length); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Common::V0::Models::Measurement) ? x : ::Io::Flow::Common::V0::Models::Measurement.new(x)))
871
- @weight = (x = opts.delete(:weight); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Common::V0::Models::Measurement) ? x : ::Io::Flow::Common::V0::Models::Measurement.new(x)))
872
- @width = (x = opts.delete(:width); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Common::V0::Models::Measurement) ? x : ::Io::Flow::Common::V0::Models::Measurement.new(x)))
873
- end
874
-
875
- def to_json
876
- JSON.dump(to_hash)
877
- end
878
-
879
- def copy(incoming={})
880
- Dimension.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
881
- end
882
-
883
- def to_hash
884
- {
885
- :type => type.value,
886
- :depth => depth.nil? ? nil : depth.to_hash,
887
- :length => length.nil? ? nil : length.to_hash,
888
- :weight => weight.nil? ? nil : weight.to_hash,
889
- :width => width.nil? ? nil : width.to_hash
890
- }
891
- end
892
-
893
- end
894
-
895
- class Error
896
-
897
- attr_reader :code, :message
898
-
899
- def initialize(incoming={})
900
- opts = HttpClient::Helper.symbolize_keys(incoming)
901
- HttpClient::Preconditions.require_keys(opts, [:code, :message], 'Error')
902
- @code = HttpClient::Preconditions.assert_class('code', opts.delete(:code), String)
903
- @message = HttpClient::Preconditions.assert_class('message', opts.delete(:message), String)
904
- end
905
-
906
- def to_json
907
- JSON.dump(to_hash)
908
- end
909
-
910
- def copy(incoming={})
911
- Error.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
912
- end
913
-
914
- def to_hash
915
- {
916
- :code => code,
917
- :message => message
918
- }
919
- end
920
-
921
- end
922
-
923
- # Represents an exception to the schedule of a location.
924
- class Exception
925
-
926
- attr_reader :type, :datetime_range
927
-
928
- def initialize(incoming={})
929
- opts = HttpClient::Helper.symbolize_keys(incoming)
930
- HttpClient::Preconditions.require_keys(opts, [:type, :datetime_range], 'Exception')
931
- @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Common::V0::Models::ExceptionType) ? x : ::Io::Flow::Common::V0::Models::ExceptionType.apply(x))
932
- @datetime_range = (x = opts.delete(:datetime_range); x.is_a?(::Io::Flow::Common::V0::Models::DatetimeRange) ? x : ::Io::Flow::Common::V0::Models::DatetimeRange.new(x))
933
- end
934
-
935
- def to_json
936
- JSON.dump(to_hash)
937
- end
938
-
939
- def copy(incoming={})
940
- Exception.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
941
- end
942
-
943
- def to_hash
944
- {
945
- :type => type.value,
946
- :datetime_range => datetime_range.to_hash
947
- }
948
- end
949
-
950
- end
951
-
952
- # Some important fields related to experiences used in various APIs
953
- class ExperienceSummary
954
-
955
- attr_reader :id, :key, :name, :currency, :country
956
-
957
- def initialize(incoming={})
958
- opts = HttpClient::Helper.symbolize_keys(incoming)
959
- HttpClient::Preconditions.require_keys(opts, [:id, :key, :name], 'ExperienceSummary')
960
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
961
- @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
962
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
963
- @currency = (x = opts.delete(:currency); x.nil? ? nil : HttpClient::Preconditions.assert_class('currency', x, String))
964
- @country = (x = opts.delete(:country); x.nil? ? nil : HttpClient::Preconditions.assert_class('country', x, String))
965
- end
966
-
967
- def to_json
968
- JSON.dump(to_hash)
969
- end
970
-
971
- def copy(incoming={})
972
- ExperienceSummary.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
973
- end
974
-
975
- def to_hash
976
- {
977
- :id => id,
978
- :key => key,
979
- :name => name,
980
- :currency => currency,
981
- :country => country
982
- }
983
- end
984
-
985
- end
986
-
987
- class Healthcheck
988
-
989
- attr_reader :status
990
-
991
- def initialize(incoming={})
992
- opts = HttpClient::Helper.symbolize_keys(incoming)
993
- HttpClient::Preconditions.require_keys(opts, [:status], 'Healthcheck')
994
- @status = HttpClient::Preconditions.assert_class('status', opts.delete(:status), String)
995
- end
996
-
997
- def to_json
998
- JSON.dump(to_hash)
999
- end
1000
-
1001
- def copy(incoming={})
1002
- Healthcheck.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1003
- end
1004
-
1005
- def to_hash
1006
- {
1007
- :status => status
1008
- }
1009
- end
1010
-
1011
- end
1012
-
1013
- # Defines structured fields for address to be used in user/form input. Either
1014
- # text or the structured input needs to be present.
1015
- class Location < ExpandableLocation
1016
-
1017
- attr_reader :text, :streets, :city, :province, :postal, :country, :latitude, :longitude
1018
-
1019
- def initialize(incoming={})
1020
- super(:name => ExpandableLocation::Types::LOCATION)
1021
- opts = HttpClient::Helper.symbolize_keys(incoming)
1022
- @text = (x = opts.delete(:text); x.nil? ? nil : HttpClient::Preconditions.assert_class('text', x, String))
1023
- @streets = (x = opts.delete(:streets); x.nil? ? nil : HttpClient::Preconditions.assert_class('streets', x, Array).map { |v| HttpClient::Preconditions.assert_class('streets', v, String) })
1024
- @city = (x = opts.delete(:city); x.nil? ? nil : HttpClient::Preconditions.assert_class('city', x, String))
1025
- @province = (x = opts.delete(:province); x.nil? ? nil : HttpClient::Preconditions.assert_class('province', x, String))
1026
- @postal = (x = opts.delete(:postal); x.nil? ? nil : HttpClient::Preconditions.assert_class('postal', x, String))
1027
- @country = (x = opts.delete(:country); x.nil? ? nil : HttpClient::Preconditions.assert_class('country', x, String))
1028
- @latitude = (x = opts.delete(:latitude); x.nil? ? nil : HttpClient::Preconditions.assert_class('latitude', x, String))
1029
- @longitude = (x = opts.delete(:longitude); x.nil? ? nil : HttpClient::Preconditions.assert_class('longitude', x, String))
1030
- end
1031
-
1032
- def to_json
1033
- JSON.dump(to_hash)
1034
- end
1035
-
1036
- def copy(incoming={})
1037
- Location.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1038
- end
1039
-
1040
- def subtype_to_hash
1041
- {
1042
- :text => text,
1043
- :streets => streets.nil? ? nil : streets,
1044
- :city => city,
1045
- :province => province,
1046
- :postal => postal,
1047
- :country => country,
1048
- :latitude => latitude,
1049
- :longitude => longitude
1050
- }
1051
- end
1052
-
1053
- end
1054
-
1055
- class LocationReference < ExpandableLocation
1056
-
1057
- attr_reader :text
1058
-
1059
- def initialize(incoming={})
1060
- super(:name => ExpandableLocation::Types::LOCATION_REFERENCE)
1061
- opts = HttpClient::Helper.symbolize_keys(incoming)
1062
- @text = (x = opts.delete(:text); x.nil? ? nil : HttpClient::Preconditions.assert_class('text', x, String))
1063
- end
1064
-
1065
- def to_json
1066
- JSON.dump(to_hash)
1067
- end
1068
-
1069
- def copy(incoming={})
1070
- LocationReference.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1071
- end
1072
-
1073
- def subtype_to_hash
1074
- {
1075
- :text => text
1076
- }
1077
- end
1078
-
1079
- end
1080
-
1081
- class Measurement
1082
-
1083
- attr_reader :value, :units
1084
-
1085
- def initialize(incoming={})
1086
- opts = HttpClient::Helper.symbolize_keys(incoming)
1087
- HttpClient::Preconditions.require_keys(opts, [:value, :units], 'Measurement')
1088
- @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), String)
1089
- @units = (x = opts.delete(:units); x.is_a?(::Io::Flow::Common::V0::Models::UnitOfMeasurement) ? x : ::Io::Flow::Common::V0::Models::UnitOfMeasurement.apply(x))
1090
- end
1091
-
1092
- def to_json
1093
- JSON.dump(to_hash)
1094
- end
1095
-
1096
- def copy(incoming={})
1097
- Measurement.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1098
- end
1099
-
1100
- def to_hash
1101
- {
1102
- :value => value,
1103
- :units => units.value
1104
- }
1105
- end
1106
-
1107
- end
1108
-
1109
- class Name
1110
-
1111
- attr_reader :first, :last
1112
-
1113
- def initialize(incoming={})
1114
- opts = HttpClient::Helper.symbolize_keys(incoming)
1115
- @first = (x = opts.delete(:first); x.nil? ? nil : HttpClient::Preconditions.assert_class('first', x, String))
1116
- @last = (x = opts.delete(:last); x.nil? ? nil : HttpClient::Preconditions.assert_class('last', x, String))
1117
- end
1118
-
1119
- def to_json
1120
- JSON.dump(to_hash)
1121
- end
1122
-
1123
- def copy(incoming={})
1124
- Name.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1125
- end
1126
-
1127
- def to_hash
1128
- {
1129
- :first => first,
1130
- :last => last
1131
- }
1132
- end
1133
-
1134
- end
1135
-
1136
- # Represents a single organization in the system
1137
- class Organization < ExpandableOrganization
1138
-
1139
- attr_reader :id, :name
1140
-
1141
- def initialize(incoming={})
1142
- super(:name => ExpandableOrganization::Types::ORGANIZATION)
1143
- opts = HttpClient::Helper.symbolize_keys(incoming)
1144
- HttpClient::Preconditions.require_keys(opts, [:id, :name], 'Organization')
1145
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1146
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
1147
- end
1148
-
1149
- def to_json
1150
- JSON.dump(to_hash)
1151
- end
1152
-
1153
- def copy(incoming={})
1154
- Organization.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1155
- end
1156
-
1157
- def subtype_to_hash
1158
- {
1159
- :id => id,
1160
- :name => name
1161
- }
1162
- end
1163
-
1164
- end
1165
-
1166
- class OrganizationReference < ExpandableOrganization
1167
-
1168
- attr_reader :id
1169
-
1170
- def initialize(incoming={})
1171
- super(:name => ExpandableOrganization::Types::ORGANIZATION_REFERENCE)
1172
- opts = HttpClient::Helper.symbolize_keys(incoming)
1173
- HttpClient::Preconditions.require_keys(opts, [:id], 'OrganizationReference')
1174
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1175
- end
1176
-
1177
- def to_json
1178
- JSON.dump(to_hash)
1179
- end
1180
-
1181
- def copy(incoming={})
1182
- OrganizationReference.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1183
- end
1184
-
1185
- def subtype_to_hash
1186
- {
1187
- :id => id
1188
- }
1189
- end
1190
-
1191
- end
1192
-
1193
- class OrganizationSummary
1194
-
1195
- attr_reader :id, :name
1196
-
1197
- def initialize(incoming={})
1198
- opts = HttpClient::Helper.symbolize_keys(incoming)
1199
- HttpClient::Preconditions.require_keys(opts, [:id, :name], 'OrganizationSummary')
1200
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1201
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
1202
- end
1203
-
1204
- def to_json
1205
- JSON.dump(to_hash)
1206
- end
1207
-
1208
- def copy(incoming={})
1209
- OrganizationSummary.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1210
- end
1211
-
1212
- def to_hash
1213
- {
1214
- :id => id,
1215
- :name => name
1216
- }
1217
- end
1218
-
1219
- end
1220
-
1221
- # Represents operating calendar and holidays of a location
1222
- class Schedule
1223
-
1224
- attr_reader :calendar, :holiday, :exception, :cutoff
1225
-
1226
- def initialize(incoming={})
1227
- opts = HttpClient::Helper.symbolize_keys(incoming)
1228
- HttpClient::Preconditions.require_keys(opts, [:holiday, :exception], 'Schedule')
1229
- @calendar = (x = opts.delete(:calendar); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Common::V0::Models::Calendar) ? x : ::Io::Flow::Common::V0::Models::Calendar.apply(x)))
1230
- @holiday = (x = opts.delete(:holiday); x.is_a?(::Io::Flow::Common::V0::Models::HolidayCalendar) ? x : ::Io::Flow::Common::V0::Models::HolidayCalendar.apply(x))
1231
- @exception = HttpClient::Preconditions.assert_class('exception', opts.delete(:exception), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Common::V0::Models::Exception) ? x : ::Io::Flow::Common::V0::Models::Exception.new(x)) }
1232
- @cutoff = (x = opts.delete(:cutoff); x.nil? ? nil : HttpClient::Preconditions.assert_class('cutoff', x, String))
1233
- end
1234
-
1235
- def to_json
1236
- JSON.dump(to_hash)
1237
- end
1238
-
1239
- def copy(incoming={})
1240
- Schedule.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1241
- end
1242
-
1243
- def to_hash
1244
- {
1245
- :calendar => calendar.nil? ? nil : calendar.value,
1246
- :holiday => holiday.value,
1247
- :exception => exception.map { |o| o.to_hash },
1248
- :cutoff => cutoff
1249
- }
1250
- end
1251
-
1252
- end
1253
-
1254
- # Represents a single user in the system
1255
- class User < ExpandableUser
1256
-
1257
- attr_reader :id, :email, :name
1258
-
1259
- def initialize(incoming={})
1260
- super(:name => ExpandableUser::Types::USER)
1261
- opts = HttpClient::Helper.symbolize_keys(incoming)
1262
- HttpClient::Preconditions.require_keys(opts, [:id, :name], 'User')
1263
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1264
- @email = (x = opts.delete(:email); x.nil? ? nil : HttpClient::Preconditions.assert_class('email', x, String))
1265
- @name = (x = opts.delete(:name); x.is_a?(::Io::Flow::Common::V0::Models::Name) ? x : ::Io::Flow::Common::V0::Models::Name.new(x))
1266
- end
1267
-
1268
- def to_json
1269
- JSON.dump(to_hash)
1270
- end
1271
-
1272
- def copy(incoming={})
1273
- User.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1274
- end
1275
-
1276
- def subtype_to_hash
1277
- {
1278
- :id => id,
1279
- :email => email,
1280
- :name => name.to_hash
1281
- }
1282
- end
1283
-
1284
- end
1285
-
1286
- class UserReference < ExpandableUser
1287
-
1288
- attr_reader :id
1289
-
1290
- def initialize(incoming={})
1291
- super(:name => ExpandableUser::Types::USER_REFERENCE)
1292
- opts = HttpClient::Helper.symbolize_keys(incoming)
1293
- HttpClient::Preconditions.require_keys(opts, [:id], 'UserReference')
1294
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1295
- end
1296
-
1297
- def to_json
1298
- JSON.dump(to_hash)
1299
- end
1300
-
1301
- def copy(incoming={})
1302
- UserReference.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1303
- end
1304
-
1305
- def subtype_to_hash
1306
- {
1307
- :id => id
1308
- }
1309
- end
1310
-
1311
- end
1312
-
1313
- class UserSummary
1314
-
1315
- attr_reader :id, :email, :name
1316
-
1317
- def initialize(incoming={})
1318
- opts = HttpClient::Helper.symbolize_keys(incoming)
1319
- HttpClient::Preconditions.require_keys(opts, [:id, :name], 'UserSummary')
1320
- @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
1321
- @email = (x = opts.delete(:email); x.nil? ? nil : HttpClient::Preconditions.assert_class('email', x, String))
1322
- @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
1323
- end
1324
-
1325
- def to_json
1326
- JSON.dump(to_hash)
1327
- end
1328
-
1329
- def copy(incoming={})
1330
- UserSummary.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
1331
- end
1332
-
1333
- def to_hash
1334
- {
1335
- :id => id,
1336
- :email => email,
1337
- :name => name
1338
- }
1339
- end
1340
-
1341
- end
1342
-
1343
- end
1344
-
1345
- # ===== END OF SERVICE DEFINITION =====
1346
- module HttpClient
1347
-
1348
- class Request
1349
-
1350
- def initialize(uri)
1351
- @uri = Preconditions.assert_class('uri', uri, URI)
1352
- @params = nil
1353
- @body = nil
1354
- @auth = nil
1355
- @headers = {}
1356
- @header_keys_lower_case = []
1357
- end
1358
-
1359
- def with_header(name, value)
1360
- Preconditions.check_not_blank('name', name, "Header name is required")
1361
- Preconditions.check_not_blank('value', value, "Header value is required")
1362
- Preconditions.check_state(!@headers.has_key?(name),
1363
- "Duplicate header named[%s]" % name)
1364
- @headers[name] = value
1365
- @header_keys_lower_case << name.downcase
1366
- self
1367
- end
1368
-
1369
- def with_auth(auth)
1370
- Preconditions.assert_class('auth', auth, HttpClient::Authorization)
1371
- Preconditions.check_state(@auth.nil?, "auth previously set")
1372
-
1373
- if auth.scheme.name == AuthScheme::BASIC.name
1374
- @auth = auth
1375
- else
1376
- raise "Auth Scheme[#{auth.scheme.name}] not supported"
1377
- end
1378
- self
1379
- end
1380
-
1381
- def with_query(params)
1382
- Preconditions.assert_class('params', params, Hash)
1383
- Preconditions.check_state(@params.nil?, "Already have query parameters")
1384
- @params = params
1385
- self
1386
- end
1387
-
1388
- # Wrapper to set Content-Type header to application/json and set
1389
- # the provided json document as the body
1390
- def with_json(json)
1391
- @headers['Content-Type'] ||= 'application/json; charset=UTF-8'
1392
- with_body(json)
1393
- end
1394
-
1395
- def with_body(body)
1396
- Preconditions.check_not_blank('body', body)
1397
- @body = body
1398
- self
1399
- end
1400
-
1401
- # Creates a new Net:HTTP client. The client returned should be
1402
- # fully configured to make a request.
1403
- def new_http_client
1404
- client = Net::HTTP.new(@uri.host, @uri.port)
1405
- if @uri.scheme == "https"
1406
- configure_ssl(client)
1407
- end
1408
- client
1409
- end
1410
-
1411
- # If HTTPS is required, this method accepts an HTTP Client and configures SSL
1412
- def configure_ssl(http)
1413
- Preconditions.assert_class('http', http, Net::HTTP)
1414
- http.use_ssl = true
1415
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
1416
- http.cert_store = OpenSSL::X509::Store.new
1417
- http.cert_store.set_default_paths
1418
- end
1419
-
1420
- def get(&block)
1421
- do_request(Net::HTTP::Get, &block)
1422
- end
1423
-
1424
- def delete(&block)
1425
- do_request(Net::HTTP::Delete, &block)
1426
- end
1427
-
1428
- def options(&block)
1429
- do_request(Net::HTTP::Options, &block)
1430
- end
1431
-
1432
- def post(&block)
1433
- do_request(Net::HTTP::Post, &block)
1434
- end
1435
-
1436
- def put(&block)
1437
- do_request(Net::HTTP::Put, &block)
1438
- end
1439
-
1440
- class PATCH < Net::HTTP::Put
1441
- METHOD = "PATCH"
1442
- end
1443
-
1444
- def patch(&block)
1445
- do_request(PATCH, &block)
1446
- end
1447
-
1448
- def do_request(klass)
1449
- Preconditions.assert_class('klass', klass, Class)
1450
-
1451
- uri = @uri.to_s
1452
- if q = to_query(@params)
1453
- uri += "?%s" % q
1454
- end
1455
-
1456
- request = klass.send(:new, uri)
1457
-
1458
- curl = ['curl']
1459
- if klass != Net::HTTP::Get
1460
- curl << "-X%s" % klass.name.split("::").last.upcase
1461
- end
1462
-
1463
- if @body
1464
- # DEBUG path = "/tmp/rest_client.tmp"
1465
- # DEBUG File.open(path, "w") { |os| os << @body.to_s }
1466
- # DEBUG curl << "-d@%s" % path
1467
- request.body = @body
1468
- end
1469
-
1470
- if @auth
1471
- curl << "-u \"%s:%s\"" % [@auth.username, @auth.password]
1472
- Preconditions.check_state(!@header_keys_lower_case.include?("authorization"),
1473
- "Cannot specify both an Authorization header and an auth instance")
1474
- user_pass = "%s:%s" % [@auth.username, @auth.password]
1475
- encoded = Base64.encode64(user_pass).to_s.split("\n").map(&:strip).join
1476
- request.add_field("Authorization", "Basic %s" % encoded)
1477
- end
1478
-
1479
- @headers.each { |key, value|
1480
- curl << "-H \"%s: %s\"" % [key, value]
1481
- request.add_field(key, value)
1482
- }
1483
-
1484
- curl << "'%s'" % uri
1485
- # DEBUG puts curl.join(" ")
1486
-
1487
- raw_response = http_request(request)
1488
- response = raw_response.to_s == "" ? nil : JSON.parse(raw_response)
1489
-
1490
- if block_given?
1491
- yield response
1492
- else
1493
- response
1494
- end
1495
- end
1496
-
1497
- private
1498
- def to_query(params={})
1499
- parts = (params || {}).map { |k,v|
1500
- if v.respond_to?(:each)
1501
- v.map { |el| "%s=%s" % [k, CGI.escape(el.to_s)] }
1502
- else
1503
- "%s=%s" % [k, CGI.escape(v.to_s)]
1504
- end
1505
- }
1506
- parts.empty? ? nil : parts.join("&")
1507
- end
1508
-
1509
- def http_request(request)
1510
- response = begin
1511
- new_http_client.request(request)
1512
- rescue SocketError => e
1513
- raise Exception.new("Error accessing uri[#{@uri}]: #{e}")
1514
- end
1515
-
1516
- case response
1517
- when Net::HTTPSuccess
1518
- response.body
1519
- else
1520
- body = response.body rescue nil
1521
- raise HttpClient::ServerError.new(response.code.to_i, response.message, :body => body, :uri => @uri.to_s)
1522
- end
1523
- end
1524
- end
1525
-
1526
- class ServerError < StandardError
1527
-
1528
- attr_reader :code, :details, :body, :uri
1529
-
1530
- def initialize(code, details, incoming={})
1531
- opts = HttpClient::Helper.symbolize_keys(incoming)
1532
- @code = HttpClient::Preconditions.assert_class('code', code, Integer)
1533
- @details = HttpClient::Preconditions.assert_class('details', details, String)
1534
- @body = HttpClient::Preconditions.assert_class_or_nil('body', opts.delete(:body), String)
1535
- @uri = HttpClient::Preconditions.assert_class_or_nil('uri', opts.delete(:uri), String)
1536
- HttpClient::Preconditions.assert_empty_opts(opts)
1537
- super(self.message)
1538
- end
1539
-
1540
- def message
1541
- m = "%s %s" % [@code, @details]
1542
- if @body
1543
- m << ": %s" % @body
1544
- end
1545
- m
1546
- end
1547
-
1548
- def body_json
1549
- JSON.parse(@body)
1550
- end
1551
-
1552
- end
1553
-
1554
- class PreconditionException < Exception
1555
-
1556
- attr_reader :message
1557
-
1558
- def initialize(message)
1559
- super(message)
1560
- @message = message
1561
- end
1562
-
1563
- end
1564
-
1565
- module Preconditions
1566
-
1567
- def Preconditions.check_argument(expression, error_message=nil)
1568
- if !expression
1569
- raise PreconditionException.new(error_message || "check_argument failed")
1570
- end
1571
- nil
1572
- end
1573
-
1574
- def Preconditions.check_state(expression, error_message=nil)
1575
- if !expression
1576
- raise PreconditionException.new(error_message || "check_state failed")
1577
- end
1578
- nil
1579
- end
1580
-
1581
- def Preconditions.check_not_nil(field_name, reference, error_message=nil)
1582
- if reference.nil?
1583
- raise PreconditionException.new(error_message || "argument for %s cannot be nil" % field_name)
1584
- end
1585
- reference
1586
- end
1587
-
1588
- def Preconditions.check_not_blank(field_name, reference, error_message=nil)
1589
- if reference.to_s.strip == ""
1590
- raise PreconditionException.new(error_message || "argument for %s cannot be blank" % field_name)
1591
- end
1592
- reference
1593
- end
1594
-
1595
- # Throws an error if opts is not empty. Useful when parsing
1596
- # arguments to a function
1597
- def Preconditions.assert_empty_opts(opts)
1598
- if !opts.empty?
1599
- raise PreconditionException.new("Invalid opts: #{opts.keys.inspect}\n#{opts.inspect}")
1600
- end
1601
- end
1602
-
1603
- # Requires that the provided hash has the specified keys.
1604
- # @param fields A list of symbols
1605
- def Preconditions.require_keys(hash, fields, error_prefix=nil)
1606
- missing = fields.select { |f| !hash.has_key?(f) }
1607
- if !missing.empty?
1608
- msg = "Missing required fields: " + missing.join(", ")
1609
- raise PreconditionException.new(error_prefix.empty? ? msg : "#{error_prefix}: #{msg}")
1610
- end
1611
- end
1612
-
1613
- # Asserts that value is not nill and is_?(klass). Returns
1614
- # value. Common use is
1615
- #
1616
- # amount = Preconditions.assert_class('amount', amount, BigDecimal)
1617
- def Preconditions.assert_class(field_name, value, klass)
1618
- Preconditions.check_not_nil('field_name', field_name)
1619
- Preconditions.check_not_nil('klass', klass)
1620
- Preconditions.check_not_nil('value', value, "Value for %s cannot be nil. Expected an instance of class %s" % [field_name, klass.name])
1621
- Preconditions.check_state(value.is_a?(klass),
1622
- "Value for #{field_name} is of type[#{value.class}] - class[#{klass}] is required. value[#{value.inspect.to_s}]")
1623
- value
1624
- end
1625
-
1626
- def Preconditions.assert_class_or_nil(field_name, value, klass)
1627
- if !value.nil?
1628
- Preconditions.assert_class(field_name, value, klass)
1629
- end
1630
- end
1631
-
1632
- def Preconditions.assert_boolean(field_name, value)
1633
- Preconditions.check_not_nil('field_name', field_name)
1634
- Preconditions.check_not_nil('value', value, "Value for %s cannot be nil. Expected an instance of TrueClass or FalseClass" % field_name)
1635
- Preconditions.check_state(value.is_a?(TrueClass) || value.is_a?(FalseClass),
1636
- "Value for #{field_name} is of type[#{value.class}] - class[TrueClass or FalseClass] is required. value[#{value.inspect.to_s}]")
1637
- value
1638
- end
1639
-
1640
- def Preconditions.assert_boolean_or_nil(field_name, value)
1641
- if !value.nil?
1642
- Preconditions.assert_boolean(field_name, value)
1643
- end
1644
- end
1645
-
1646
- def Preconditions.assert_collection_of_class(field_name, values, klass)
1647
- Preconditions.assert_class(field_name, values, Array)
1648
- values.each { |v| Preconditions.assert_class(field_name, v, klass) }
1649
- end
1650
-
1651
- def Preconditions.assert_hash_of_class(field_name, hash, klass)
1652
- Preconditions.assert_class(field_name, hash, Hash)
1653
- values.each { |k, v| Preconditions.assert_class(field_name, v, klass) }
1654
- end
1655
-
1656
- end
1657
-
1658
- class AuthScheme
1659
-
1660
- attr_reader :name
1661
-
1662
- def initialize(name)
1663
- @name = HttpClient::Preconditions.check_not_blank('name', name)
1664
- end
1665
-
1666
- BASIC = AuthScheme.new("basic") unless defined?(BASIC)
1667
-
1668
- end
1669
-
1670
- class Authorization
1671
-
1672
- attr_reader :scheme, :username, :password
1673
-
1674
- def initialize(scheme, username, opts={})
1675
- @scheme = HttpClient::Preconditions.assert_class('schema', scheme, AuthScheme)
1676
- @username = HttpClient::Preconditions.check_not_blank('username', username, "username is required")
1677
- @password = HttpClient::Preconditions.assert_class_or_nil('password', opts.delete(:password), String)
1678
- HttpClient::Preconditions.assert_empty_opts(opts)
1679
- end
1680
-
1681
- def Authorization.basic(username, password=nil)
1682
- Authorization.new(AuthScheme::BASIC, username, :password => password)
1683
- end
1684
-
1685
- end
1686
-
1687
- module Helper
1688
-
1689
- def Helper.symbolize_keys(hash)
1690
- Preconditions.assert_class('hash', hash, Hash)
1691
- new_hash = {}
1692
- hash.each { |k, v|
1693
- new_hash[k.to_sym] = v
1694
- }
1695
- new_hash
1696
- end
1697
-
1698
- def Helper.to_big_decimal(value)
1699
- value ? BigDecimal.new(value.to_s) : nil
1700
- end
1701
-
1702
- def Helper.to_object(value)
1703
- value ? JSON.parse(value) : nil
1704
- end
1705
-
1706
- def Helper.to_uuid(value)
1707
- 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$/),
1708
- "Invalid guid[%s]" % value)
1709
- value
1710
- end
1711
-
1712
- def Helper.to_date_iso8601(value)
1713
- if value.is_a?(Date)
1714
- value
1715
- elsif value
1716
- Date.parse(value.to_s)
1717
- else
1718
- nil
1719
- end
1720
- end
1721
-
1722
- def Helper.to_date_time_iso8601(value)
1723
- if value.is_a?(DateTime)
1724
- value
1725
- elsif value
1726
- DateTime.parse(value.to_s)
1727
- else
1728
- nil
1729
- end
1730
- end
1731
-
1732
- def Helper.date_iso8601_to_string(value)
1733
- value.nil? ? nil : value.strftime('%Y-%m-%d')
1734
- end
1735
-
1736
- def Helper.date_time_iso8601_to_string(value)
1737
- value.nil? ? nil : value.strftime('%Y-%m-%dT%H:%M:%S%z')
1738
- end
1739
-
1740
- TRUE_STRINGS = ['t', 'true', 'y', 'yes', 'on', '1', 'trueclass'] unless defined?(TRUE_STRINGS)
1741
- FALSE_STRINGS = ['f', 'false', 'n', 'no', 'off', '0', 'falseclass'] unless defined?(FALSE_STRINGS)
1742
-
1743
- def Helper.to_boolean(field_name, value)
1744
- string = value.to_s.strip.downcase
1745
- if TRUE_STRINGS.include?(string)
1746
- true
1747
- elsif FALSE_STRINGS.include?(string)
1748
- false
1749
- elsif string != ""
1750
- 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}")
1751
- else
1752
- nil
1753
- end
1754
- end
1755
-
1756
- end
1757
-
1758
- end
1759
- end
1760
- end
1761
- end
1762
- end