patch_ruby 1.5.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dad4b825fa4e046cac94a1672e5b89d5fc1edd0ab48e414d35449e71137a1b01
4
- data.tar.gz: 8a23b9c1d27d6dd8b32da5f064e7aaef3bd4c2452d3b9e4934c2dd9877d97c6b
3
+ metadata.gz: 38a97b1d48e2a6ae9a50749434d02046c07d2c29f719294f62a30f6de392ec32
4
+ data.tar.gz: 5c2fdd1a90d0e41f9ada976ad4f7bdbfdbe5926cfc6892f183aee3d241ab8f3f
5
5
  SHA512:
6
- metadata.gz: ee4a8a1abc63aea00bff1b795340ab44bad333e539f89d39733d74d8645907796afdbc2a72f0ab93a84bdde82ec2d9dc825c8fe7ebd3715337fc82a606edab12
7
- data.tar.gz: 96376448d26040c8ce8be567a9ff9110964f1fb380ab7852029274508ce2b9ab599a809f927918dd0661dc153f2eee6f03315f4486b3ce7d4ebadf76e08cc951
6
+ metadata.gz: 22a036eb09ecd66937e745b0403af743bb25c712fa9c485be9dfdf4f2762247e47a0c0df5a21d5701073983af4de64abffd24889415a3f2c5b53ca4b695150e1
7
+ data.tar.gz: a183b61d3de80803aae094ab765f97c19d3fd01afec70335b839d3af7796577d320c4141b25ebc0d9c732d820ecd8c8d55c4f3d8b1e7f704cc07b3347fd843ec
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.7.0] - 2021-07-14
9
+
10
+ ### Changed
11
+
12
+ - [BREAKING] Changed `order.price_cents_usd` and `order.patch_fee_cents_usd` from string to integer.
13
+
14
+ ## [1.6.0] - 2021-07-14
15
+
16
+ ### Added
17
+
18
+ - Order responses return a `registry_url` field
19
+ - Add support for Bitcoin estimates
20
+
21
+ ## [1.5.2] - 2021-03-30
22
+
23
+ ### Changed
24
+
25
+ - Updated the value validation for certain parameters to match the API
26
+ - Added the `renewables` type
27
+
28
+ ## [1.5.1] - 2021-03-02
29
+
30
+ ### Fixed
31
+
32
+ - Fixed a `NameError` that was thrown when `Patch::Sdg` was called. Specs have been added to ensure this does not happen again.
33
+
8
34
  ## [1.5.0] - 2021-03-01
9
35
 
10
36
  ### Changed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- patch_ruby (1.4.0)
4
+ patch_ruby (1.7.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.12.0)
23
- ffi (>= 1.3.0)
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.14.2)
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.1.4
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
- $ gem build patch_ruby.gemspec
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
- $ gem install patch_ruby-1.x.x.gem
231
+ ```bash
232
+ gem install patch_ruby-1.x.x.gem
229
233
  ```
230
234
 
231
235
  Install dependencies:
232
236
 
233
- ```
234
- $ bundle install
237
+ ```bash
238
+ bundle install
235
239
  ```
236
240
 
237
241
  Set up required environment variables:
238
242
 
239
- ```
240
- $ export SANDBOX_API_KEY=<SANDBOX API KEY>
243
+ ```bash
244
+ export SANDBOX_API_KEY=<SANDBOX API KEY>
241
245
  ```
242
246
 
243
247
  Run tests:
244
248
 
