patch_ruby 1.5.2 → 1.9.0

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.
@@ -0,0 +1,264 @@
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: developers@usepatch.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module Patch
16
+ class CreateEthereumEstimateRequest
17
+ attr_accessor :timestamp
18
+
19
+ attr_accessor :gas_used
20
+
21
+ attr_accessor :transaction_value_eth_gwei
22
+
23
+ attr_accessor :project_id
24
+
25
+ attr_accessor :create_order
26
+
27
+ # Attribute mapping from ruby-style variable name to JSON key.
28
+ def self.attribute_map
29
+ {
30
+ :'timestamp' => :'timestamp',
31
+ :'gas_used' => :'gas_used',
32
+ :'transaction_value_eth_gwei' => :'transaction_value_eth_gwei',
33
+ :'project_id' => :'project_id',
34
+ :'create_order' => :'create_order'
35
+ }
36
+ end
37
+
38
+ # Attribute type mapping.
39
+ def self.openapi_types
40
+ {
41
+ :'timestamp' => :'String',
42
+ :'gas_used' => :'Integer',
43
+ :'transaction_value_eth_gwei' => :'Integer',
44
+ :'project_id' => :'String',
45
+ :'create_order' => :'Boolean'
46
+ }
47
+ end
48
+
49
+ # Set with nullable attributes.
50
+ def self.openapi_nullable
51
+ nullable_properties = Set.new
52
+
53
+ nullable_properties.add("timestamp")
54
+
55
+ nullable_properties.add("gas_used")
56
+
57
+ nullable_properties.add("transaction_value_eth_gwei")
58
+
59
+ nullable_properties.add("project_id")
60
+
61
+ nullable_properties.add("create_order")
62
+
63
+ nullable_properties
64
+ end
65
+
66
+ # Allows models with corresponding API classes to delegate API operations to those API classes
67
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
68
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
69
+ def self.method_missing(message, *args, &block)
70
+ if Object.const_defined?('Patch::CreateEthereumEstimateRequestsApi::OPERATIONS') && Patch::CreateEthereumEstimateRequestsApi::OPERATIONS.include?(message)
71
+ Patch::CreateEthereumEstimateRequestsApi.new.send(message, *args)
72
+ else
73
+ super
74
+ end
75
+ end
76
+
77
+ # Initializes the object
78
+ # @param [Hash] attributes Model attributes in the form of hash
79
+ def initialize(attributes = {})
80
+ if (!attributes.is_a?(Hash))
81
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::CreateEthereumEstimateRequest` initialize method"
82
+ end
83
+
84
+ # check to see if the attribute exists and convert string to symbol for hash key
85
+ attributes = attributes.each_with_object({}) { |(k, v), h|
86
+ if (!self.class.attribute_map.key?(k.to_sym))
87
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::CreateEthereumEstimateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
88
+ end
89
+ h[k.to_sym] = v
90
+ }
91
+
92
+ if attributes.key?(:'timestamp')
93
+ self.timestamp = attributes[:'timestamp']
94
+ end
95
+
96
+ if attributes.key?(:'gas_used')
97
+ self.gas_used = attributes[:'gas_used']
98
+ end
99
+
100
+ if attributes.key?(:'transaction_value_eth_gwei')
101
+ self.transaction_value_eth_gwei = attributes[:'transaction_value_eth_gwei']
102
+ end
103
+
104
+ if attributes.key?(:'project_id')
105
+ self.project_id = attributes[:'project_id']
106
+ end
107
+
108
+ if attributes.key?(:'create_order')
109
+ self.create_order = attributes[:'create_order']
110
+ end
111
+ end
112
+
113
+ # Show invalid properties with the reasons. Usually used together with valid?
114
+ # @return Array for valid properties with the reasons
115
+ def list_invalid_properties
116
+ invalid_properties = Array.new
117
+ invalid_properties
118
+ end
119
+
120
+ # Check to see if the all the properties in the model are valid
121
+ # @return true if the model is valid
122
+ def valid?
123
+ true
124
+ end
125
+
126
+ # Checks equality by comparing each attribute.
127
+ # @param [Object] Object to be compared
128
+ def ==(o)
129
+ return true if self.equal?(o)
130
+ self.class == o.class &&
131
+ timestamp == o.timestamp &&
132
+ gas_used == o.gas_used &&
133
+ transaction_value_eth_gwei == o.transaction_value_eth_gwei &&
134
+ project_id == o.project_id &&
135
+ create_order == o.create_order
136
+ end
137
+
138
+ # @see the `==` method
139
+ # @param [Object] Object to be compared
140
+ def eql?(o)
141
+ self == o
142
+ end
143
+
144
+ # Calculates hash code according to all attributes.
145
+ # @return [Integer] Hash code
146
+ def hash
147
+ [timestamp, gas_used, transaction_value_eth_gwei, project_id, create_order].hash
148
+ end
149
+
150
+ # Builds the object from hash
151
+ # @param [Hash] attributes Model attributes in the form of hash
152
+ # @return [Object] Returns the model itself
153
+ def self.build_from_hash(attributes)
154
+ new.build_from_hash(attributes)
155
+ end
156
+
157
+ # Builds the object from hash
158
+ # @param [Hash] attributes Model attributes in the form of hash
159
+ # @return [Object] Returns the model itself
160
+ def build_from_hash(attributes)
161
+ return nil unless attributes.is_a?(Hash)
162
+ self.class.openapi_types.each_pair do |key, type|
163
+ if type =~ /\AArray<(.*)>/i
164
+ # check to ensure the input is an array given that the attribute
165
+ # is documented as an array but the input is not
166
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
167
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
168
+ end
169
+ elsif !attributes[self.class.attribute_map[key]].nil?
170
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
171
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
172
+ end
173
+
174
+ self
175
+ end
176
+
177
+ # Deserializes the data based on type
178
+ # @param string type Data type
179
+ # @param string value Value to be deserialized
180
+ # @return [Object] Deserialized data
181
+ def _deserialize(type, value)
182
+ case type.to_sym
183
+ when :DateTime
184
+ DateTime.parse(value)
185
+ when :Date
186
+ Date.parse(value)
187
+ when :String
188
+ value.to_s
189
+ when :Integer
190
+ value.to_i
191
+ when :Float
192
+ value.to_f
193
+ when :Boolean
194
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
195
+ true
196
+ else
197
+ false
198
+ end
199
+ when :Object
200
+ # generic object (usually a Hash), return directly
201
+ value
202
+ when /\AArray<(?<inner_type>.+)>\z/
203
+ inner_type = Regexp.last_match[:inner_type]
204
+ value.map { |v| _deserialize(inner_type, v) }
205
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
206
+ k_type = Regexp.last_match[:k_type]
207
+ v_type = Regexp.last_match[:v_type]
208
+ {}.tap do |hash|
209
+ value.each do |k, v|
210
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
211
+ end
212
+ end
213
+ else # model
214
+ Patch.const_get(type).build_from_hash(value)
215
+ end
216
+ end
217
+
218
+ # Returns the string representation of the object
219
+ # @return [String] String presentation of the object
220
+ def to_s
221
+ to_hash.to_s
222
+ end
223
+
224
+ # to_body is an alias to to_hash (backward compatibility)
225
+ # @return [Hash] Returns the object in the form of hash
226
+ def to_body
227
+ to_hash
228
+ end
229
+
230
+ # Returns the object in the form of hash
231
+ # @return [Hash] Returns the object in the form of hash
232
+ def to_hash
233
+ hash = {}
234
+ self.class.attribute_map.each_pair do |attr, param|
235
+ value = self.send(attr)
236
+ if value.nil?
237
+ is_nullable = self.class.openapi_nullable.include?(attr)
238
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
239
+ end
240
+
241
+ hash[param] = _to_hash(value)
242
+ end
243
+ hash
244
+ end
245
+
246
+ # Outputs non-array value in the form of hash
247
+ # For object, use to_hash. Otherwise, just return the value
248
+ # @param [Object] value Any valid value
249
+ # @return [Hash] Returns the value in the form of hash
250
+ def _to_hash(value)
251
+ if value.is_a?(Array)
252
+ value.compact.map { |v| _to_hash(v) }
253
+ elsif value.is_a?(Hash)
254
+ {}.tap do |hash|
255
+ value.each { |k, v| hash[k] = _to_hash(v) }
256
+ end
257
+ elsif value.respond_to? :to_hash
258
+ value.to_hash
259
+ else
260
+ value
261
+ end
262
+ end
263
+ end
264
+ end
@@ -20,7 +20,7 @@ module Patch
20
20
  # A boolean indicating if this estimate is a production or test mode estimate.
21
21
  attr_accessor :production
22
22
 
23
- # The type of estimate. Available types are mass, flight, shipping, and vehicle.
23
+ # The type of estimate. Available types are mass, flight, shipping, vehicle, and crypto.
24
24
  attr_accessor :type
25
25
 
26
26
  # The estimated mass in grams for this estimate.
@@ -38,6 +38,9 @@ module Patch
38
38
  # An array containing the inventory allocations for this order.
39
39
  attr_accessor :allocations
40
40
 
41
+ # The url of this order in the public registry.
42
+ attr_accessor :registry_url
43
+
41
44
  # An optional JSON object containing metadata for this order.
42
45
  attr_accessor :metadata
43
46
 
@@ -74,6 +77,7 @@ module Patch
74
77
  :'price_cents_usd' => :'price_cents_usd',
75
78
  :'patch_fee_cents_usd' => :'patch_fee_cents_usd',
76
79
  :'allocations' => :'allocations',
80
+ :'registry_url' => :'registry_url',
77
81
  :'metadata' => :'metadata'
78
82
  }
79
83
  end
@@ -86,9 +90,10 @@ module Patch
86
90
  :'production' => :'Boolean',
87
91
  :'state' => :'String',
88
92
  :'allocation_state' => :'String',
89
- :'price_cents_usd' => :'String',
90
- :'patch_fee_cents_usd' => :'String',
93
+ :'price_cents_usd' => :'Integer',
94
+ :'patch_fee_cents_usd' => :'Integer',
91
95
  :'allocations' => :'Array<Allocation>',
96
+ :'registry_url' => :'String',
92
97
  :'metadata' => :'Object'
93
98
  }
94
99
  end
@@ -164,6 +169,10 @@ module Patch
164
169
  end
165
170
  end
166
171
 
172
+ if attributes.key?(:'registry_url')
173
+ self.registry_url = attributes[:'registry_url']
174
+ end
175
+
167
176
  if attributes.key?(:'metadata')
168
177
  self.metadata = attributes[:'metadata']
169
178
  end
@@ -221,7 +230,7 @@ module Patch
221
230
  return false if @mass_g < 0
222
231
  return false if @production.nil?
223
232
  return false if @state.nil?
224
- state_validator = EnumAttributeValidator.new('String', ["draft", "placed", "complete", "cancelled"])
233
+ state_validator = EnumAttributeValidator.new('String', ["draft", "placed", "processing", "complete", "cancelled"])
225
234
  return false unless state_validator.valid?(@state)
226
235
  return false if @allocation_state.nil?
227
236
  allocation_state_validator = EnumAttributeValidator.new('String', ["pending", "partially_allocated", "allocated"])
@@ -252,7 +261,7 @@ module Patch
252
261
  # Custom attribute writer method checking allowed values (enum).
253
262
  # @param [Object] state Object to be assigned
254
263
  def state=(state)
255
- validator = EnumAttributeValidator.new('String', ["draft", "placed", "complete", "cancelled"])
264
+ validator = EnumAttributeValidator.new('String', ["draft", "placed", "processing", "complete", "cancelled"])
256
265
  unless validator.valid?(state)
257
266
  fail ArgumentError, "invalid value for \"state\", must be one of #{validator.allowable_values}."
258
267
  end
@@ -282,6 +291,7 @@ module Patch
282
291
  price_cents_usd == o.price_cents_usd &&
283
292
  patch_fee_cents_usd == o.patch_fee_cents_usd &&
284
293
  allocations == o.allocations &&
294
+ registry_url == o.registry_url &&
285
295
  metadata == o.metadata
286
296
  end
287
297
 
@@ -294,7 +304,7 @@ module Patch
294
304
  # Calculates hash code according to all attributes.
295
305
  # @return [Integer] Hash code
296
306
  def hash
297
- [id, mass_g, production, state, allocation_state, price_cents_usd, patch_fee_cents_usd, allocations, metadata].hash
307
+ [id, mass_g, production, state, allocation_state, price_cents_usd, patch_fee_cents_usd, allocations, registry_url, metadata].hash
298
308
  end
299
309
 
300
310
  # Builds the object from hash
@@ -11,5 +11,5 @@ OpenAPI Generator version: 4.3.1
11
11
  =end
12
12
 
13
13
  module Patch
14
- VERSION = '1.5.2'
14
+ VERSION = '1.9.0'
15
15
  end
Binary file
@@ -1,10 +1,4 @@
1
1
  RSpec.describe 'Estimates Integration' do
2
- before do
3
- Patch.configure do |config|
4
- config.access_token = ENV['SANDBOX_API_KEY']
5
- end
6
- end
7
-
8
2
  it 'supports create, retrieve and list' do
9
3
  create_estimate_response = Patch::Estimate.create_mass_estimate(mass_g: 100)
10
4
  estimate_id = create_estimate_response.data.id
@@ -33,7 +27,7 @@ RSpec.describe 'Estimates Integration' do
33
27
  )
34
28
 
35
29
  expect(flight_estimate.data.type).to eq 'flight'
36
- expect(flight_estimate.data.mass_g).to eq 1_031_697
30
+ expect(flight_estimate.data.mass_g).to eq 1_000_622
37
31
  end
38
32
 
39
33
  it 'supports creating vehicle estimates' do
@@ -79,4 +73,57 @@ RSpec.describe 'Estimates Integration' do
79
73
  expect(create_estimate_response.data.type).to eq 'shipping'
80
74
  expect(create_estimate_response.data.mass_g).to eq 12_431
81
75
  end
76
+
77
+ it 'supports creating bitcoin estimates with partial information' do
78
+ bitcoin_estimate = Patch::Estimate.create_bitcoin_estimate({ create_order: false })
79
+
80
+ expect(bitcoin_estimate.data.type).to eq 'bitcoin'
81
+ expect(bitcoin_estimate.data.mass_g).to be >= 2_000
82
+ end
83
+
84
+ it 'supports creating bitcoin estimates with a transaction amount' do
85
+ bitcoin_estimate = Patch::Estimate.create_bitcoin_estimate(
86
+ transaction_value_btc_sats: 10_000
87
+ )
88
+
89
+ bitcoin_estimate_2 = Patch::Estimate.create_bitcoin_estimate(
90
+ transaction_value_btc_sats: 100_000
91
+ )
92
+
93
+ expect(bitcoin_estimate.data.type).to eq 'bitcoin'
94
+ expect(bitcoin_estimate.data.mass_g).to be < bitcoin_estimate_2.data.mass_g
95
+ end
96
+
97
+ it 'supports creating bitcoin estimates with a timestamp' do
98
+ bitcoin_estimate_1 = Patch::Estimate.create_bitcoin_estimate(
99
+ timestamp: '2021-06-01T20:31:18.403Z'
100
+ )
101
+
102
+ bitcoin_estimate_2 = Patch::Estimate.create_bitcoin_estimate(
103
+ timestamp: '2021-07-01T20:31:18.403Z'
104
+ )
105
+
106
+ expect(bitcoin_estimate_1.data.type).to eq 'bitcoin'
107
+ expect(bitcoin_estimate_1.data.mass_g).to be > bitcoin_estimate_2.data.mass_g # Bitcoin was emitting less in July 2021 than in June
108
+ end
109
+
110
+ it 'supports creating ethereum estimates with a gas amount' do
111
+ ethereum_estimate = Patch::Estimate.create_ethereum_estimate(
112
+ gas_used: 100
113
+ )
114
+
115
+ ethereum_estimate_2 = Patch::Estimate.create_ethereum_estimate(
116
+ gas_used: 1000
117
+ )
118
+
119
+ expect(ethereum_estimate.data.type).to eq 'ethereum'
120
+ expect(ethereum_estimate.data.mass_g).to be < ethereum_estimate_2.data.mass_g
121
+ end
122
+
123
+ it 'supports creating ethereum estimates with partial information' do
124
+ ethereum_estimate = Patch::Estimate.create_ethereum_estimate({ create_order: false })
125
+
126
+ expect(ethereum_estimate.data.type).to eq 'ethereum'
127
+ expect(ethereum_estimate.data.mass_g).to be >= 2_000
128
+ end
82
129
  end
@@ -1,10 +1,4 @@
1
1
  RSpec.describe 'Orders Integration' do
2
- before do
3
- Patch.configure do |config|
4
- config.access_token = ENV['SANDBOX_API_KEY']
5
- end
6
- end
7
-
8
2
  it 'supports create, place, cancel, retrieve and list' do
9
3
  create_order_response = Patch::Order.create_order(mass_g: 100)
10
4
  order_id = create_order_response.data.id
@@ -44,8 +38,9 @@ RSpec.describe 'Orders Integration' do
44
38
  expect(create_order_response.success).to eq true
45
39
  expect(order.id).not_to be_nil
46
40
  expect(order.mass_g).to eq(order_mass_g)
47
- expect(order.price_cents_usd.to_i).to be_between(expected_price - 1, expected_price + 1)
48
- expect(order.patch_fee_cents_usd).not_to be_empty
41
+ expect(order.price_cents_usd).to be_between(expected_price - 2, expected_price + 2)
42
+ expect(order.patch_fee_cents_usd).to be_kind_of(Integer)
43
+ expect(order.registry_url).not_to be_empty
49
44
  end
50
45
 
51
46
  it 'supports create with a total price' do
@@ -54,7 +49,7 @@ RSpec.describe 'Orders Integration' do
54
49
  )
55
50
 
56
51
  project_id = retrieve_project_response.data.id
57
- total_price_cents_usd = 5_00
52
+ total_price_cents_usd = 50_00
58
53
 
59
54
  create_order_response = Patch::Order.create_order(
60
55
  total_price_cents_usd: total_price_cents_usd,
@@ -66,23 +61,28 @@ RSpec.describe 'Orders Integration' do
66
61
  order = create_order_response.data
67
62
 
68
63
  expect(order.id).not_to be_nil
69
- expect(order.mass_g).to eq(5_00_000)
70
- expect(order.price_cents_usd).not_to be_empty
71
- expect(order.patch_fee_cents_usd).not_to be_empty
72
- expect(
73
- order.price_cents_usd.to_i + order.patch_fee_cents_usd.to_i
74
- ).to eq(total_price_cents_usd)
64
+ expect(order.price_cents_usd + order.patch_fee_cents_usd).to eq total_price_cents_usd
65
+ expect(order.registry_url).not_to be_empty
75
66
  end
76
67
 
77
- it 'supports create with metadata' do
68
+ it 'supports creation with and querying by metadata' do
78
69
  metadata = { user: 'john doe' }
79
70
 
80
- create_order_response = Patch::Order.create_order(mass_g: 100, metadata: metadata)
71
+ create_order_response =
72
+ Patch::Order.create_order(mass_g: 100, metadata: metadata)
81
73
 
82
74
  expect(create_order_response.success).to eq true
83
75
  expect(create_order_response.data.id).not_to be_nil
84
76
  expect(create_order_response.data.mass_g).to eq(100)
85
77
  expect(create_order_response.data.metadata).to eq(metadata)
78
+
79
+ retrieve_orders_response = Patch::Order.retrieve_orders(
80
+ page: 1, metadata: { user: 'john' }
81
+ )
82
+ expect(retrieve_orders_response.success).to eq true
83
+ expect(retrieve_orders_response.data.count).to be >= 1
84
+ expect(retrieve_orders_response.data.map(&:metadata))
85
+ .to all(have_key(:user))
86
86
  end
87
87
 
88
88
  it 'supports place and cancel for orders created via an estimate' do