patch_ruby 1.23.0 → 1.24.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -11
- data/lib/patch_ruby/api/estimates_api.rb +357 -7
- data/lib/patch_ruby/api/orders_api.rb +36 -36
- data/lib/patch_ruby/api/projects_api.rb +2 -2
- data/lib/patch_ruby/api_client.rb +1 -1
- data/lib/patch_ruby/models/create_air_shipping_estimate_request.rb +374 -0
- data/lib/patch_ruby/models/{v1_orders_issued_to.rb → create_ecommerce_estimate_request.rb} +154 -20
- data/lib/patch_ruby/models/create_order_request.rb +3 -4
- data/lib/patch_ruby/models/create_rail_shipping_estimate_request.rb +404 -0
- data/lib/patch_ruby/models/create_road_shipping_estimate_request.rb +507 -0
- data/lib/patch_ruby/models/create_sea_shipping_estimate_request.rb +461 -0
- data/lib/patch_ruby/models/order.rb +7 -3
- data/lib/patch_ruby/models/{issued_to.rb → order_issued_to.rb} +7 -7
- data/lib/patch_ruby/models/place_order_request.rb +1 -2
- data/lib/patch_ruby/models/project.rb +1 -1
- data/lib/patch_ruby/version.rb +1 -1
- data/lib/patch_ruby.rb +6 -2
- data/spec/integration/estimates_spec.rb +165 -1
- data/spec/integration/orders_spec.rb +3 -3
- data/spec/integration/projects_spec.rb +2 -2
- data/spec/models/create_order_request_spec.rb +1 -1
- metadata +31 -27
@@ -28,19 +28,19 @@ module Patch
|
|
28
28
|
@api_client = api_client
|
29
29
|
end
|
30
30
|
# Cancel an order
|
31
|
-
# Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` or `placed` state can be cancelled.
|
32
|
-
# @param id [String]
|
31
|
+
# Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` or `placed` state can be cancelled.
|
32
|
+
# @param id [String]
|
33
33
|
# @param [Hash] opts the optional parameters
|
34
34
|
# @return [OrderResponse]
|
35
35
|
def cancel_order(id, opts = {})
|
36
|
-
|
36
|
+
|
37
37
|
data, _status_code, _headers = cancel_order_with_http_info(id, opts)
|
38
38
|
data
|
39
39
|
end
|
40
40
|
|
41
41
|
# Cancel an order
|
42
|
-
# Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the
|
43
|
-
# @param id [String]
|
42
|
+
# Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` or `placed` state can be cancelled.
|
43
|
+
# @param id [String]
|
44
44
|
# @param [Hash] opts the optional parameters
|
45
45
|
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
|
46
46
|
def cancel_order_with_http_info(id, opts = {})
|
@@ -92,19 +92,19 @@ module Patch
|
|
92
92
|
end
|
93
93
|
|
94
94
|
# Creates an order
|
95
|
-
# Creates an order in the `placed` or `draft` state.
|
96
|
-
# @param create_order_request [CreateOrderRequest]
|
95
|
+
# Creates an order in the `placed` or `draft` state.
|
96
|
+
# @param create_order_request [CreateOrderRequest]
|
97
97
|
# @param [Hash] opts the optional parameters
|
98
98
|
# @return [OrderResponse]
|
99
99
|
def create_order(create_order_request = {}, opts = {})
|
100
|
-
_create_order_request = Patch::CreateOrderRequest.new(create_order_request)
|
100
|
+
_create_order_request = Patch::CreateOrderRequest.new(create_order_request)
|
101
101
|
data, _status_code, _headers = create_order_with_http_info(_create_order_request, opts)
|
102
102
|
data
|
103
103
|
end
|
104
104
|
|
105
105
|
# Creates an order
|
106
|
-
# Creates an order in the
|
107
|
-
# @param create_order_request [CreateOrderRequest]
|
106
|
+
# Creates an order in the `placed` or `draft` state.
|
107
|
+
# @param create_order_request [CreateOrderRequest]
|
108
108
|
# @param [Hash] opts the optional parameters
|
109
109
|
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
|
110
110
|
def create_order_with_http_info(create_order_request, opts = {})
|
@@ -161,22 +161,22 @@ module Patch
|
|
161
161
|
end
|
162
162
|
|
163
163
|
# Place an order
|
164
|
-
# Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed
|
165
|
-
# @param id [String]
|
164
|
+
# Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed
|
165
|
+
# @param id [String]
|
166
166
|
# @param [Hash] opts the optional parameters
|
167
|
-
# @option opts [PlaceOrderRequest] :place_order_request
|
167
|
+
# @option opts [PlaceOrderRequest] :place_order_request
|
168
168
|
# @return [OrderResponse]
|
169
|
-
def place_order(id,
|
170
|
-
|
171
|
-
data, _status_code, _headers = place_order_with_http_info(id, opts
|
169
|
+
def place_order(id, opts = {})
|
170
|
+
|
171
|
+
data, _status_code, _headers = place_order_with_http_info(id, opts)
|
172
172
|
data
|
173
173
|
end
|
174
174
|
|
175
175
|
# Place an order
|
176
|
-
# Placing an order confirms an order
|
177
|
-
# @param id [String]
|
176
|
+
# Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed
|
177
|
+
# @param id [String]
|
178
178
|
# @param [Hash] opts the optional parameters
|
179
|
-
# @option opts [PlaceOrderRequest] :place_order_request
|
179
|
+
# @option opts [PlaceOrderRequest] :place_order_request
|
180
180
|
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
|
181
181
|
def place_order_with_http_info(id, opts = {})
|
182
182
|
if @api_client.config.debugging
|
@@ -206,7 +206,7 @@ module Patch
|
|
206
206
|
form_params = opts[:form_params] || {}
|
207
207
|
|
208
208
|
# http body (model)
|
209
|
-
post_body = opts[:debug_body] || @api_client.object_to_http_body(opts
|
209
|
+
post_body = opts[:debug_body] || @api_client.object_to_http_body(opts)
|
210
210
|
|
211
211
|
# return_type
|
212
212
|
return_type = opts[:debug_return_type] || 'OrderResponse'
|
@@ -232,19 +232,19 @@ module Patch
|
|
232
232
|
end
|
233
233
|
|
234
234
|
# Retrieves an order
|
235
|
-
# Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
|
236
|
-
# @param id [String]
|
235
|
+
# Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
|
236
|
+
# @param id [String]
|
237
237
|
# @param [Hash] opts the optional parameters
|
238
238
|
# @return [OrderResponse]
|
239
239
|
def retrieve_order(id, opts = {})
|
240
|
-
|
240
|
+
|
241
241
|
data, _status_code, _headers = retrieve_order_with_http_info(id, opts)
|
242
242
|
data
|
243
243
|
end
|
244
244
|
|
245
245
|
# Retrieves an order
|
246
|
-
# Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
|
247
|
-
# @param id [String]
|
246
|
+
# Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
|
247
|
+
# @param id [String]
|
248
248
|
# @param [Hash] opts the optional parameters
|
249
249
|
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
|
250
250
|
def retrieve_order_with_http_info(id, opts = {})
|
@@ -296,26 +296,26 @@ module Patch
|
|
296
296
|
end
|
297
297
|
|
298
298
|
# Retrieves a list of orders
|
299
|
-
# Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
|
299
|
+
# Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
|
300
300
|
# @param [Hash] opts the optional parameters
|
301
|
-
# @option opts [Integer] :page
|
302
|
-
# @option opts [String] :metadata
|
303
|
-
# @option opts [String] :metadata_example1
|
304
|
-
# @option opts [String] :metadata_example2
|
301
|
+
# @option opts [Integer] :page
|
302
|
+
# @option opts [String] :metadata
|
303
|
+
# @option opts [String] :metadata_example1
|
304
|
+
# @option opts [String] :metadata_example2
|
305
305
|
# @return [OrderListResponse]
|
306
306
|
def retrieve_orders(opts = {})
|
307
|
-
|
307
|
+
|
308
308
|
data, _status_code, _headers = retrieve_orders_with_http_info(opts)
|
309
309
|
data
|
310
310
|
end
|
311
311
|
|
312
312
|
# Retrieves a list of orders
|
313
|
-
# Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
|
313
|
+
# Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
|
314
314
|
# @param [Hash] opts the optional parameters
|
315
|
-
# @option opts [Integer] :page
|
316
|
-
# @option opts [String] :metadata
|
317
|
-
# @option opts [String] :metadata_example1
|
318
|
-
# @option opts [String] :metadata_example2
|
315
|
+
# @option opts [Integer] :page
|
316
|
+
# @option opts [String] :metadata
|
317
|
+
# @option opts [String] :metadata_example1
|
318
|
+
# @option opts [String] :metadata_example2
|
319
319
|
# @return [Array<(OrderListResponse, Integer, Hash)>] OrderListResponse data, response status code and response headers
|
320
320
|
def retrieve_orders_with_http_info(opts = {})
|
321
321
|
if @api_client.config.debugging
|
@@ -37,7 +37,7 @@ module Patch
|
|
37
37
|
end
|
38
38
|
|
39
39
|
# Retrieves a project
|
40
|
-
# Retrieves a project available on Patch
|
40
|
+
# Retrieves a project available on Patch's platform.
|
41
41
|
# @param id [String]
|
42
42
|
# @param [Hash] opts the optional parameters
|
43
43
|
# @option opts [String] :accept_language
|
@@ -107,7 +107,7 @@ module Patch
|
|
107
107
|
end
|
108
108
|
|
109
109
|
# Retrieves a list of projects
|
110
|
-
# Retrieves a list of projects available for purchase on Patch
|
110
|
+
# Retrieves a list of projects available for purchase on Patch's platform.
|
111
111
|
# @param [Hash] opts the optional parameters
|
112
112
|
# @option opts [Integer] :page
|
113
113
|
# @option opts [String] :country
|
@@ -31,7 +31,7 @@ module Patch
|
|
31
31
|
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
32
32
|
def initialize(config = Configuration.default)
|
33
33
|
@config = config
|
34
|
-
@user_agent = "patch-ruby/1.
|
34
|
+
@user_agent = "patch-ruby/1.24.2"
|
35
35
|
@default_headers = {
|
36
36
|
'Content-Type' => 'application/json',
|
37
37
|
'User-Agent' => @user_agent
|
@@ -0,0 +1,374 @@
|
|
1
|
+
=begin
|
2
|
+
#Patch API V1
|
3
|
+
|
4
|
+
#The core API used to integrate with Patch's service
|
5
|
+
|
6
|
+
The version of the OpenAPI document: v1
|
7
|
+
Contact: engineering@usepatch.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 5.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'time'
|
15
|
+
|
16
|
+
module Patch
|
17
|
+
class CreateAirShippingEstimateRequest
|
18
|
+
attr_accessor :destination_airport
|
19
|
+
|
20
|
+
attr_accessor :origin_airport
|
21
|
+
|
22
|
+
attr_accessor :aircraft_code
|
23
|
+
|
24
|
+
attr_accessor :aircraft_type
|
25
|
+
|
26
|
+
attr_accessor :freight_mass_g
|
27
|
+
|
28
|
+
attr_accessor :emissions_scope
|
29
|
+
|
30
|
+
attr_accessor :project_id
|
31
|
+
|
32
|
+
attr_accessor :create_order
|
33
|
+
|
34
|
+
class EnumAttributeValidator
|
35
|
+
attr_reader :datatype
|
36
|
+
attr_reader :allowable_values
|
37
|
+
|
38
|
+
def initialize(datatype, allowable_values)
|
39
|
+
@allowable_values = allowable_values.map do |value|
|
40
|
+
case datatype.to_s
|
41
|
+
when /Integer/i
|
42
|
+
value.to_i
|
43
|
+
when /Float/i
|
44
|
+
value.to_f
|
45
|
+
else
|
46
|
+
value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def valid?(value)
|
52
|
+
!value || allowable_values.include?(value)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
57
|
+
def self.attribute_map
|
58
|
+
{
|
59
|
+
:'destination_airport' => :'destination_airport',
|
60
|
+
:'origin_airport' => :'origin_airport',
|
61
|
+
:'aircraft_code' => :'aircraft_code',
|
62
|
+
:'aircraft_type' => :'aircraft_type',
|
63
|
+
:'freight_mass_g' => :'freight_mass_g',
|
64
|
+
:'emissions_scope' => :'emissions_scope',
|
65
|
+
:'project_id' => :'project_id',
|
66
|
+
:'create_order' => :'create_order'
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns all the JSON keys this model knows about
|
71
|
+
def self.acceptable_attributes
|
72
|
+
attribute_map.values
|
73
|
+
end
|
74
|
+
|
75
|
+
# Attribute type mapping.
|
76
|
+
def self.openapi_types
|
77
|
+
{
|
78
|
+
:'destination_airport' => :'String',
|
79
|
+
:'origin_airport' => :'String',
|
80
|
+
:'aircraft_code' => :'String',
|
81
|
+
:'aircraft_type' => :'String',
|
82
|
+
:'freight_mass_g' => :'Integer',
|
83
|
+
:'emissions_scope' => :'String',
|
84
|
+
:'project_id' => :'String',
|
85
|
+
:'create_order' => :'Boolean'
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
# List of attributes with nullable: true
|
90
|
+
def self.openapi_nullable
|
91
|
+
Set.new([
|
92
|
+
:'destination_airport',
|
93
|
+
:'origin_airport',
|
94
|
+
:'aircraft_code',
|
95
|
+
:'aircraft_type',
|
96
|
+
:'emissions_scope',
|
97
|
+
:'project_id',
|
98
|
+
:'create_order'
|
99
|
+
])
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
# Allows models with corresponding API classes to delegate API operations to those API classes
|
104
|
+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
|
105
|
+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
|
106
|
+
def self.method_missing(message, *args, &block)
|
107
|
+
if Object.const_defined?('Patch::CreateAirShippingEstimateRequestsApi::OPERATIONS') && Patch::CreateAirShippingEstimateRequestsApi::OPERATIONS.include?(message)
|
108
|
+
Patch::CreateAirShippingEstimateRequestsApi.new.send(message, *args)
|
109
|
+
else
|
110
|
+
super
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Initializes the object
|
115
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
116
|
+
def initialize(attributes = {})
|
117
|
+
if (!attributes.is_a?(Hash))
|
118
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::CreateAirShippingEstimateRequest` initialize method"
|
119
|
+
end
|
120
|
+
|
121
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
122
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
123
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
124
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::CreateAirShippingEstimateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
125
|
+
end
|
126
|
+
h[k.to_sym] = v
|
127
|
+
}
|
128
|
+
|
129
|
+
if attributes.key?(:'destination_airport')
|
130
|
+
self.destination_airport = attributes[:'destination_airport']
|
131
|
+
end
|
132
|
+
|
133
|
+
if attributes.key?(:'origin_airport')
|
134
|
+
self.origin_airport = attributes[:'origin_airport']
|
135
|
+
end
|
136
|
+
|
137
|
+
if attributes.key?(:'aircraft_code')
|
138
|
+
self.aircraft_code = attributes[:'aircraft_code']
|
139
|
+
end
|
140
|
+
|
141
|
+
if attributes.key?(:'aircraft_type')
|
142
|
+
self.aircraft_type = attributes[:'aircraft_type']
|
143
|
+
else
|
144
|
+
self.aircraft_type = 'unknown'
|
145
|
+
end
|
146
|
+
|
147
|
+
if attributes.key?(:'freight_mass_g')
|
148
|
+
self.freight_mass_g = attributes[:'freight_mass_g']
|
149
|
+
end
|
150
|
+
|
151
|
+
if attributes.key?(:'emissions_scope')
|
152
|
+
self.emissions_scope = attributes[:'emissions_scope']
|
153
|
+
else
|
154
|
+
self.emissions_scope = 'ttw'
|
155
|
+
end
|
156
|
+
|
157
|
+
if attributes.key?(:'project_id')
|
158
|
+
self.project_id = attributes[:'project_id']
|
159
|
+
end
|
160
|
+
|
161
|
+
if attributes.key?(:'create_order')
|
162
|
+
self.create_order = attributes[:'create_order']
|
163
|
+
else
|
164
|
+
self.create_order = false
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
169
|
+
# @return Array for valid properties with the reasons
|
170
|
+
def list_invalid_properties
|
171
|
+
invalid_properties = Array.new
|
172
|
+
if !@freight_mass_g.nil? && @freight_mass_g > 2000000000
|
173
|
+
invalid_properties.push('invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.')
|
174
|
+
end
|
175
|
+
|
176
|
+
if !@freight_mass_g.nil? && @freight_mass_g < 0
|
177
|
+
invalid_properties.push('invalid value for "freight_mass_g", must be greater than or equal to 0.')
|
178
|
+
end
|
179
|
+
|
180
|
+
invalid_properties
|
181
|
+
end
|
182
|
+
|
183
|
+
# Check to see if the all the properties in the model are valid
|
184
|
+
# @return true if the model is valid
|
185
|
+
def valid?
|
186
|
+
aircraft_type_validator = EnumAttributeValidator.new('String', ["passenger", "cargo", "unknown"])
|
187
|
+
return false unless aircraft_type_validator.valid?(@aircraft_type)
|
188
|
+
return false if !@freight_mass_g.nil? && @freight_mass_g > 2000000000
|
189
|
+
return false if !@freight_mass_g.nil? && @freight_mass_g < 0
|
190
|
+
emissions_scope_validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"])
|
191
|
+
return false unless emissions_scope_validator.valid?(@emissions_scope)
|
192
|
+
true
|
193
|
+
end
|
194
|
+
|
195
|
+
# Custom attribute writer method checking allowed values (enum).
|
196
|
+
# @param [Object] aircraft_type Object to be assigned
|
197
|
+
def aircraft_type=(aircraft_type)
|
198
|
+
validator = EnumAttributeValidator.new('String', ["passenger", "cargo", "unknown"])
|
199
|
+
unless validator.valid?(aircraft_type)
|
200
|
+
fail ArgumentError, "invalid value for \"aircraft_type\", must be one of #{validator.allowable_values}."
|
201
|
+
end
|
202
|
+
@aircraft_type = aircraft_type
|
203
|
+
end
|
204
|
+
|
205
|
+
# Custom attribute writer method with validation
|
206
|
+
# @param [Object] freight_mass_g Value to be assigned
|
207
|
+
def freight_mass_g=(freight_mass_g)
|
208
|
+
if !freight_mass_g.nil? && freight_mass_g > 2000000000
|
209
|
+
fail ArgumentError, 'invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.'
|
210
|
+
end
|
211
|
+
|
212
|
+
if !freight_mass_g.nil? && freight_mass_g < 0
|
213
|
+
fail ArgumentError, 'invalid value for "freight_mass_g", must be greater than or equal to 0.'
|
214
|
+
end
|
215
|
+
|
216
|
+
@freight_mass_g = freight_mass_g
|
217
|
+
end
|
218
|
+
|
219
|
+
# Custom attribute writer method checking allowed values (enum).
|
220
|
+
# @param [Object] emissions_scope Object to be assigned
|
221
|
+
def emissions_scope=(emissions_scope)
|
222
|
+
validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"])
|
223
|
+
unless validator.valid?(emissions_scope)
|
224
|
+
fail ArgumentError, "invalid value for \"emissions_scope\", must be one of #{validator.allowable_values}."
|
225
|
+
end
|
226
|
+
@emissions_scope = emissions_scope
|
227
|
+
end
|
228
|
+
|
229
|
+
# Checks equality by comparing each attribute.
|
230
|
+
# @param [Object] Object to be compared
|
231
|
+
def ==(o)
|
232
|
+
return true if self.equal?(o)
|
233
|
+
self.class == o.class &&
|
234
|
+
destination_airport == o.destination_airport &&
|
235
|
+
origin_airport == o.origin_airport &&
|
236
|
+
aircraft_code == o.aircraft_code &&
|
237
|
+
aircraft_type == o.aircraft_type &&
|
238
|
+
freight_mass_g == o.freight_mass_g &&
|
239
|
+
emissions_scope == o.emissions_scope &&
|
240
|
+
project_id == o.project_id &&
|
241
|
+
create_order == o.create_order
|
242
|
+
end
|
243
|
+
|
244
|
+
# @see the `==` method
|
245
|
+
# @param [Object] Object to be compared
|
246
|
+
def eql?(o)
|
247
|
+
self == o
|
248
|
+
end
|
249
|
+
|
250
|
+
# Calculates hash code according to all attributes.
|
251
|
+
# @return [Integer] Hash code
|
252
|
+
def hash
|
253
|
+
[destination_airport, origin_airport, aircraft_code, aircraft_type, freight_mass_g, emissions_scope, project_id, create_order].hash
|
254
|
+
end
|
255
|
+
|
256
|
+
# Builds the object from hash
|
257
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
258
|
+
# @return [Object] Returns the model itself
|
259
|
+
def self.build_from_hash(attributes)
|
260
|
+
new.build_from_hash(attributes)
|
261
|
+
end
|
262
|
+
|
263
|
+
# Builds the object from hash
|
264
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
265
|
+
# @return [Object] Returns the model itself
|
266
|
+
def build_from_hash(attributes)
|
267
|
+
return nil unless attributes.is_a?(Hash)
|
268
|
+
self.class.openapi_types.each_pair do |key, type|
|
269
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
270
|
+
self.send("#{key}=", nil)
|
271
|
+
elsif type =~ /\AArray<(.*)>/i
|
272
|
+
# check to ensure the input is an array given that the attribute
|
273
|
+
# is documented as an array but the input is not
|
274
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
275
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
276
|
+
end
|
277
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
278
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
self
|
283
|
+
end
|
284
|
+
|
285
|
+
# Deserializes the data based on type
|
286
|
+
# @param string type Data type
|
287
|
+
# @param string value Value to be deserialized
|
288
|
+
# @return [Object] Deserialized data
|
289
|
+
def _deserialize(type, value)
|
290
|
+
case type.to_sym
|
291
|
+
when :Time
|
292
|
+
Time.parse(value)
|
293
|
+
when :Date
|
294
|
+
Date.parse(value)
|
295
|
+
when :String
|
296
|
+
value.to_s
|
297
|
+
when :Integer
|
298
|
+
value.to_i
|
299
|
+
when :Float
|
300
|
+
value.to_f
|
301
|
+
when :Boolean
|
302
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
303
|
+
true
|
304
|
+
else
|
305
|
+
false
|
306
|
+
end
|
307
|
+
when :Object
|
308
|
+
# generic object (usually a Hash), return directly
|
309
|
+
value
|
310
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
311
|
+
inner_type = Regexp.last_match[:inner_type]
|
312
|
+
value.map { |v| _deserialize(inner_type, v) }
|
313
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
314
|
+
k_type = Regexp.last_match[:k_type]
|
315
|
+
v_type = Regexp.last_match[:v_type]
|
316
|
+
{}.tap do |hash|
|
317
|
+
value.each do |k, v|
|
318
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
else # model
|
322
|
+
# models (e.g. Pet) or oneOf
|
323
|
+
klass = Patch.const_get(type)
|
324
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
# Returns the string representation of the object
|
329
|
+
# @return [String] String presentation of the object
|
330
|
+
def to_s
|
331
|
+
to_hash.to_s
|
332
|
+
end
|
333
|
+
|
334
|
+
# to_body is an alias to to_hash (backward compatibility)
|
335
|
+
# @return [Hash] Returns the object in the form of hash
|
336
|
+
def to_body
|
337
|
+
to_hash
|
338
|
+
end
|
339
|
+
|
340
|
+
# Returns the object in the form of hash
|
341
|
+
# @return [Hash] Returns the object in the form of hash
|
342
|
+
def to_hash
|
343
|
+
hash = {}
|
344
|
+
self.class.attribute_map.each_pair do |attr, param|
|
345
|
+
value = self.send(attr)
|
346
|
+
if value.nil?
|
347
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
348
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
349
|
+
end
|
350
|
+
|
351
|
+
hash[param] = _to_hash(value)
|
352
|
+
end
|
353
|
+
hash
|
354
|
+
end
|
355
|
+
|
356
|
+
# Outputs non-array value in the form of hash
|
357
|
+
# For object, use to_hash. Otherwise, just return the value
|
358
|
+
# @param [Object] value Any valid value
|
359
|
+
# @return [Hash] Returns the value in the form of hash
|
360
|
+
def _to_hash(value)
|
361
|
+
if value.is_a?(Array)
|
362
|
+
value.compact.map { |v| _to_hash(v) }
|
363
|
+
elsif value.is_a?(Hash)
|
364
|
+
{}.tap do |hash|
|
365
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
366
|
+
end
|
367
|
+
elsif value.respond_to? :to_hash
|
368
|
+
value.to_hash
|
369
|
+
else
|
370
|
+
value
|
371
|
+
end
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|