patch_ruby 1.5.1 → 1.8.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/Gemfile.lock +5 -5
- data/README.md +14 -10
- data/lib/patch_ruby.rb +2 -0
- data/lib/patch_ruby/api/estimates_api.rb +130 -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/create_ethereum_estimate_request.rb +253 -0
- data/lib/patch_ruby/models/create_mass_estimate_request.rb +5 -5
- data/lib/patch_ruby/models/create_order_request.rb +5 -5
- data/lib/patch_ruby/models/order.rb +20 -10
- data/lib/patch_ruby/models/project.rb +3 -3
- data/lib/patch_ruby/version.rb +1 -1
- data/spec/integration/estimates_spec.rb +53 -0
- data/spec/integration/orders_spec.rb +9 -11
- metadata +31 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ab75a1c077e255f54aa542b15eefc55ae4125994a71d8138be99a0534c1a5bd
|
4
|
+
data.tar.gz: f0cd837fc4ed2187a775a01d33711b4d54b16ca30f992386305b32a81a159c1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6706f4e0965eaa1edbed707a18609f04e85e5de5808d8ab95646a5c8d63c95cdbcb0d1b7dc7859270bbb098f28e6e094ca973b9ff13c403c08982a4d6292aea
|
7
|
+
data.tar.gz: 4fcf46077c53e8e79c72d5a2caf88200b39e9c6297c67b6709c86dcc6572e3f559332bff888872e1b2b8e4827fefd829a3990045232b89f83841bae0d7e65490
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,32 @@ 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.8.0] - 2021-07-20
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Add support for Ethereum estimates
|
13
|
+
|
14
|
+
## [1.7.0] - 2021-07-14
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
- [BREAKING] Changed `order.price_cents_usd` and `order.patch_fee_cents_usd` from string to integer.
|
19
|
+
|
20
|
+
## [1.6.0] - 2021-07-14
|
21
|
+
|
22
|
+
### Added
|
23
|
+
|
24
|
+
- Order responses return a `registry_url` field
|
25
|
+
- Add support for Bitcoin estimates
|
26
|
+
|
27
|
+
## [1.5.2] - 2021-03-30
|
28
|
+
|
29
|
+
### Changed
|
30
|
+
|
31
|
+
- Updated the value validation for certain parameters to match the API
|
32
|
+
- Added the `renewables` type
|
33
|
+
|
8
34
|
## [1.5.1] - 2021-03-02
|
9
35
|
|
10
36
|
### Fixed
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
patch_ruby (1.
|
4
|
+
patch_ruby (1.8.0)
|
5
5
|
json (~> 2.1, >= 2.1.0)
|
6
6
|
typhoeus (~> 1.0, >= 1.0.1)
|
7
7
|
|
@@ -19,11 +19,11 @@ GEM
|
|
19
19
|
coderay (1.1.3)
|
20
20
|
concurrent-ruby (1.1.7)
|
21
21
|
diff-lcs (1.4.3)
|
22
|
-
ethon (0.
|
23
|
-
ffi (>= 1.
|
22
|
+
ethon (0.14.0)
|
23
|
+
ffi (>= 1.15.0)
|
24
24
|
factory_bot (6.1.0)
|
25
25
|
activesupport (>= 5.0.0)
|
26
|
-
ffi (1.
|
26
|
+
ffi (1.15.3)
|
27
27
|
i18n (1.8.7)
|
28
28
|
concurrent-ruby (~> 1.0)
|
29
29
|
json (2.5.1)
|
@@ -86,4 +86,4 @@ DEPENDENCIES
|
|
86
86
|
rubocop
|
87
87
|
|
88
88
|
BUNDLED WITH
|
89
|
-
2.
|
89
|
+
2.2.14
|
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,8 @@ 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'
|
22
|
+
require 'patch_ruby/models/create_ethereum_estimate_request'
|
21
23
|
require 'patch_ruby/models/create_mass_estimate_request'
|
22
24
|
require 'patch_ruby/models/create_order_request'
|
23
25
|
require 'patch_ruby/models/create_preference_request'
|
@@ -15,6 +15,8 @@ require 'cgi'
|
|
15
15
|
module Patch
|
16
16
|
class EstimatesApi
|
17
17
|
OPERATIONS = [
|
18
|
+
:create_bitcoin_estimate,
|
19
|
+
:create_ethereum_estimate,
|
18
20
|
:create_flight_estimate,
|
19
21
|
:create_mass_estimate,
|
20
22
|
:create_shipping_estimate,
|
@@ -28,6 +30,134 @@ module Patch
|
|
28
30
|
def initialize(api_client = ApiClient.default)
|
29
31
|
@api_client = api_client
|
30
32
|
end
|
33
|
+
# Create a bitcoin estimate given a timestamp and transaction value
|
34
|
+
# 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.
|
35
|
+
# @param create_bitcoin_estimate_request [CreateBitcoinEstimateRequest]
|
36
|
+
# @param [Hash] opts the optional parameters
|
37
|
+
# @return [EstimateResponse]
|
38
|
+
def create_bitcoin_estimate(create_bitcoin_estimate_request, opts = {})
|
39
|
+
data, _status_code, _headers = create_bitcoin_estimate_with_http_info(create_bitcoin_estimate_request, opts)
|
40
|
+
data
|
41
|
+
end
|
42
|
+
|
43
|
+
# Create a bitcoin estimate given a timestamp and transaction value
|
44
|
+
# 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.
|
45
|
+
# @param create_bitcoin_estimate_request [CreateBitcoinEstimateRequest]
|
46
|
+
# @param [Hash] opts the optional parameters
|
47
|
+
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
|
48
|
+
def create_bitcoin_estimate_with_http_info(create_bitcoin_estimate_request, opts = {})
|
49
|
+
if @api_client.config.debugging
|
50
|
+
@api_client.config.logger.debug 'Calling API: EstimatesApi.create_bitcoin_estimate ...'
|
51
|
+
end
|
52
|
+
# verify the required parameter 'create_bitcoin_estimate_request' is set
|
53
|
+
if @api_client.config.client_side_validation && create_bitcoin_estimate_request.nil?
|
54
|
+
fail ArgumentError, "Missing the required parameter 'create_bitcoin_estimate_request' when calling EstimatesApi.create_bitcoin_estimate"
|
55
|
+
end
|
56
|
+
# resource path
|
57
|
+
local_var_path = '/v1/estimates/crypto/btc'
|
58
|
+
|
59
|
+
# query parameters
|
60
|
+
query_params = opts[:query_params] || {}
|
61
|
+
|
62
|
+
# header parameters
|
63
|
+
header_params = opts[:header_params] || {}
|
64
|
+
# HTTP header 'Accept' (if needed)
|
65
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
66
|
+
# HTTP header 'Content-Type'
|
67
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
68
|
+
|
69
|
+
# form parameters
|
70
|
+
form_params = opts[:form_params] || {}
|
71
|
+
|
72
|
+
# http body (model)
|
73
|
+
post_body = opts[:body] || @api_client.object_to_http_body(create_bitcoin_estimate_request)
|
74
|
+
|
75
|
+
# return_type
|
76
|
+
return_type = opts[:return_type] || 'EstimateResponse'
|
77
|
+
|
78
|
+
# auth_names
|
79
|
+
auth_names = opts[:auth_names] || ['bearer_auth']
|
80
|
+
|
81
|
+
new_options = opts.merge(
|
82
|
+
:header_params => header_params,
|
83
|
+
:query_params => query_params,
|
84
|
+
:form_params => form_params,
|
85
|
+
:body => post_body,
|
86
|
+
:auth_names => auth_names,
|
87
|
+
:return_type => return_type
|
88
|
+
)
|
89
|
+
|
90
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
91
|
+
if @api_client.config.debugging
|
92
|
+
@api_client.config.logger.debug "API called: EstimatesApi#create_bitcoin_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
93
|
+
end
|
94
|
+
return data, status_code, headers
|
95
|
+
end
|
96
|
+
|
97
|
+
# Create an ethereum estimate given a timestamp and gas used
|
98
|
+
# 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.
|
99
|
+
# @param create_ethereum_estimate_request [CreateEthereumEstimateRequest]
|
100
|
+
# @param [Hash] opts the optional parameters
|
101
|
+
# @return [EstimateResponse]
|
102
|
+
def create_ethereum_estimate(create_ethereum_estimate_request, opts = {})
|
103
|
+
data, _status_code, _headers = create_ethereum_estimate_with_http_info(create_ethereum_estimate_request, opts)
|
104
|
+
data
|
105
|
+
end
|
106
|
+
|
107
|
+
# Create an ethereum estimate given a timestamp and gas used
|
108
|
+
# 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.
|
109
|
+
# @param create_ethereum_estimate_request [CreateEthereumEstimateRequest]
|
110
|
+
# @param [Hash] opts the optional parameters
|
111
|
+
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
|
112
|
+
def create_ethereum_estimate_with_http_info(create_ethereum_estimate_request, opts = {})
|
113
|
+
if @api_client.config.debugging
|
114
|
+
@api_client.config.logger.debug 'Calling API: EstimatesApi.create_ethereum_estimate ...'
|
115
|
+
end
|
116
|
+
# verify the required parameter 'create_ethereum_estimate_request' is set
|
117
|
+
if @api_client.config.client_side_validation && create_ethereum_estimate_request.nil?
|
118
|
+
fail ArgumentError, "Missing the required parameter 'create_ethereum_estimate_request' when calling EstimatesApi.create_ethereum_estimate"
|
119
|
+
end
|
120
|
+
# resource path
|
121
|
+
local_var_path = '/v1/estimates/crypto/eth'
|
122
|
+
|
123
|
+
# query parameters
|
124
|
+
query_params = opts[:query_params] || {}
|
125
|
+
|
126
|
+
# header parameters
|
127
|
+
header_params = opts[:header_params] || {}
|
128
|
+
# HTTP header 'Accept' (if needed)
|
129
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
130
|
+
# HTTP header 'Content-Type'
|
131
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
132
|
+
|
133
|
+
# form parameters
|
134
|
+
form_params = opts[:form_params] || {}
|
135
|
+
|
136
|
+
# http body (model)
|
137
|
+
post_body = opts[:body] || @api_client.object_to_http_body(create_ethereum_estimate_request)
|
138
|
+
|
139
|
+
# return_type
|
140
|
+
return_type = opts[:return_type] || 'EstimateResponse'
|
141
|
+
|
142
|
+
# auth_names
|
143
|
+
auth_names = opts[:auth_names] || ['bearer_auth']
|
144
|
+
|
145
|
+
new_options = opts.merge(
|
146
|
+
:header_params => header_params,
|
147
|
+
:query_params => query_params,
|
148
|
+
:form_params => form_params,
|
149
|
+
:body => post_body,
|
150
|
+
:auth_names => auth_names,
|
151
|
+
:return_type => return_type
|
152
|
+
)
|
153
|
+
|
154
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
155
|
+
if @api_client.config.debugging
|
156
|
+
@api_client.config.logger.debug "API called: EstimatesApi#create_ethereum_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
157
|
+
end
|
158
|
+
return data, status_code, headers
|
159
|
+
end
|
160
|
+
|
31
161
|
# Create a flight estimate given the distance traveled in meters
|
32
162
|
# 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
163
|
# @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
|
@@ -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 CreateEthereumEstimateRequest
|
17
|
+
attr_accessor :timestamp
|
18
|
+
|
19
|
+
attr_accessor :gas_used
|
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
|
+
:'gas_used' => :'gas_used',
|
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
|
+
:'gas_used' => :'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("gas_used")
|
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::CreateEthereumEstimateRequestsApi::OPERATIONS') && Patch::CreateEthereumEstimateRequestsApi::OPERATIONS.include?(message)
|
65
|
+
Patch::CreateEthereumEstimateRequestsApi.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::CreateEthereumEstimateRequest` 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::CreateEthereumEstimateRequest`. 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?(:'gas_used')
|
91
|
+
self.gas_used = attributes[:'gas_used']
|
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
|
+
gas_used == o.gas_used &&
|
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, gas_used, 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
|
@@ -98,8 +98,8 @@ module Patch
|
|
98
98
|
invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 2000000000.')
|
99
99
|
end
|
100
100
|
|
101
|
-
if @mass_g <
|
102
|
-
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to
|
101
|
+
if @mass_g < 0
|
102
|
+
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 0.')
|
103
103
|
end
|
104
104
|
|
105
105
|
invalid_properties
|
@@ -110,7 +110,7 @@ module Patch
|
|
110
110
|
def valid?
|
111
111
|
return false if @mass_g.nil?
|
112
112
|
return false if @mass_g > 2000000000
|
113
|
-
return false if @mass_g <
|
113
|
+
return false if @mass_g < 0
|
114
114
|
true
|
115
115
|
end
|
116
116
|
|
@@ -125,8 +125,8 @@ module Patch
|
|
125
125
|
fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 2000000000.'
|
126
126
|
end
|
127
127
|
|
128
|
-
if mass_g <
|
129
|
-
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to
|
128
|
+
if mass_g < 0
|
129
|
+
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 0.'
|
130
130
|
end
|
131
131
|
|
132
132
|
@mass_g = mass_g
|
@@ -100,8 +100,8 @@ module Patch
|
|
100
100
|
invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 2000000000.')
|
101
101
|
end
|
102
102
|
|
103
|
-
if !@mass_g.nil? && @mass_g <
|
104
|
-
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to
|
103
|
+
if !@mass_g.nil? && @mass_g < 0
|
104
|
+
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 0.')
|
105
105
|
end
|
106
106
|
|
107
107
|
if !@total_price_cents_usd.nil? && @total_price_cents_usd < 1
|
@@ -115,7 +115,7 @@ module Patch
|
|
115
115
|
# @return true if the model is valid
|
116
116
|
def valid?
|
117
117
|
return false if !@mass_g.nil? && @mass_g > 2000000000
|
118
|
-
return false if !@mass_g.nil? && @mass_g <
|
118
|
+
return false if !@mass_g.nil? && @mass_g < 0
|
119
119
|
return false if !@total_price_cents_usd.nil? && @total_price_cents_usd < 1
|
120
120
|
true
|
121
121
|
end
|
@@ -127,8 +127,8 @@ module Patch
|
|
127
127
|
fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 2000000000.'
|
128
128
|
end
|
129
129
|
|
130
|
-
if !mass_g.nil? && mass_g <
|
131
|
-
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to
|
130
|
+
if !mass_g.nil? && mass_g < 0
|
131
|
+
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 0.'
|
132
132
|
end
|
133
133
|
|
134
134
|
@mass_g = mass_g
|
@@ -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' => :'
|
90
|
-
:'patch_fee_cents_usd' => :'
|
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
|
@@ -185,8 +194,8 @@ module Patch
|
|
185
194
|
invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 2000000000.')
|
186
195
|
end
|
187
196
|
|
188
|
-
if @mass_g <
|
189
|
-
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to
|
197
|
+
if @mass_g < 0
|
198
|
+
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 0.')
|
190
199
|
end
|
191
200
|
|
192
201
|
if @production.nil?
|
@@ -218,10 +227,10 @@ module Patch
|
|
218
227
|
return false if @id.nil?
|
219
228
|
return false if @mass_g.nil?
|
220
229
|
return false if @mass_g > 2000000000
|
221
|
-
return false if @mass_g <
|
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"])
|
@@ -242,8 +251,8 @@ module Patch
|
|
242
251
|
fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 2000000000.'
|
243
252
|
end
|
244
253
|
|
245
|
-
if mass_g <
|
246
|
-
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to
|
254
|
+
if mass_g < 0
|
255
|
+
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 0.'
|
247
256
|
end
|
248
257
|
|
249
258
|
@mass_g = mass_g
|
@@ -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
|
@@ -26,7 +26,7 @@ module Patch
|
|
26
26
|
# The description of the project.
|
27
27
|
attr_accessor :description
|
28
28
|
|
29
|
-
# The type of carbon removal project, currently available project types are Biomass, Dac, Forestry, Mineralization, Ocean, Soil.
|
29
|
+
# The type of carbon removal project, currently available project types are Biomass, Dac, Forestry, Mineralization, Ocean, Renewables, Soil.
|
30
30
|
attr_accessor :type
|
31
31
|
|
32
32
|
# The country of origin of the project.
|
@@ -246,7 +246,7 @@ module Patch
|
|
246
246
|
return false if @production.nil?
|
247
247
|
return false if @name.nil?
|
248
248
|
return false if @description.nil?
|
249
|
-
type_validator = EnumAttributeValidator.new('String', ["biomass", "dac", "forestry", "mineralization", "ocean", "soil"])
|
249
|
+
type_validator = EnumAttributeValidator.new('String', ["biomass", "dac", "forestry", "mineralization", "ocean", "renewables", "soil"])
|
250
250
|
return false unless type_validator.valid?(@type)
|
251
251
|
return false if @country.nil?
|
252
252
|
return false if @developer.nil?
|
@@ -258,7 +258,7 @@ module Patch
|
|
258
258
|
# Custom attribute writer method checking allowed values (enum).
|
259
259
|
# @param [Object] type Object to be assigned
|
260
260
|
def type=(type)
|
261
|
-
validator = EnumAttributeValidator.new('String', ["biomass", "dac", "forestry", "mineralization", "ocean", "soil"])
|
261
|
+
validator = EnumAttributeValidator.new('String', ["biomass", "dac", "forestry", "mineralization", "ocean", "renewables", "soil"])
|
262
262
|
unless validator.valid?(type)
|
263
263
|
fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
|
264
264
|
end
|
data/lib/patch_ruby/version.rb
CHANGED
@@ -79,4 +79,57 @@ 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
|
102
|
+
|
103
|
+
it 'supports creating bitcoin estimates with a timestamp' do
|
104
|
+
bitcoin_estimate_1 = Patch::Estimate.create_bitcoin_estimate(
|
105
|
+
timestamp: '2021-06-01T20:31:18.403Z'
|
106
|
+
)
|
107
|
+
|
108
|
+
bitcoin_estimate_2 = Patch::Estimate.create_bitcoin_estimate(
|
109
|
+
timestamp: '2021-07-01T20:31:18.403Z'
|
110
|
+
)
|
111
|
+
|
112
|
+
expect(bitcoin_estimate_1.data.type).to eq 'bitcoin'
|
113
|
+
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
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'supports creating ethereum estimates with a gas amount' do
|
117
|
+
ethereum_estimate = Patch::Estimate.create_ethereum_estimate(
|
118
|
+
gas_used: 100
|
119
|
+
)
|
120
|
+
|
121
|
+
ethereum_estimate_2 = Patch::Estimate.create_ethereum_estimate(
|
122
|
+
gas_used: 1000
|
123
|
+
)
|
124
|
+
|
125
|
+
expect(ethereum_estimate.data.type).to eq 'ethereum'
|
126
|
+
expect(ethereum_estimate.data.mass_g).to be < ethereum_estimate_2.data.mass_g
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'supports creating ethereum estimates with partial information' do
|
130
|
+
ethereum_estimate = Patch::Estimate.create_ethereum_estimate({ create_order: false })
|
131
|
+
|
132
|
+
expect(ethereum_estimate.data.type).to eq 'ethereum'
|
133
|
+
expect(ethereum_estimate.data.mass_g).to be >= 2_000
|
134
|
+
end
|
82
135
|
end
|
@@ -40,11 +40,13 @@ RSpec.describe 'Orders Integration' do
|
|
40
40
|
|
41
41
|
create_order_response = Patch::Order.create_order(mass_g: order_mass_g, project_id: project_id)
|
42
42
|
|
43
|
+
order = create_order_response.data
|
43
44
|
expect(create_order_response.success).to eq true
|
44
|
-
expect(
|
45
|
-
expect(
|
46
|
-
expect(
|
47
|
-
expect(
|
45
|
+
expect(order.id).not_to be_nil
|
46
|
+
expect(order.mass_g).to eq(order_mass_g)
|
47
|
+
expect(order.price_cents_usd).to be_between(expected_price - 2, expected_price + 2)
|
48
|
+
expect(order.patch_fee_cents_usd).to be_kind_of(Integer)
|
49
|
+
expect(order.registry_url).not_to be_empty
|
48
50
|
end
|
49
51
|
|
50
52
|
it 'supports create with a total price' do
|
@@ -53,7 +55,7 @@ RSpec.describe 'Orders Integration' do
|
|
53
55
|
)
|
54
56
|
|
55
57
|
project_id = retrieve_project_response.data.id
|
56
|
-
total_price_cents_usd =
|
58
|
+
total_price_cents_usd = 50_00
|
57
59
|
|
58
60
|
create_order_response = Patch::Order.create_order(
|
59
61
|
total_price_cents_usd: total_price_cents_usd,
|
@@ -65,12 +67,8 @@ RSpec.describe 'Orders Integration' do
|
|
65
67
|
order = create_order_response.data
|
66
68
|
|
67
69
|
expect(order.id).not_to be_nil
|
68
|
-
expect(order.
|
69
|
-
expect(order.
|
70
|
-
expect(order.patch_fee_cents_usd).not_to be_empty
|
71
|
-
expect(
|
72
|
-
order.price_cents_usd.to_i + order.patch_fee_cents_usd.to_i
|
73
|
-
).to eq(total_price_cents_usd)
|
70
|
+
expect(order.price_cents_usd + order.patch_fee_cents_usd).to eq total_price_cents_usd
|
71
|
+
expect(order.registry_url).not_to be_empty
|
74
72
|
end
|
75
73
|
|
76
74
|
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.8.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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -92,6 +92,8 @@ 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
|
96
|
+
- lib/patch_ruby/models/create_ethereum_estimate_request.rb
|
95
97
|
- lib/patch_ruby/models/create_mass_estimate_request.rb
|
96
98
|
- lib/patch_ruby/models/create_order_request.rb
|
97
99
|
- lib/patch_ruby/models/create_preference_request.rb
|
@@ -188,53 +190,53 @@ signing_key:
|
|
188
190
|
specification_version: 4
|
189
191
|
summary: Ruby wrapper for the Patch API
|
190
192
|
test_files:
|
191
|
-
- spec/api/
|
193
|
+
- spec/api/preferences_api_spec.rb
|
192
194
|
- spec/api/projects_api_spec.rb
|
193
195
|
- spec/api/estimates_api_spec.rb
|
194
|
-
- spec/api/
|
196
|
+
- spec/api/orders_api_spec.rb
|
195
197
|
- spec/api_client_spec.rb
|
196
198
|
- spec/configuration_spec.rb
|
197
199
|
- spec/constants.rb
|
198
|
-
- spec/factories/project_responses.rb
|
199
|
-
- spec/factories/create_preference_requests.rb
|
200
|
-
- spec/factories/meta_index_objects.rb
|
201
|
-
- spec/factories/project_list_responses.rb
|
202
|
-
- spec/factories/orders.rb
|
203
200
|
- spec/factories/order_list_responses.rb
|
204
|
-
- spec/factories/order_responses.rb
|
205
201
|
- spec/factories/preferences.rb
|
206
|
-
- spec/factories/
|
207
|
-
- spec/factories/error_responses.rb
|
202
|
+
- spec/factories/project_responses.rb
|
208
203
|
- spec/factories/estimates.rb
|
204
|
+
- spec/factories/preference_responses.rb
|
209
205
|
- spec/factories/estimate_list_responses.rb
|
210
|
-
- spec/factories/
|
211
|
-
- spec/factories/
|
212
|
-
- spec/factories/
|
213
|
-
- spec/factories/
|
206
|
+
- spec/factories/create_preference_requests.rb
|
207
|
+
- spec/factories/project_list_responses.rb
|
208
|
+
- spec/factories/error_responses.rb
|
209
|
+
- spec/factories/meta_index_objects.rb
|
214
210
|
- spec/factories/preference_list_responses.rb
|
211
|
+
- spec/factories/projects.rb
|
215
212
|
- spec/factories/create_mass_estimate_requests.rb
|
216
|
-
- spec/
|
217
|
-
- spec/
|
213
|
+
- spec/factories/order_responses.rb
|
214
|
+
- spec/factories/allocations.rb
|
215
|
+
- spec/factories/orders.rb
|
216
|
+
- spec/factories/create_order_requests.rb
|
217
|
+
- spec/factories/estimate_responses.rb
|
218
218
|
- spec/integration/orders_spec.rb
|
219
|
+
- spec/integration/preferences_spec.rb
|
220
|
+
- spec/integration/estimates_spec.rb
|
219
221
|
- spec/integration/projects_spec.rb
|
220
|
-
- spec/models/order_list_response_spec.rb
|
221
|
-
- spec/models/allocation_spec.rb
|
222
|
-
- spec/models/order_response_spec.rb
|
223
|
-
- spec/models/preference_list_response_spec.rb
|
224
222
|
- spec/models/create_preference_request_spec.rb
|
223
|
+
- spec/models/preference_spec.rb
|
224
|
+
- spec/models/estimate_response_spec.rb
|
225
|
+
- spec/models/error_response_spec.rb
|
225
226
|
- spec/models/estimate_list_response_spec.rb
|
227
|
+
- spec/models/create_mass_estimate_request_spec.rb
|
226
228
|
- spec/models/project_spec.rb
|
229
|
+
- spec/models/order_spec.rb
|
230
|
+
- spec/models/preference_response_spec.rb
|
231
|
+
- spec/models/order_list_response_spec.rb
|
227
232
|
- spec/models/project_list_response_spec.rb
|
228
|
-
- spec/models/estimate_response_spec.rb
|
229
|
-
- spec/models/preference_spec.rb
|
230
|
-
- spec/models/create_order_request_spec.rb
|
231
|
-
- spec/models/create_mass_estimate_request_spec.rb
|
232
233
|
- spec/models/project_response_spec.rb
|
233
|
-
- spec/models/order_spec.rb
|
234
|
-
- spec/models/error_response_spec.rb
|
235
234
|
- spec/models/estimate_spec.rb
|
236
235
|
- spec/models/meta_index_object_spec.rb
|
237
|
-
- spec/models/
|
236
|
+
- spec/models/order_response_spec.rb
|
237
|
+
- spec/models/preference_list_response_spec.rb
|
238
|
+
- spec/models/allocation_spec.rb
|
239
|
+
- spec/models/create_order_request_spec.rb
|
238
240
|
- spec/patch_ruby_spec.rb
|
239
241
|
- spec/spec_helper.rb
|
240
242
|
- spec/support/shared/generated_classes.rb
|