245
- ```
246
- $ bundle exec rspec
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'
@@ -36,6 +37,7 @@ require 'patch_ruby/models/preference_response'
36
37
  require 'patch_ruby/models/project'
37
38
  require 'patch_ruby/models/project_list_response'
38
39
  require 'patch_ruby/models/project_response'
40
+ require 'patch_ruby/models/sdg'
39
41
  require 'patch_ruby/models/standard'
40
42
 
41
43
  # APIs
@@ -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 &#x60;draft&#x60; 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 &#x60;draft&#x60; 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 &#x60;draft&#x60; or &#x60;placed&#x60; 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
@@ -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 < 1
102
- invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 1.')
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 < 1
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 < 1
129
- fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 1.'
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 < 1
104
- invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 1.')
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 < 1
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 < 1
131
- fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 1.'
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' => :'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
@@ -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 < 1
189
- invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 1.')
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 < 1
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 < 1
246
- fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 1.'
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
@@ -11,5 +11,5 @@ OpenAPI Generator version: 4.3.1
11
11
  =end
12
12
 
13
13
  module Patch
14
- VERSION = '1.5.0'
14
+ VERSION = '1.7.0'
15
15
  end
@@ -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
@@ -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(create_order_response.data.id).not_to be_nil
45
- expect(create_order_response.data.mass_g).to eq(order_mass_g)
46
- expect(create_order_response.data.price_cents_usd.to_i).to eq(expected_price)
47
- expect(create_order_response.data.patch_fee_cents_usd).not_to be_empty
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 = 5_00
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.mass_g).to eq(5_00_000)
69
- expect(order.price_cents_usd).not_to be_empty
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
@@ -0,0 +1,18 @@
1
+ describe Patch do
2
+ context 'Models' do
3
+ it 'defines all models' do
4
+ constants.each do |constant|
5
+ expect { Patch.const_get(constant) }.not_to raise_error
6
+ end
7
+ end
8
+ end
9
+
10
+ def constants
11
+ # Given a file path return the constant of that path, for example:
12
+ # 'lib/patch_ruby/models/project_response.rb' -> ProjectResponse
13
+ Dir.glob("lib/patch_ruby/models/*.rb").map do |file|
14
+ parsed_filename = file.split('/').last.split('.').first
15
+ constant = parsed_filename.split('_').map(&:capitalize).join('')
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patch_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.7.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-03-01 00:00:00.000000000 Z
11
+ date: 2021-07-14 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
@@ -161,6 +162,7 @@ files:
161
162
  - spec/models/project_list_response_spec.rb
162
163
  - spec/models/project_response_spec.rb
163
164
  - spec/models/project_spec.rb
165
+ - spec/patch_ruby_spec.rb
164
166
  - spec/spec_helper.rb
165
167
  - spec/support/shared/generated_classes.rb
166
168
  homepage: https://www.patch.io
@@ -187,52 +189,53 @@ signing_key:
187
189
  specification_version: 4
188
190
  summary: Ruby wrapper for the Patch API
189
191
  test_files:
190
- - spec/api/orders_api_spec.rb
192
+ - spec/api/preferences_api_spec.rb
191
193
  - spec/api/projects_api_spec.rb
192
194
  - spec/api/estimates_api_spec.rb
193
- - spec/api/preferences_api_spec.rb
195
+ - spec/api/orders_api_spec.rb
194
196
  - spec/api_client_spec.rb
195
197
  - spec/configuration_spec.rb
196
198
  - spec/constants.rb
197
- - spec/factories/project_responses.rb
198
- - spec/factories/create_preference_requests.rb
199
- - spec/factories/meta_index_objects.rb
200
- - spec/factories/project_list_responses.rb
201
- - spec/factories/orders.rb
202
199
  - spec/factories/order_list_responses.rb
203
- - spec/factories/order_responses.rb
204
200
  - spec/factories/preferences.rb
205
- - spec/factories/preference_responses.rb
206
- - spec/factories/error_responses.rb
201
+ - spec/factories/project_responses.rb
207
202
  - spec/factories/estimates.rb
203
+ - spec/factories/preference_responses.rb
208
204
  - spec/factories/estimate_list_responses.rb
209
- - spec/factories/create_order_requests.rb
210
- - spec/factories/allocations.rb
211
- - spec/factories/projects.rb
212
- - spec/factories/estimate_responses.rb
205
+ - spec/factories/create_preference_requests.rb
206
+ - spec/factories/project_list_responses.rb
207
+ - spec/factories/error_responses.rb
208
+ - spec/factories/meta_index_objects.rb
213
209
  - spec/factories/preference_list_responses.rb
210
+ - spec/factories/projects.rb
214
211
  - spec/factories/create_mass_estimate_requests.rb
215
- - spec/integration/estimates_spec.rb
216
- - spec/integration/preferences_spec.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
+ - spec/integration/preferences_spec.rb
219
+ - spec/integration/estimates_spec.rb
218
220
  - spec/integration/projects_spec.rb
219
- - spec/models/order_list_response_spec.rb
220
- - spec/models/allocation_spec.rb
221
- - spec/models/order_response_spec.rb
222
- - spec/models/preference_list_response_spec.rb
223
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
224
225
  - spec/models/estimate_list_response_spec.rb
226
+ - spec/models/create_mass_estimate_request_spec.rb
225
227
  - spec/models/project_spec.rb
228
+ - spec/models/order_spec.rb
229
+ - spec/models/preference_response_spec.rb
230
+ - spec/models/order_list_response_spec.rb
226
231
  - spec/models/project_list_response_spec.rb
227
- - spec/models/estimate_response_spec.rb
228
- - spec/models/preference_spec.rb
229
- - spec/models/create_order_request_spec.rb
230
- - spec/models/create_mass_estimate_request_spec.rb
231
232
  - spec/models/project_response_spec.rb
232
- - spec/models/order_spec.rb
233
- - spec/models/error_response_spec.rb
234
233
  - spec/models/estimate_spec.rb
235
234
  - spec/models/meta_index_object_spec.rb
236
- - spec/models/preference_response_spec.rb
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
239
+ - spec/patch_ruby_spec.rb
237
240
  - spec/spec_helper.rb
238
241
  - spec/support/shared/generated_classes.rb