patch_ruby 1.24.1 → 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 +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -11
- data/lib/patch_ruby/api/estimates_api.rb +70 -0
- data/lib/patch_ruby/api_client.rb +1 -1
- data/lib/patch_ruby/models/create_air_shipping_estimate_request.rb +1 -1
- data/lib/patch_ruby/models/create_ecommerce_estimate_request.rb +373 -0
- data/lib/patch_ruby/models/create_rail_shipping_estimate_request.rb +1 -1
- data/lib/patch_ruby/models/create_road_shipping_estimate_request.rb +1 -1
- data/lib/patch_ruby/models/create_sea_shipping_estimate_request.rb +1 -1
- data/lib/patch_ruby/version.rb +1 -1
- data/lib/patch_ruby.rb +1 -0
- data/spec/integration/estimates_spec.rb +29 -16
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b23fba84f1274a67e893894072fecdbce7dca1d06032e8e633a6a41aad29c1ef
|
4
|
+
data.tar.gz: 19b0e1d44b7e07b1b8a01c2eb7167e79a4bdaabc2ed6fce1a4494e1ea509a981
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2acf29fa87be15b021490c6bea19c8342f870636dff4ef5afd95b6be64e7885f6ee19e8aea490f50c40e4f09e2dea0706f272f207e4219ecc891ea4ca7c42c49
|
7
|
+
data.tar.gz: '079afc3add925e55cc64f9752e6f0ebf871ee6b8e7cd94c39b0c4e07eafc5a507c72b3b6bfaa4166eb3fcbc1a389317b26ea9538cfe676c0a1be9d96ae8871f3'
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [1.24.2] - 2022-08-10
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Adds `Patch::Estimate.create_ecommerce_estimate` method
|
13
|
+
|
8
14
|
## [1.24.0] - 2022-07-22
|
9
15
|
|
10
16
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -127,16 +127,6 @@ Patch::Estimate.create_mass_estimate(mass_g: mass)
|
|
127
127
|
distance_m = 1_000_000 # Pass in the distance traveled in meters
|
128
128
|
Patch::Estimate.create_flight_estimate(distance_m: distance_m)
|
129
129
|
|
130
|
-
# Create a shipping estimate
|
131
|
-
distance_m = 1_000_000 # Pass in the shipping distance in meters
|
132
|
-
package_mass_g = 10_000 # Pass in the weight of the package shipped in grams
|
133
|
-
transportation_method = "air" # Pass in the transportation method (air, rail, road, sea)
|
134
|
-
Patch::Estimate.create_shipping_estimate(
|
135
|
-
distance_m: distance_m,
|
136
|
-
package_mass_g: package_mass_g,
|
137
|
-
transportation_method: transportation_method
|
138
|
-
)
|
139
|
-
|
140
130
|
# Create a vehicle estimate
|
141
131
|
distance_m = 1_000_000 # Pass in the shipping distance in meters
|
142
132
|
make = "Toyota" # Pass in the car make
|
@@ -149,10 +139,20 @@ Patch::Estimate.create_vehicle_estimate(
|
|
149
139
|
year: year
|
150
140
|
)
|
151
141
|
|
152
|
-
# Create a
|
142
|
+
# Create a Bitcoin estimate
|
153
143
|
transaction_value_btc_sats = 1000; # [Optional] Pass in the transaction value in satoshis
|
154
144
|
Patch::Estimate.create_bitcoin_estimate(transaction_value_btc_sats: transaction_value_btc_sats)
|
155
145
|
|
146
|
+
# Create an ecommerce estimate
|
147
|
+
distance_m = 1_000_000 # Pass in the shipping distance in meters
|
148
|
+
package_mass_g = 10_000 # Pass in the weight of the package shipped in grams
|
149
|
+
transportation_method = "air" # Pass in the transportation method (air, rail, road, sea)
|
150
|
+
Patch::Estimate.create_ecommerce_estimate(
|
151
|
+
distance_m: distance_m,
|
152
|
+
package_mass_g: package_mass_g,
|
153
|
+
transportation_method: transportation_method
|
154
|
+
)
|
155
|
+
|
156
156
|
## You can also specify a project-id field (optional) to be used instead of the preferred one
|
157
157
|
project_id = 'pro_test_1234' # Pass in the project's ID
|
158
158
|
Patch::Estimate.create_mass_estimate(mass_g: mass, project_id: project_id)
|
@@ -17,6 +17,7 @@ module Patch
|
|
17
17
|
OPERATIONS = [
|
18
18
|
:create_air_shipping_estimate,
|
19
19
|
:create_bitcoin_estimate,
|
20
|
+
:create_ecommerce_estimate,
|
20
21
|
:create_ethereum_estimate,
|
21
22
|
:create_flight_estimate,
|
22
23
|
:create_hotel_estimate,
|
@@ -173,6 +174,75 @@ module Patch
|
|
173
174
|
return data, status_code, headers
|
174
175
|
end
|
175
176
|
|
177
|
+
# Create an e-commerce estimate given the distance traveled in meters, package weight, and transportation method.
|
178
|
+
# Creates a e-commerce estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters.
|
179
|
+
# @param create_ecommerce_estimate_request [CreateEcommerceEstimateRequest]
|
180
|
+
# @param [Hash] opts the optional parameters
|
181
|
+
# @return [EstimateResponse]
|
182
|
+
def create_ecommerce_estimate(create_ecommerce_estimate_request = {}, opts = {})
|
183
|
+
_create_ecommerce_estimate_request = Patch::CreateEcommerceEstimateRequest.new(create_ecommerce_estimate_request)
|
184
|
+
data, _status_code, _headers = create_ecommerce_estimate_with_http_info(_create_ecommerce_estimate_request, opts)
|
185
|
+
data
|
186
|
+
end
|
187
|
+
|
188
|
+
# Create an e-commerce estimate given the distance traveled in meters, package weight, and transportation method.
|
189
|
+
# Creates a e-commerce estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters.
|
190
|
+
# @param create_ecommerce_estimate_request [CreateEcommerceEstimateRequest]
|
191
|
+
# @param [Hash] opts the optional parameters
|
192
|
+
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
|
193
|
+
def create_ecommerce_estimate_with_http_info(create_ecommerce_estimate_request, opts = {})
|
194
|
+
if @api_client.config.debugging
|
195
|
+
@api_client.config.logger.debug 'Calling API: EstimatesApi.create_ecommerce_estimate ...'
|
196
|
+
end
|
197
|
+
# verify the required parameter 'create_ecommerce_estimate_request' is set
|
198
|
+
if @api_client.config.client_side_validation && create_ecommerce_estimate_request.nil?
|
199
|
+
fail ArgumentError, "Missing the required parameter 'create_ecommerce_estimate_request' when calling EstimatesApi.create_ecommerce_estimate"
|
200
|
+
end
|
201
|
+
# resource path
|
202
|
+
local_var_path = '/v1/estimates/ecommerce'
|
203
|
+
|
204
|
+
# query parameters
|
205
|
+
query_params = opts[:query_params] || {}
|
206
|
+
|
207
|
+
# header parameters
|
208
|
+
header_params = opts[:header_params] || {}
|
209
|
+
# HTTP header 'Accept' (if needed)
|
210
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
211
|
+
# HTTP header 'Content-Type'
|
212
|
+
content_type = @api_client.select_header_content_type(['application/json'])
|
213
|
+
if !content_type.nil?
|
214
|
+
header_params['Content-Type'] = content_type
|
215
|
+
end
|
216
|
+
|
217
|
+
# form parameters
|
218
|
+
form_params = opts[:form_params] || {}
|
219
|
+
|
220
|
+
# http body (model)
|
221
|
+
post_body = opts[:debug_body] || @api_client.object_to_http_body(create_ecommerce_estimate_request)
|
222
|
+
|
223
|
+
# return_type
|
224
|
+
return_type = opts[:debug_return_type] || 'EstimateResponse'
|
225
|
+
|
226
|
+
# auth_names
|
227
|
+
auth_names = opts[:debug_auth_names] || ['bearer_auth']
|
228
|
+
|
229
|
+
new_options = opts.merge(
|
230
|
+
:operation => :"EstimatesApi.create_ecommerce_estimate",
|
231
|
+
:header_params => header_params,
|
232
|
+
:query_params => query_params,
|
233
|
+
:form_params => form_params,
|
234
|
+
:body => post_body,
|
235
|
+
:auth_names => auth_names,
|
236
|
+
:return_type => return_type
|
237
|
+
)
|
238
|
+
|
239
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
240
|
+
if @api_client.config.debugging
|
241
|
+
@api_client.config.logger.debug "API called: EstimatesApi#create_ecommerce_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
242
|
+
end
|
243
|
+
return data, status_code, headers
|
244
|
+
end
|
245
|
+
|
176
246
|
# Create an ethereum estimate
|
177
247
|
# Creates an ethereum estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate.
|
178
248
|
# @param create_ethereum_estimate_request [CreateEthereumEstimateRequest]
|
@@ -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.24.
|
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,373 @@
|
|
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 CreateEcommerceEstimateRequest
|
18
|
+
attr_accessor :distance_m
|
19
|
+
|
20
|
+
attr_accessor :package_mass_g
|
21
|
+
|
22
|
+
attr_accessor :transportation_method
|
23
|
+
|
24
|
+
attr_accessor :project_id
|
25
|
+
|
26
|
+
attr_accessor :create_order
|
27
|
+
|
28
|
+
class EnumAttributeValidator
|
29
|
+
attr_reader :datatype
|
30
|
+
attr_reader :allowable_values
|
31
|
+
|
32
|
+
def initialize(datatype, allowable_values)
|
33
|
+
@allowable_values = allowable_values.map do |value|
|
34
|
+
case datatype.to_s
|
35
|
+
when /Integer/i
|
36
|
+
value.to_i
|
37
|
+
when /Float/i
|
38
|
+
value.to_f
|
39
|
+
else
|
40
|
+
value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def valid?(value)
|
46
|
+
!value || allowable_values.include?(value)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
51
|
+
def self.attribute_map
|
52
|
+
{
|
53
|
+
:'distance_m' => :'distance_m',
|
54
|
+
:'package_mass_g' => :'package_mass_g',
|
55
|
+
:'transportation_method' => :'transportation_method',
|
56
|
+
:'project_id' => :'project_id',
|
57
|
+
:'create_order' => :'create_order'
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns all the JSON keys this model knows about
|
62
|
+
def self.acceptable_attributes
|
63
|
+
attribute_map.values
|
64
|
+
end
|
65
|
+
|
66
|
+
# Attribute type mapping.
|
67
|
+
def self.openapi_types
|
68
|
+
{
|
69
|
+
:'distance_m' => :'Integer',
|
70
|
+
:'package_mass_g' => :'Integer',
|
71
|
+
:'transportation_method' => :'String',
|
72
|
+
:'project_id' => :'String',
|
73
|
+
:'create_order' => :'Boolean'
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
# List of attributes with nullable: true
|
78
|
+
def self.openapi_nullable
|
79
|
+
Set.new([
|
80
|
+
:'project_id',
|
81
|
+
:'create_order'
|
82
|
+
])
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
# Allows models with corresponding API classes to delegate API operations to those API classes
|
87
|
+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
|
88
|
+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
|
89
|
+
def self.method_missing(message, *args, &block)
|
90
|
+
if Object.const_defined?('Patch::CreateEcommerceEstimateRequestsApi::OPERATIONS') && Patch::CreateEcommerceEstimateRequestsApi::OPERATIONS.include?(message)
|
91
|
+
Patch::CreateEcommerceEstimateRequestsApi.new.send(message, *args)
|
92
|
+
else
|
93
|
+
super
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Initializes the object
|
98
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
99
|
+
def initialize(attributes = {})
|
100
|
+
if (!attributes.is_a?(Hash))
|
101
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::CreateEcommerceEstimateRequest` initialize method"
|
102
|
+
end
|
103
|
+
|
104
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
105
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
106
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
107
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::CreateEcommerceEstimateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
108
|
+
end
|
109
|
+
h[k.to_sym] = v
|
110
|
+
}
|
111
|
+
|
112
|
+
if attributes.key?(:'distance_m')
|
113
|
+
self.distance_m = attributes[:'distance_m']
|
114
|
+
end
|
115
|
+
|
116
|
+
if attributes.key?(:'package_mass_g')
|
117
|
+
self.package_mass_g = attributes[:'package_mass_g']
|
118
|
+
end
|
119
|
+
|
120
|
+
if attributes.key?(:'transportation_method')
|
121
|
+
self.transportation_method = attributes[:'transportation_method']
|
122
|
+
end
|
123
|
+
|
124
|
+
if attributes.key?(:'project_id')
|
125
|
+
self.project_id = attributes[:'project_id']
|
126
|
+
end
|
127
|
+
|
128
|
+
if attributes.key?(:'create_order')
|
129
|
+
self.create_order = attributes[:'create_order']
|
130
|
+
else
|
131
|
+
self.create_order = false
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
136
|
+
# @return Array for valid properties with the reasons
|
137
|
+
def list_invalid_properties
|
138
|
+
invalid_properties = Array.new
|
139
|
+
if @distance_m.nil?
|
140
|
+
invalid_properties.push('invalid value for "distance_m", distance_m cannot be nil.')
|
141
|
+
end
|
142
|
+
|
143
|
+
if @distance_m > 400000000
|
144
|
+
invalid_properties.push('invalid value for "distance_m", must be smaller than or equal to 400000000.')
|
145
|
+
end
|
146
|
+
|
147
|
+
if @distance_m < 0
|
148
|
+
invalid_properties.push('invalid value for "distance_m", must be greater than or equal to 0.')
|
149
|
+
end
|
150
|
+
|
151
|
+
if @package_mass_g.nil?
|
152
|
+
invalid_properties.push('invalid value for "package_mass_g", package_mass_g cannot be nil.')
|
153
|
+
end
|
154
|
+
|
155
|
+
if @package_mass_g > 2000000000
|
156
|
+
invalid_properties.push('invalid value for "package_mass_g", must be smaller than or equal to 2000000000.')
|
157
|
+
end
|
158
|
+
|
159
|
+
if @package_mass_g < 0
|
160
|
+
invalid_properties.push('invalid value for "package_mass_g", must be greater than or equal to 0.')
|
161
|
+
end
|
162
|
+
|
163
|
+
if @transportation_method.nil?
|
164
|
+
invalid_properties.push('invalid value for "transportation_method", transportation_method cannot be nil.')
|
165
|
+
end
|
166
|
+
|
167
|
+
invalid_properties
|
168
|
+
end
|
169
|
+
|
170
|
+
# Check to see if the all the properties in the model are valid
|
171
|
+
# @return true if the model is valid
|
172
|
+
def valid?
|
173
|
+
return false if @distance_m.nil?
|
174
|
+
return false if @distance_m > 400000000
|
175
|
+
return false if @distance_m < 0
|
176
|
+
return false if @package_mass_g.nil?
|
177
|
+
return false if @package_mass_g > 2000000000
|
178
|
+
return false if @package_mass_g < 0
|
179
|
+
return false if @transportation_method.nil?
|
180
|
+
transportation_method_validator = EnumAttributeValidator.new('String', ["air", "rail", "road", "sea"])
|
181
|
+
return false unless transportation_method_validator.valid?(@transportation_method)
|
182
|
+
true
|
183
|
+
end
|
184
|
+
|
185
|
+
# Custom attribute writer method with validation
|
186
|
+
# @param [Object] distance_m Value to be assigned
|
187
|
+
def distance_m=(distance_m)
|
188
|
+
if distance_m.nil?
|
189
|
+
fail ArgumentError, 'distance_m cannot be nil'
|
190
|
+
end
|
191
|
+
|
192
|
+
if distance_m > 400000000
|
193
|
+
fail ArgumentError, 'invalid value for "distance_m", must be smaller than or equal to 400000000.'
|
194
|
+
end
|
195
|
+
|
196
|
+
if distance_m < 0
|
197
|
+
fail ArgumentError, 'invalid value for "distance_m", must be greater than or equal to 0.'
|
198
|
+
end
|
199
|
+
|
200
|
+
@distance_m = distance_m
|
201
|
+
end
|
202
|
+
|
203
|
+
# Custom attribute writer method with validation
|
204
|
+
# @param [Object] package_mass_g Value to be assigned
|
205
|
+
def package_mass_g=(package_mass_g)
|
206
|
+
if package_mass_g.nil?
|
207
|
+
fail ArgumentError, 'package_mass_g cannot be nil'
|
208
|
+
end
|
209
|
+
|
210
|
+
if package_mass_g > 2000000000
|
211
|
+
fail ArgumentError, 'invalid value for "package_mass_g", must be smaller than or equal to 2000000000.'
|
212
|
+
end
|
213
|
+
|
214
|
+
if package_mass_g < 0
|
215
|
+
fail ArgumentError, 'invalid value for "package_mass_g", must be greater than or equal to 0.'
|
216
|
+
end
|
217
|
+
|
218
|
+
@package_mass_g = package_mass_g
|
219
|
+
end
|
220
|
+
|
221
|
+
# Custom attribute writer method checking allowed values (enum).
|
222
|
+
# @param [Object] transportation_method Object to be assigned
|
223
|
+
def transportation_method=(transportation_method)
|
224
|
+
validator = EnumAttributeValidator.new('String', ["air", "rail", "road", "sea"])
|
225
|
+
unless validator.valid?(transportation_method)
|
226
|
+
fail ArgumentError, "invalid value for \"transportation_method\", must be one of #{validator.allowable_values}."
|
227
|
+
end
|
228
|
+
@transportation_method = transportation_method
|
229
|
+
end
|
230
|
+
|
231
|
+
# Checks equality by comparing each attribute.
|
232
|
+
# @param [Object] Object to be compared
|
233
|
+
def ==(o)
|
234
|
+
return true if self.equal?(o)
|
235
|
+
self.class == o.class &&
|
236
|
+
distance_m == o.distance_m &&
|
237
|
+
package_mass_g == o.package_mass_g &&
|
238
|
+
transportation_method == o.transportation_method &&
|
239
|
+
project_id == o.project_id &&
|
240
|
+
create_order == o.create_order
|
241
|
+
end
|
242
|
+
|
243
|
+
# @see the `==` method
|
244
|
+
# @param [Object] Object to be compared
|
245
|
+
def eql?(o)
|
246
|
+
self == o
|
247
|
+
end
|
248
|
+
|
249
|
+
# Calculates hash code according to all attributes.
|
250
|
+
# @return [Integer] Hash code
|
251
|
+
def hash
|
252
|
+
[distance_m, package_mass_g, transportation_method, project_id, create_order].hash
|
253
|
+
end
|
254
|
+
|
255
|
+
# Builds the object from hash
|
256
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
257
|
+
# @return [Object] Returns the model itself
|
258
|
+
def self.build_from_hash(attributes)
|
259
|
+
new.build_from_hash(attributes)
|
260
|
+
end
|
261
|
+
|
262
|
+
# Builds the object from hash
|
263
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
264
|
+
# @return [Object] Returns the model itself
|
265
|
+
def build_from_hash(attributes)
|
266
|
+
return nil unless attributes.is_a?(Hash)
|
267
|
+
self.class.openapi_types.each_pair do |key, type|
|
268
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
269
|
+
self.send("#{key}=", nil)
|
270
|
+
elsif type =~ /\AArray<(.*)>/i
|
271
|
+
# check to ensure the input is an array given that the attribute
|
272
|
+
# is documented as an array but the input is not
|
273
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
274
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
275
|
+
end
|
276
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
277
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
self
|
282
|
+
end
|
283
|
+
|
284
|
+
# Deserializes the data based on type
|
285
|
+
# @param string type Data type
|
286
|
+
# @param string value Value to be deserialized
|
287
|
+
# @return [Object] Deserialized data
|
288
|
+
def _deserialize(type, value)
|
289
|
+
case type.to_sym
|
290
|
+
when :Time
|
291
|
+
Time.parse(value)
|
292
|
+
when :Date
|
293
|
+
Date.parse(value)
|
294
|
+
when :String
|
295
|
+
value.to_s
|
296
|
+
when :Integer
|
297
|
+
value.to_i
|
298
|
+
when :Float
|
299
|
+
value.to_f
|
300
|
+
when :Boolean
|
301
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
302
|
+
true
|
303
|
+
else
|
304
|
+
false
|
305
|
+
end
|
306
|
+
when :Object
|
307
|
+
# generic object (usually a Hash), return directly
|
308
|
+
value
|
309
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
310
|
+
inner_type = Regexp.last_match[:inner_type]
|
311
|
+
value.map { |v| _deserialize(inner_type, v) }
|
312
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
313
|
+
k_type = Regexp.last_match[:k_type]
|
314
|
+
v_type = Regexp.last_match[:v_type]
|
315
|
+
{}.tap do |hash|
|
316
|
+
value.each do |k, v|
|
317
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
else # model
|
321
|
+
# models (e.g. Pet) or oneOf
|
322
|
+
klass = Patch.const_get(type)
|
323
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
# Returns the string representation of the object
|
328
|
+
# @return [String] String presentation of the object
|
329
|
+
def to_s
|
330
|
+
to_hash.to_s
|
331
|
+
end
|
332
|
+
|
333
|
+
# to_body is an alias to to_hash (backward compatibility)
|
334
|
+
# @return [Hash] Returns the object in the form of hash
|
335
|
+
def to_body
|
336
|
+
to_hash
|
337
|
+
end
|
338
|
+
|
339
|
+
# Returns the object in the form of hash
|
340
|
+
# @return [Hash] Returns the object in the form of hash
|
341
|
+
def to_hash
|
342
|
+
hash = {}
|
343
|
+
self.class.attribute_map.each_pair do |attr, param|
|
344
|
+
value = self.send(attr)
|
345
|
+
if value.nil?
|
346
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
347
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
348
|
+
end
|
349
|
+
|
350
|
+
hash[param] = _to_hash(value)
|
351
|
+
end
|
352
|
+
hash
|
353
|
+
end
|
354
|
+
|
355
|
+
# Outputs non-array value in the form of hash
|
356
|
+
# For object, use to_hash. Otherwise, just return the value
|
357
|
+
# @param [Object] value Any valid value
|
358
|
+
# @return [Hash] Returns the value in the form of hash
|
359
|
+
def _to_hash(value)
|
360
|
+
if value.is_a?(Array)
|
361
|
+
value.compact.map { |v| _to_hash(v) }
|
362
|
+
elsif value.is_a?(Hash)
|
363
|
+
{}.tap do |hash|
|
364
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
365
|
+
end
|
366
|
+
elsif value.respond_to? :to_hash
|
367
|
+
value.to_hash
|
368
|
+
else
|
369
|
+
value
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
end
|
data/lib/patch_ruby/version.rb
CHANGED
data/lib/patch_ruby.rb
CHANGED
@@ -20,6 +20,7 @@ require 'patch_ruby/configuration'
|
|
20
20
|
require 'patch_ruby/models/allocation'
|
21
21
|
require 'patch_ruby/models/create_air_shipping_estimate_request'
|
22
22
|
require 'patch_ruby/models/create_bitcoin_estimate_request'
|
23
|
+
require 'patch_ruby/models/create_ecommerce_estimate_request'
|
23
24
|
require 'patch_ruby/models/create_ethereum_estimate_request'
|
24
25
|
require 'patch_ruby/models/create_flight_estimate_request'
|
25
26
|
require 'patch_ruby/models/create_hotel_estimate_request'
|
@@ -90,7 +90,6 @@ RSpec.describe 'Estimates Integration' do
|
|
90
90
|
expect(create_estimate_response.data.mass_g).to be >= 10_000
|
91
91
|
end
|
92
92
|
|
93
|
-
|
94
93
|
it 'supports creating bitcoin estimates with partial information' do
|
95
94
|
bitcoin_estimate = Patch::Estimate.create_bitcoin_estimate()
|
96
95
|
|
@@ -172,6 +171,20 @@ RSpec.describe 'Estimates Integration' do
|
|
172
171
|
expect(create_estimate_response.data.id).not_to be_nil
|
173
172
|
end
|
174
173
|
|
174
|
+
it 'supports creating ecommerce estimates' do
|
175
|
+
distance_m = 100_000_000
|
176
|
+
package_mass_g = 10_000
|
177
|
+
create_estimate_response = Patch::Estimate.create_ecommerce_estimate(
|
178
|
+
distance_m: distance_m,
|
179
|
+
package_mass_g: package_mass_g,
|
180
|
+
transportation_method: 'rail',
|
181
|
+
create_order: false
|
182
|
+
)
|
183
|
+
|
184
|
+
expect(create_estimate_response.data.type).to eq 'ecommerce'
|
185
|
+
expect(create_estimate_response.data.mass_g).to be >= 10_000
|
186
|
+
end
|
187
|
+
|
175
188
|
context "when creating an air shipping estimate" do
|
176
189
|
it "supports creating an estimate using airports" do
|
177
190
|
air_shipping_estimate = Patch::Estimate.create_air_shipping_estimate(
|
@@ -182,7 +195,7 @@ RSpec.describe 'Estimates Integration' do
|
|
182
195
|
origin_airport: "SFO"
|
183
196
|
)
|
184
197
|
expect(air_shipping_estimate.data.type).to eq('shipping_air')
|
185
|
-
expect(air_shipping_estimate.data.mass_g).to be
|
198
|
+
expect(air_shipping_estimate.data.mass_g).to be > 0
|
186
199
|
end
|
187
200
|
|
188
201
|
it "supports creating an estimate with an order" do
|
@@ -194,8 +207,8 @@ RSpec.describe 'Estimates Integration' do
|
|
194
207
|
origin_airport: "SFO"
|
195
208
|
)
|
196
209
|
expect(air_shipping_estimate.data.type).to eq('shipping_air')
|
197
|
-
expect(air_shipping_estimate.data.mass_g).to be
|
198
|
-
expect(air_shipping_estimate.data.order.amount).to be
|
210
|
+
expect(air_shipping_estimate.data.mass_g).to be > 0
|
211
|
+
expect(air_shipping_estimate.data.order.amount).to be > 0
|
199
212
|
end
|
200
213
|
end
|
201
214
|
|
@@ -210,7 +223,7 @@ RSpec.describe 'Estimates Integration' do
|
|
210
223
|
origin_locode: "USSD2"
|
211
224
|
)
|
212
225
|
expect(rail_shipping_estimate.data.type).to eq('shipping_rail')
|
213
|
-
expect(rail_shipping_estimate.data.mass_g).to be
|
226
|
+
expect(rail_shipping_estimate.data.mass_g).to be > 0
|
214
227
|
end
|
215
228
|
|
216
229
|
it "supports creating an estimate using postal codes" do
|
@@ -225,7 +238,7 @@ RSpec.describe 'Estimates Integration' do
|
|
225
238
|
origin_postal_code: "90210"
|
226
239
|
)
|
227
240
|
expect(rail_shipping_estimate.data.type).to eq('shipping_rail')
|
228
|
-
expect(rail_shipping_estimate.data.mass_g).to be
|
241
|
+
expect(rail_shipping_estimate.data.mass_g).to be > 0
|
229
242
|
end
|
230
243
|
|
231
244
|
it "supports creating an estimate with an order" do
|
@@ -236,8 +249,8 @@ RSpec.describe 'Estimates Integration' do
|
|
236
249
|
origin_locode: "USSD2"
|
237
250
|
)
|
238
251
|
expect(rail_shipping_estimate.data.type).to eq('shipping_rail')
|
239
|
-
expect(rail_shipping_estimate.data.mass_g).to be
|
240
|
-
expect(rail_shipping_estimate.data.order.amount).to be
|
252
|
+
expect(rail_shipping_estimate.data.mass_g).to be > 0
|
253
|
+
expect(rail_shipping_estimate.data.order.amount).to be > 0
|
241
254
|
end
|
242
255
|
end
|
243
256
|
|
@@ -252,7 +265,7 @@ RSpec.describe 'Estimates Integration' do
|
|
252
265
|
origin_locode: "USSD2"
|
253
266
|
)
|
254
267
|
expect(road_shipping_estimate.data.type).to eq('shipping_road')
|
255
|
-
expect(road_shipping_estimate.data.mass_g).to be
|
268
|
+
expect(road_shipping_estimate.data.mass_g).to be > 0
|
256
269
|
end
|
257
270
|
|
258
271
|
it "supports creating an estimate using postal codes" do
|
@@ -266,7 +279,7 @@ RSpec.describe 'Estimates Integration' do
|
|
266
279
|
origin_postal_code: "90210"
|
267
280
|
)
|
268
281
|
expect(road_shipping_estimate.data.type).to eq('shipping_road')
|
269
|
-
expect(road_shipping_estimate.data.mass_g).to be
|
282
|
+
expect(road_shipping_estimate.data.mass_g).to be > 0
|
270
283
|
end
|
271
284
|
|
272
285
|
it "supports creating an estimate with an order" do
|
@@ -277,8 +290,8 @@ RSpec.describe 'Estimates Integration' do
|
|
277
290
|
origin_locode: "USSD2"
|
278
291
|
)
|
279
292
|
expect(road_shipping_estimate.data.type).to eq('shipping_road')
|
280
|
-
expect(road_shipping_estimate.data.mass_g).to be
|
281
|
-
expect(road_shipping_estimate.data.order.amount).to be
|
293
|
+
expect(road_shipping_estimate.data.mass_g).to be > 0
|
294
|
+
expect(road_shipping_estimate.data.order.amount).to be > 0
|
282
295
|
end
|
283
296
|
end
|
284
297
|
|
@@ -293,7 +306,7 @@ RSpec.describe 'Estimates Integration' do
|
|
293
306
|
origin_locode: "FRMRS"
|
294
307
|
)
|
295
308
|
expect(sea_shipping_estimate.data.type).to eq('shipping_sea')
|
296
|
-
expect(sea_shipping_estimate.data.mass_g).to be
|
309
|
+
expect(sea_shipping_estimate.data.mass_g).to be > 0
|
297
310
|
end
|
298
311
|
|
299
312
|
it "supports creating an estimate using postal codes" do
|
@@ -307,7 +320,7 @@ RSpec.describe 'Estimates Integration' do
|
|
307
320
|
origin_postal_code: "90210"
|
308
321
|
)
|
309
322
|
expect(sea_shipping_estimate.data.type).to eq('shipping_sea')
|
310
|
-
expect(sea_shipping_estimate.data.mass_g).to be
|
323
|
+
expect(sea_shipping_estimate.data.mass_g).to be > 0
|
311
324
|
end
|
312
325
|
|
313
326
|
it "supports creating an estimate with an order" do
|
@@ -318,8 +331,8 @@ RSpec.describe 'Estimates Integration' do
|
|
318
331
|
origin_locode: "USSD2"
|
319
332
|
)
|
320
333
|
expect(sea_shipping_estimate.data.type).to eq('shipping_sea')
|
321
|
-
expect(sea_shipping_estimate.data.mass_g).to be
|
322
|
-
expect(sea_shipping_estimate.data.order.amount).to be
|
334
|
+
expect(sea_shipping_estimate.data.mass_g).to be > 0
|
335
|
+
expect(sea_shipping_estimate.data.order.amount).to be > 0
|
323
336
|
end
|
324
337
|
end
|
325
338
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: patch_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.24.
|
4
|
+
version: 1.24.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patch Technology
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- lib/patch_ruby/models/allocation.rb
|
104
104
|
- lib/patch_ruby/models/create_air_shipping_estimate_request.rb
|
105
105
|
- lib/patch_ruby/models/create_bitcoin_estimate_request.rb
|
106
|
+
- lib/patch_ruby/models/create_ecommerce_estimate_request.rb
|
106
107
|
- lib/patch_ruby/models/create_ethereum_estimate_request.rb
|
107
108
|
- lib/patch_ruby/models/create_flight_estimate_request.rb
|
108
109
|
- lib/patch_ruby/models/create_hotel_estimate_request.rb
|