patch_ruby 1.5.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +14 -10
- data/lib/patch_ruby.rb +1 -0
- data/lib/patch_ruby/api/estimates_api.rb +65 -0
- data/lib/patch_ruby/api/orders_api.rb +2 -2
- data/lib/patch_ruby/models/create_bitcoin_estimate_request.rb +253 -0
- data/lib/patch_ruby/models/order.rb +13 -3
- data/lib/patch_ruby/version.rb +1 -1
- data/spec/integration/estimates_spec.rb +20 -0
- data/spec/integration/orders_spec.rb +5 -2
- metadata +29 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cf4569e76d9ab3e100909b2e1ef6baab9bec5fdccf509cbda298bef9424cf49
|
4
|
+
data.tar.gz: 391d81d9dd2d6bd9e761c21f28ca1bb07685ef67da8b9eef138c5c41e49012d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b179c02c365df62a4f35ebb7215b5fa4fefbc143fbd76d2fc387f745d47c0d51af43af719a941f7a106903f81f060eb8af29854de811293022dc37342a4e58a3
|
7
|
+
data.tar.gz: bc742b04409a703f3fbc9d539743379dd4c35e921d6bc6ca13b938e98fb800b30223cdf5ccce169ee7870c93e02e726cdf48250d82955aa9f4c26bf3e7e4ca07
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,13 @@ 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.6.0] - 2021-07-14
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Order responses return a `registry_url` field
|
13
|
+
- Add support for Bitcoin estimates
|
14
|
+
|
8
15
|
## [1.5.2] - 2021-03-30
|
9
16
|
|
10
17
|
### Changed
|
data/README.md
CHANGED
@@ -139,6 +139,10 @@ Patch::Estimate.create_vehicle_estimate(
|
|
139
139
|
year: year
|
140
140
|
)
|
141
141
|
|
142
|
+
# Create a flight estimate
|
143
|
+
transaction_value_btc_sats = 1000; # [Optional] Pass in the transaction value in satoshis
|
144
|
+
Patch::Estimate.create_bitcoin_estimate(transaction_value_btc_sats: transaction_value_btc_sats)
|
145
|
+
|
142
146
|
## You can also specify a project-id field (optional) to be used instead of the preferred one
|
143
147
|
project_id = 'pro_test_1234' # Pass in the project's ID
|
144
148
|
Patch::Estimate.create_mass_estimate(mass_g: mass, project_id: project_id)
|
@@ -218,30 +222,30 @@ Patch::Preference.retrieve_preferences(page: page)
|
|
218
222
|
|
219
223
|
To build the gem locally, run:
|
220
224
|
|
221
|
-
```
|
222
|
-
|
225
|
+
```bash
|
226
|
+
gem build patch_ruby.gemspec
|
223
227
|
```
|
224
228
|
|
225
229
|
This will create a .gem file. To install the local gem:
|
226
230
|
|
227
|
-
```
|
228
|
-
|
231
|
+
```bash
|
232
|
+
gem install patch_ruby-1.x.x.gem
|
229
233
|
```
|
230
234
|
|
231
235
|
Install dependencies:
|
232
236
|
|
233
|
-
```
|
234
|
-
|
237
|
+
```bash
|
238
|
+
bundle install
|
235
239
|
```
|
236
240
|
|
237
241
|
Set up required environment variables:
|
238
242
|
|
239
|
-
```
|
240
|
-
|
243
|
+
```bash
|
244
|
+
export SANDBOX_API_KEY=<SANDBOX API KEY>
|
241
245
|
```
|
242
246
|
|
243
247
|
Run tests:
|
244
248
|
|
245
|
-
```
|
246
|
-
|
249
|
+
```bash
|
250
|
+
bundle exec rspec
|
247
251
|
```
|
data/lib/patch_ruby.rb
CHANGED
@@ -18,6 +18,7 @@ require 'patch_ruby/configuration'
|
|
18
18
|
|
19
19
|
# Models
|
20
20
|
require 'patch_ruby/models/allocation'
|
21
|
+
require 'patch_ruby/models/create_bitcoin_estimate_request'
|
21
22
|
require 'patch_ruby/models/create_mass_estimate_request'
|
22
23
|
require 'patch_ruby/models/create_order_request'
|
23
24
|
require 'patch_ruby/models/create_preference_request'
|
@@ -15,6 +15,7 @@ require 'cgi'
|
|
15
15
|
module Patch
|
16
16
|
class EstimatesApi
|
17
17
|
OPERATIONS = [
|
18
|
+
:create_bitcoin_estimate,
|
18
19
|
:create_flight_estimate,
|
19
20
|
:create_mass_estimate,
|
20
21
|
:create_shipping_estimate,
|
@@ -28,6 +29,70 @@ module Patch
|
|
28
29
|
def initialize(api_client = ApiClient.default)
|
29
30
|
@api_client = api_client
|
30
31
|
end
|
32
|
+
# Create a bitcoin estimate given a timestamp and transaction value
|
33
|
+
# Creates a bitcoin 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.
|
34
|
+
# @param create_bitcoin_estimate_request [CreateBitcoinEstimateRequest]
|
35
|
+
# @param [Hash] opts the optional parameters
|
36
|
+
# @return [EstimateResponse]
|
37
|
+
def create_bitcoin_estimate(create_bitcoin_estimate_request, opts = {})
|
38
|
+
data, _status_code, _headers = create_bitcoin_estimate_with_http_info(create_bitcoin_estimate_request, opts)
|
39
|
+
data
|
40
|
+
end
|
41
|
+
|
42
|
+
# Create a bitcoin estimate given a timestamp and transaction value
|
43
|
+
# Creates a bitcoin 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.
|
44
|
+
# @param create_bitcoin_estimate_request [CreateBitcoinEstimateRequest]
|
45
|
+
# @param [Hash] opts the optional parameters
|
46
|
+
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
|
47
|
+
def create_bitcoin_estimate_with_http_info(create_bitcoin_estimate_request, opts = {})
|
48
|
+
if @api_client.config.debugging
|
49
|
+
@api_client.config.logger.debug 'Calling API: EstimatesApi.create_bitcoin_estimate ...'
|
50
|
+
end
|
51
|
+
# verify the required parameter 'create_bitcoin_estimate_request' is set
|
52
|
+
if @api_client.config.client_side_validation && create_bitcoin_estimate_request.nil?
|
53
|
+
fail ArgumentError, "Missing the required parameter 'create_bitcoin_estimate_request' when calling EstimatesApi.create_bitcoin_estimate"
|
54
|
+
end
|
55
|
+
# resource path
|
56
|
+
local_var_path = '/v1/estimates/crypto/btc'
|
57
|
+
|
58
|
+
# query parameters
|
59
|
+
query_params = opts[:query_params] || {}
|
60
|
+
|
61
|
+
# header parameters
|
62
|
+
header_params = opts[:header_params] || {}
|
63
|
+
# HTTP header 'Accept' (if needed)
|
64
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
65
|
+
# HTTP header 'Content-Type'
|
66
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
67
|
+
|
68
|
+
# form parameters
|
69
|
+
form_params = opts[:form_params] || {}
|
70
|
+
|
71
|
+
# http body (model)
|
72
|
+
post_body = opts[:body] || @api_client.object_to_http_body(create_bitcoin_estimate_request)
|
73
|
+
|
74
|
+
# return_type
|
75
|
+
return_type = opts[:return_type] || 'EstimateResponse'
|
76
|
+
|
77
|
+
# auth_names
|
78
|
+
auth_names = opts[:auth_names] || ['bearer_auth']
|
79
|
+
|
80
|
+
new_options = opts.merge(
|
81
|
+
:header_params => header_params,
|
82
|
+
:query_params => query_params,
|
83
|
+
:form_params => form_params,
|
84
|
+
:body => post_body,
|
85
|
+
:auth_names => auth_names,
|
86
|
+
:return_type => return_type
|
87
|
+
)
|
88
|
+
|
89
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
90
|
+
if @api_client.config.debugging
|
91
|
+
@api_client.config.logger.debug "API called: EstimatesApi#create_bitcoin_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
92
|
+
end
|
93
|
+
return data, status_code, headers
|
94
|
+
end
|
95
|
+
|
31
96
|
# Create a flight estimate given the distance traveled in meters
|
32
97
|
# Creates a flight 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.
|
33
98
|
# @param create_flight_estimate_request [CreateFlightEstimateRequest]
|
@@ -28,7 +28,7 @@ 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` state can be cancelled.
|
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
32
|
# @param id [String]
|
33
33
|
# @param [Hash] opts the optional parameters
|
34
34
|
# @return [OrderResponse]
|
@@ -38,7 +38,7 @@ module Patch
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# Cancel an order
|
41
|
-
# Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` state can be cancelled.
|
41
|
+
# 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.
|
42
42
|
# @param id [String]
|
43
43
|
# @param [Hash] opts the optional parameters
|
44
44
|
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
|
@@ -0,0 +1,253 @@
|
|
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 CreateBitcoinEstimateRequest
|
17
|
+
attr_accessor :timestamp
|
18
|
+
|
19
|
+
attr_accessor :transaction_value_btc_sats
|
20
|
+
|
21
|
+
attr_accessor :project_id
|
22
|
+
|
23
|
+
attr_accessor :create_order
|
24
|
+
|
25
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
26
|
+
def self.attribute_map
|
27
|
+
{
|
28
|
+
:'timestamp' => :'timestamp',
|
29
|
+
:'transaction_value_btc_sats' => :'transaction_value_btc_sats',
|
30
|
+
:'project_id' => :'project_id',
|
31
|
+
:'create_order' => :'create_order'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# Attribute type mapping.
|
36
|
+
def self.openapi_types
|
37
|
+
{
|
38
|
+
:'timestamp' => :'String',
|
39
|
+
:'transaction_value_btc_sats' => :'Integer',
|
40
|
+
:'project_id' => :'String',
|
41
|
+
:'create_order' => :'Boolean'
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
# Set with nullable attributes.
|
46
|
+
def self.openapi_nullable
|
47
|
+
nullable_properties = Set.new
|
48
|
+
|
49
|
+
nullable_properties.add("timestamp")
|
50
|
+
|
51
|
+
nullable_properties.add("transaction_value_btc_sats")
|
52
|
+
|
53
|
+
nullable_properties.add("project_id")
|
54
|
+
|
55
|
+
nullable_properties.add("create_order")
|
56
|
+
|
57
|
+
nullable_properties
|
58
|
+
end
|
59
|
+
|
60
|
+
# Allows models with corresponding API classes to delegate API operations to those API classes
|
61
|
+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
|
62
|
+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
|
63
|
+
def self.method_missing(message, *args, &block)
|
64
|
+
if Object.const_defined?('Patch::CreateBitcoinEstimateRequestsApi::OPERATIONS') && Patch::CreateBitcoinEstimateRequestsApi::OPERATIONS.include?(message)
|
65
|
+
Patch::CreateBitcoinEstimateRequestsApi.new.send(message, *args)
|
66
|
+
else
|
67
|
+
super
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Initializes the object
|
72
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
73
|
+
def initialize(attributes = {})
|
74
|
+
if (!attributes.is_a?(Hash))
|
75
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::CreateBitcoinEstimateRequest` initialize method"
|
76
|
+
end
|
77
|
+
|
78
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
79
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
80
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
81
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::CreateBitcoinEstimateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
82
|
+
end
|
83
|
+
h[k.to_sym] = v
|
84
|
+
}
|
85
|
+
|
86
|
+
if attributes.key?(:'timestamp')
|
87
|
+
self.timestamp = attributes[:'timestamp']
|
88
|
+
end
|
89
|
+
|
90
|
+
if attributes.key?(:'transaction_value_btc_sats')
|
91
|
+
self.transaction_value_btc_sats = attributes[:'transaction_value_btc_sats']
|
92
|
+
end
|
93
|
+
|
94
|
+
if attributes.key?(:'project_id')
|
95
|
+
self.project_id = attributes[:'project_id']
|
96
|
+
end
|
97
|
+
|
98
|
+
if attributes.key?(:'create_order')
|
99
|
+
self.create_order = attributes[:'create_order']
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
104
|
+
# @return Array for valid properties with the reasons
|
105
|
+
def list_invalid_properties
|
106
|
+
invalid_properties = Array.new
|
107
|
+
invalid_properties
|
108
|
+
end
|
109
|
+
|
110
|
+
# Check to see if the all the properties in the model are valid
|
111
|
+
# @return true if the model is valid
|
112
|
+
def valid?
|
113
|
+
true
|
114
|
+
end
|
115
|
+
|
116
|
+
# Checks equality by comparing each attribute.
|
117
|
+
# @param [Object] Object to be compared
|
118
|
+
def ==(o)
|
119
|
+
return true if self.equal?(o)
|
120
|
+
self.class == o.class &&
|
121
|
+
timestamp == o.timestamp &&
|
122
|
+
transaction_value_btc_sats == o.transaction_value_btc_sats &&
|
123
|
+
project_id == o.project_id &&
|
124
|
+
create_order == o.create_order
|
125
|
+
end
|
126
|
+
|
127
|
+
# @see the `==` method
|
128
|
+
# @param [Object] Object to be compared
|
129
|
+
def eql?(o)
|
130
|
+
self == o
|
131
|
+
end
|
132
|
+
|
133
|
+
# Calculates hash code according to all attributes.
|
134
|
+
# @return [Integer] Hash code
|
135
|
+
def hash
|
136
|
+
[timestamp, transaction_value_btc_sats, project_id, create_order].hash
|
137
|
+
end
|
138
|
+
|
139
|
+
# Builds the object from hash
|
140
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
141
|
+
# @return [Object] Returns the model itself
|
142
|
+
def self.build_from_hash(attributes)
|
143
|
+
new.build_from_hash(attributes)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Builds the object from hash
|
147
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
148
|
+
# @return [Object] Returns the model itself
|
149
|
+
def build_from_hash(attributes)
|
150
|
+
return nil unless attributes.is_a?(Hash)
|
151
|
+
self.class.openapi_types.each_pair do |key, type|
|
152
|
+
if type =~ /\AArray<(.*)>/i
|
153
|
+
# check to ensure the input is an array given that the attribute
|
154
|
+
# is documented as an array but the input is not
|
155
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
156
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
157
|
+
end
|
158
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
159
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
160
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
161
|
+
end
|
162
|
+
|
163
|
+
self
|
164
|
+
end
|
165
|
+
|
166
|
+
# Deserializes the data based on type
|
167
|
+
# @param string type Data type
|
168
|
+
# @param string value Value to be deserialized
|
169
|
+
# @return [Object] Deserialized data
|
170
|
+
def _deserialize(type, value)
|
171
|
+
case type.to_sym
|
172
|
+
when :DateTime
|
173
|
+
DateTime.parse(value)
|
174
|
+
when :Date
|
175
|
+
Date.parse(value)
|
176
|
+
when :String
|
177
|
+
value.to_s
|
178
|
+
when :Integer
|
179
|
+
value.to_i
|
180
|
+
when :Float
|
181
|
+
value.to_f
|
182
|
+
when :Boolean
|
183
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
184
|
+
true
|
185
|
+
else
|
186
|
+
false
|
187
|
+
end
|
188
|
+
when :Object
|
189
|
+
# generic object (usually a Hash), return directly
|
190
|
+
value
|
191
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
192
|
+
inner_type = Regexp.last_match[:inner_type]
|
193
|
+
value.map { |v| _deserialize(inner_type, v) }
|
194
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
195
|
+
k_type = Regexp.last_match[:k_type]
|
196
|
+
v_type = Regexp.last_match[:v_type]
|
197
|
+
{}.tap do |hash|
|
198
|
+
value.each do |k, v|
|
199
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
else # model
|
203
|
+
Patch.const_get(type).build_from_hash(value)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
# Returns the string representation of the object
|
208
|
+
# @return [String] String presentation of the object
|
209
|
+
def to_s
|
210
|
+
to_hash.to_s
|
211
|
+
end
|
212
|
+
|
213
|
+
# to_body is an alias to to_hash (backward compatibility)
|
214
|
+
# @return [Hash] Returns the object in the form of hash
|
215
|
+
def to_body
|
216
|
+
to_hash
|
217
|
+
end
|
218
|
+
|
219
|
+
# Returns the object in the form of hash
|
220
|
+
# @return [Hash] Returns the object in the form of hash
|
221
|
+
def to_hash
|
222
|
+
hash = {}
|
223
|
+
self.class.attribute_map.each_pair do |attr, param|
|
224
|
+
value = self.send(attr)
|
225
|
+
if value.nil?
|
226
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
227
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
228
|
+
end
|
229
|
+
|
230
|
+
hash[param] = _to_hash(value)
|
231
|
+
end
|
232
|
+
hash
|
233
|
+
end
|
234
|
+
|
235
|
+
# Outputs non-array value in the form of hash
|
236
|
+
# For object, use to_hash. Otherwise, just return the value
|
237
|
+
# @param [Object] value Any valid value
|
238
|
+
# @return [Hash] Returns the value in the form of hash
|
239
|
+
def _to_hash(value)
|
240
|
+
if value.is_a?(Array)
|
241
|
+
value.compact.map { |v| _to_hash(v) }
|
242
|
+
elsif value.is_a?(Hash)
|
243
|
+
{}.tap do |hash|
|
244
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
245
|
+
end
|
246
|
+
elsif value.respond_to? :to_hash
|
247
|
+
value.to_hash
|
248
|
+
else
|
249
|
+
value
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
@@ -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
|
@@ -89,6 +93,7 @@ module Patch
|
|
89
93
|
:'price_cents_usd' => :'String',
|
90
94
|
:'patch_fee_cents_usd' => :'String',
|
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
|
data/lib/patch_ruby/version.rb
CHANGED
@@ -79,4 +79,24 @@ RSpec.describe 'Estimates Integration' do
|
|
79
79
|
expect(create_estimate_response.data.type).to eq 'shipping'
|
80
80
|
expect(create_estimate_response.data.mass_g).to eq 12_431
|
81
81
|
end
|
82
|
+
|
83
|
+
it 'supports creating bitcoin estimates with partial information' do
|
84
|
+
bitcoin_estimate = Patch::Estimate.create_bitcoin_estimate({ create_order: false })
|
85
|
+
|
86
|
+
expect(bitcoin_estimate.data.type).to eq 'bitcoin'
|
87
|
+
expect(bitcoin_estimate.data.mass_g).to be >= 2_000
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'supports creating bitcoin estimates with a transaction amount' do
|
91
|
+
bitcoin_estimate = Patch::Estimate.create_bitcoin_estimate(
|
92
|
+
transaction_value_btc_sats: 10_000
|
93
|
+
)
|
94
|
+
|
95
|
+
bitcoin_estimate_2 = Patch::Estimate.create_bitcoin_estimate(
|
96
|
+
transaction_value_btc_sats: 100_000
|
97
|
+
)
|
98
|
+
|
99
|
+
expect(bitcoin_estimate.data.type).to eq 'bitcoin'
|
100
|
+
expect(bitcoin_estimate.data.mass_g).to be < bitcoin_estimate_2.data.mass_g
|
101
|
+
end
|
82
102
|
end
|
@@ -44,8 +44,9 @@ RSpec.describe 'Orders Integration' do
|
|
44
44
|
expect(create_order_response.success).to eq true
|
45
45
|
expect(order.id).not_to be_nil
|
46
46
|
expect(order.mass_g).to eq(order_mass_g)
|
47
|
-
expect(order.price_cents_usd.to_i).to be_between(expected_price -
|
47
|
+
expect(order.price_cents_usd.to_i).to be_between(expected_price - 2, expected_price + 2)
|
48
48
|
expect(order.patch_fee_cents_usd).not_to be_empty
|
49
|
+
expect(order.registry_url).not_to be_empty
|
49
50
|
end
|
50
51
|
|
51
52
|
it 'supports create with a total price' do
|
@@ -66,12 +67,14 @@ RSpec.describe 'Orders Integration' do
|
|
66
67
|
order = create_order_response.data
|
67
68
|
|
68
69
|
expect(order.id).not_to be_nil
|
69
|
-
expect(order.mass_g).to
|
70
|
+
expect(order.mass_g).to be > 450_000
|
71
|
+
expect(order.mass_g).to be < 460_000
|
70
72
|
expect(order.price_cents_usd).not_to be_empty
|
71
73
|
expect(order.patch_fee_cents_usd).not_to be_empty
|
72
74
|
expect(
|
73
75
|
order.price_cents_usd.to_i + order.patch_fee_cents_usd.to_i
|
74
76
|
).to eq(total_price_cents_usd)
|
77
|
+
expect(order.registry_url).not_to be_empty
|
75
78
|
end
|
76
79
|
|
77
80
|
it 'supports create with metadata' do
|
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.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patch Technology
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/patch_ruby/api_error.rb
|
93
93
|
- lib/patch_ruby/configuration.rb
|
94
94
|
- lib/patch_ruby/models/allocation.rb
|
95
|
+
- lib/patch_ruby/models/create_bitcoin_estimate_request.rb
|
95
96
|
- lib/patch_ruby/models/create_mass_estimate_request.rb
|
96
97
|
- lib/patch_ruby/models/create_order_request.rb
|
97
98
|
- lib/patch_ruby/models/create_preference_request.rb
|
@@ -189,52 +190,52 @@ specification_version: 4
|
|
189
190
|
summary: Ruby wrapper for the Patch API
|
190
191
|
test_files:
|
191
192
|
- spec/api/preferences_api_spec.rb
|
192
|
-
- spec/api/estimates_api_spec.rb
|
193
193
|
- spec/api/projects_api_spec.rb
|
194
|
+
- spec/api/estimates_api_spec.rb
|
194
195
|
- spec/api/orders_api_spec.rb
|
195
196
|
- spec/api_client_spec.rb
|
196
197
|
- spec/configuration_spec.rb
|
197
198
|
- spec/constants.rb
|
198
|
-
- spec/factories/preference_list_responses.rb
|
199
|
-
- spec/factories/order_responses.rb
|
200
|
-
- spec/factories/projects.rb
|
201
|
-
- spec/factories/error_responses.rb
|
202
|
-
- spec/factories/orders.rb
|
203
|
-
- spec/factories/create_order_requests.rb
|
204
|
-
- spec/factories/create_mass_estimate_requests.rb
|
205
|
-
- spec/factories/project_responses.rb
|
206
|
-
- spec/factories/estimate_list_responses.rb
|
207
199
|
- spec/factories/order_list_responses.rb
|
208
|
-
- spec/factories/create_preference_requests.rb
|
209
|
-
- spec/factories/allocations.rb
|
210
200
|
- spec/factories/preferences.rb
|
211
|
-
- spec/factories/
|
201
|
+
- spec/factories/project_responses.rb
|
212
202
|
- spec/factories/estimates.rb
|
213
203
|
- spec/factories/preference_responses.rb
|
214
|
-
- spec/factories/
|
204
|
+
- spec/factories/estimate_list_responses.rb
|
205
|
+
- spec/factories/create_preference_requests.rb
|
206
|
+
- spec/factories/project_list_responses.rb
|
207
|
+
- spec/factories/error_responses.rb
|
215
208
|
- spec/factories/meta_index_objects.rb
|
216
|
-
- spec/
|
209
|
+
- spec/factories/preference_list_responses.rb
|
210
|
+
- spec/factories/projects.rb
|
211
|
+
- spec/factories/create_mass_estimate_requests.rb
|
212
|
+
- spec/factories/order_responses.rb
|
213
|
+
- spec/factories/allocations.rb
|
214
|
+
- spec/factories/orders.rb
|
215
|
+
- spec/factories/create_order_requests.rb
|
216
|
+
- spec/factories/estimate_responses.rb
|
217
217
|
- spec/integration/orders_spec.rb
|
218
218
|
- spec/integration/preferences_spec.rb
|
219
|
+
- spec/integration/estimates_spec.rb
|
219
220
|
- spec/integration/projects_spec.rb
|
220
|
-
- spec/models/
|
221
|
+
- spec/models/create_preference_request_spec.rb
|
222
|
+
- spec/models/preference_spec.rb
|
223
|
+
- spec/models/estimate_response_spec.rb
|
224
|
+
- spec/models/error_response_spec.rb
|
225
|
+
- spec/models/estimate_list_response_spec.rb
|
221
226
|
- spec/models/create_mass_estimate_request_spec.rb
|
227
|
+
- spec/models/project_spec.rb
|
222
228
|
- spec/models/order_spec.rb
|
223
|
-
- spec/models/
|
229
|
+
- spec/models/preference_response_spec.rb
|
224
230
|
- spec/models/order_list_response_spec.rb
|
225
|
-
- spec/models/estimate_list_response_spec.rb
|
226
|
-
- spec/models/error_response_spec.rb
|
227
231
|
- spec/models/project_list_response_spec.rb
|
228
|
-
- spec/models/preference_spec.rb
|
229
|
-
- spec/models/order_response_spec.rb
|
230
|
-
- spec/models/preference_list_response_spec.rb
|
231
|
-
- spec/models/create_preference_request_spec.rb
|
232
232
|
- spec/models/project_response_spec.rb
|
233
233
|
- spec/models/estimate_spec.rb
|
234
234
|
- spec/models/meta_index_object_spec.rb
|
235
|
-
- spec/models/
|
236
|
-
- spec/models/
|
237
|
-
- spec/models/
|
235
|
+
- spec/models/order_response_spec.rb
|
236
|
+
- spec/models/preference_list_response_spec.rb
|
237
|
+
- spec/models/allocation_spec.rb
|
238
|
+
- spec/models/create_order_request_spec.rb
|
238
239
|
- spec/patch_ruby_spec.rb
|
239
240
|
- spec/spec_helper.rb
|
240
241
|
- spec/support/shared/generated_classes.rb
|