patch_ruby 1.20.0 → 1.21.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: 8e38c237237f243dcdefd64f39b87d2f052f5df647ba2c160971f68757bfdfc4
4
- data.tar.gz: b129e13caef807d8c28ec975173881fb78a39df1a2c979d55958e3409a262f8d
3
+ metadata.gz: 6e90b99f33c3f3a2115590dba9caffe9335da298a1bb4fb362496e31d87c8f6e
4
+ data.tar.gz: 86a32f5775dd5d23fa61b5ac2617f6ff65ff1a487d9deb19bcf5f27752dc5dad
5
5
  SHA512:
6
- metadata.gz: 8b2e3c8486b47e5a3b7c7f7fd773f83773ffcab9da7c11d0fa04ea0ec29127179b81d76d68e383a2a4816aeb26fef7e23243e2c32b8b48b09f285e1d0f235383
7
- data.tar.gz: 0a7d3ce9b60026bfaab7687785e34f4397e7d7c4fb5fe4095b8003918f32cae12bfe092ef426b6ba580ad5cfafae408b02fd2b06675600a400249496294146f7
6
+ metadata.gz: 8f85ec5d3bb14d15411ae9b75da0d0e4655d599dec6144128801b05c3f5a8984f644de5fb0c95065d7c1e7c1adf73f4c4d5af24c0ff216291866b020ffeecc13
7
+ data.tar.gz: 9cd5df665fe03ff82e9f1d6b49d48dc7378cea330c023d38572d89cadc537cf58464eb0ef88c2c195e99f953ad79135c954632f0c9864709b41b8fa31e3529d6
data/CHANGELOG.md CHANGED
@@ -5,6 +5,21 @@ 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.21.0] - 2022-05-03
9
+
10
+ ### Added
11
+
12
+ - Adds optional `total_price` and `currency` field to `order` creation
13
+ - Adds optional `amount` and `unit` field to `order` creation
14
+ - Adds inventory to `project` responses
15
+ - Adds inventory to `order` responses
16
+
17
+ ### Changed
18
+
19
+ - Deprecates `mass_g` and `total_price_cents_usd` fields for create `order` requests
20
+ - Deprecates `average_price_per_tonne_cents_usd` and `remaining_mass_g` from `project` responses
21
+ - Deprecates `price_cents_usd`, `patch_fee_cents_usd`, and `mass_g` from `order` responses
22
+
8
23
  ## [1.20.0] - 2022-04-18
9
24
 
10
25
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- patch_ruby (1.20.0)
4
+ patch_ruby (1.21.0)
5
5
  typhoeus (~> 1.0, >= 1.0.1)
6
6
 
7
7
  GEM
@@ -73,6 +73,7 @@ PLATFORMS
73
73
  arm64-darwin-20
74
74
  arm64-darwin-21
75
75
  x86_64-darwin-20
76
+ x86_64-linux
76
77
 
77
78
  DEPENDENCIES
78
79
  factory_bot (~> 6.2)
data/README.md CHANGED
@@ -51,9 +51,9 @@ end
51
51
 
52
52
  ### Orders
53
53
 
54
- In Patch, orders represent a purchase of carbon offsets or negative emissions by mass. Place orders directly if you know the amount of carbon dioxide you would like to sequester. If you do not know how much to purchase, use an estimate.
54
+ In Patch, orders represent a purchase of carbon offsets or negative emissions by amount. Place orders directly if you know the amount of carbon dioxide you would like to sequester. If you do not know how much to purchase, use an estimate.
55
55
 
56
- You can also create an order with a maximum desired price, and we'll allocate enough mass to
56
+ You can also create an order with a maximum desired price, and we'll allocate enough to
57
57
  fulfill the order for you.
58
58
 
59
59
  [API Reference](https://docs.patch.io/#/?id=orders)
@@ -62,23 +62,25 @@ fulfill the order for you.
62
62
 
63
63
  ```ruby
64
64
  # Create an order - you can create an order
65
- # providing either mass_g or total_price_cents_usd, but not both
65
+ # providing either amount (and unit) or total_price (and currency), but not both
66
66
 
67
- # Create order with mass
68
- mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
69
- Patch::Order.create_order(mass_g: mass)
67
+ # Create order with amount
68
+ amount = 1_000_000 # Pass in the amount in unit specified
69
+ unit = "g"
70
+ Patch::Order.create_order(amount: amount, unit: unit)
70
71
 
71
- # Create an order with maximum total price
72
- total_price_cents_usd = 5_00 # Pass in the total price in cents (i.e. 5 dollars)
73
- Patch::Order.create_order(total_price_cents_usd: total_price_cents_usd)
72
+ # Create an order with total price
73
+ total_price = 5_00 # Pass in the total price in smallest currency unit (ie cents for USD).
74
+ currency = "USD"
75
+ Patch::Order.create_order(total_price: total_price, currency: currency)
74
76
 
75
77
  ## You can also specify a project-id field (optional) to be used instead of the preferred one
76
78
  project_id = 'pro_test_1234' # Pass in the project's ID
77
- Patch::Order.create_order(mass_g: mass, project_id: project_id)
79
+ Patch::Order.create_order(amount: amount, unit: unit, project_id: project_id)
78
80
 
79
81
  ## Orders also accept a metadata field (optional)
80
82
  metadata = {user: "john doe"}
81
- Patch::Order.create_order(mass_g: mass, metadata: metadata)
83
+ Patch::Order.create_order(amount: amount, unit: unit, metadata: metadata)
82
84
 
83
85
  # Retrieve an order
84
86
  order_id = 'ord_test_1234' # Pass in the order's id
@@ -31,7 +31,7 @@ module Patch
31
31
  # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
32
32
  def initialize(config = Configuration.default)
33
33
  @config = config
34
- @user_agent = "patch-ruby/1.20.0"
34
+ @user_agent = "patch-ruby/1.21.0"
35
35
  @default_headers = {
36
36
  'Content-Type' => 'application/json',
37
37
  'User-Agent' => @user_agent
@@ -27,6 +27,14 @@ module Patch
27
27
 
28
28
  attr_accessor :vintage_year
29
29
 
30
+ attr_accessor :total_price
31
+
32
+ attr_accessor :currency
33
+
34
+ attr_accessor :amount
35
+
36
+ attr_accessor :unit
37
+
30
38
  class EnumAttributeValidator
31
39
  attr_reader :datatype
32
40
  attr_reader :allowable_values
@@ -57,7 +65,11 @@ module Patch
57
65
  :'project_id' => :'project_id',
58
66
  :'metadata' => :'metadata',
59
67
  :'state' => :'state',
60
- :'vintage_year' => :'vintage_year'
68
+ :'vintage_year' => :'vintage_year',
69
+ :'total_price' => :'total_price',
70
+ :'currency' => :'currency',
71
+ :'amount' => :'amount',
72
+ :'unit' => :'unit'
61
73
  }
62
74
  end
63
75
 
@@ -74,7 +86,11 @@ module Patch
74
86
  :'project_id' => :'String',
75
87
  :'metadata' => :'Object',
76
88
  :'state' => :'String',
77
- :'vintage_year' => :'Integer'
89
+ :'vintage_year' => :'Integer',
90
+ :'total_price' => :'Integer',
91
+ :'currency' => :'String',
92
+ :'amount' => :'Integer',
93
+ :'unit' => :'String'
78
94
  }
79
95
  end
80
96
 
@@ -86,7 +102,11 @@ module Patch
86
102
  :'project_id',
87
103
  :'metadata',
88
104
  :'state',
89
- :'vintage_year'
105
+ :'vintage_year',
106
+ :'total_price',
107
+ :'currency',
108
+ :'amount',
109
+ :'unit'
90
110
  ])
91
111
  end
92
112
 
@@ -140,6 +160,22 @@ module Patch
140
160
  if attributes.key?(:'vintage_year')
141
161
  self.vintage_year = attributes[:'vintage_year']
142
162
  end
163
+
164
+ if attributes.key?(:'total_price')
165
+ self.total_price = attributes[:'total_price']
166
+ end
167
+
168
+ if attributes.key?(:'currency')
169
+ self.currency = attributes[:'currency']
170
+ end
171
+
172
+ if attributes.key?(:'amount')
173
+ self.amount = attributes[:'amount']
174
+ end
175
+
176
+ if attributes.key?(:'unit')
177
+ self.unit = attributes[:'unit']
178
+ end
143
179
  end
144
180
 
145
181
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -166,6 +202,18 @@ module Patch
166
202
  invalid_properties.push('invalid value for "vintage_year", must be greater than or equal to 1900.')
167
203
  end
168
204
 
205
+ if !@total_price.nil? && @total_price < 1
206
+ invalid_properties.push('invalid value for "total_price", must be greater than or equal to 1.')
207
+ end
208
+
209
+ if !@amount.nil? && @amount > 100000000000
210
+ invalid_properties.push('invalid value for "amount", must be smaller than or equal to 100000000000.')
211
+ end
212
+
213
+ if !@amount.nil? && @amount < 0
214
+ invalid_properties.push('invalid value for "amount", must be greater than or equal to 0.')
215
+ end
216
+
169
217
  invalid_properties
170
218
  end
171
219
 
@@ -179,6 +227,11 @@ module Patch
179
227
  return false unless state_validator.valid?(@state)
180
228
  return false if !@vintage_year.nil? && @vintage_year > 2100
181
229
  return false if !@vintage_year.nil? && @vintage_year < 1900
230
+ return false if !@total_price.nil? && @total_price < 1
231
+ return false if !@amount.nil? && @amount > 100000000000
232
+ return false if !@amount.nil? && @amount < 0
233
+ unit_validator = EnumAttributeValidator.new('String', ["g", "Wh"])
234
+ return false unless unit_validator.valid?(@unit)
182
235
  true
183
236
  end
184
237
 
@@ -230,6 +283,40 @@ module Patch
230
283
  @vintage_year = vintage_year
231
284
  end
232
285
 
286
+ # Custom attribute writer method with validation
287
+ # @param [Object] total_price Value to be assigned
288
+ def total_price=(total_price)
289
+ if !total_price.nil? && total_price < 1
290
+ fail ArgumentError, 'invalid value for "total_price", must be greater than or equal to 1.'
291
+ end
292
+
293
+ @total_price = total_price
294
+ end
295
+
296
+ # Custom attribute writer method with validation
297
+ # @param [Object] amount Value to be assigned
298
+ def amount=(amount)
299
+ if !amount.nil? && amount > 100000000000
300
+ fail ArgumentError, 'invalid value for "amount", must be smaller than or equal to 100000000000.'
301
+ end
302
+
303
+ if !amount.nil? && amount < 0
304
+ fail ArgumentError, 'invalid value for "amount", must be greater than or equal to 0.'
305
+ end
306
+
307
+ @amount = amount
308
+ end
309
+
310
+ # Custom attribute writer method checking allowed values (enum).
311
+ # @param [Object] unit Object to be assigned
312
+ def unit=(unit)
313
+ validator = EnumAttributeValidator.new('String', ["g", "Wh"])
314
+ unless validator.valid?(unit)
315
+ fail ArgumentError, "invalid value for \"unit\", must be one of #{validator.allowable_values}."
316
+ end
317
+ @unit = unit
318
+ end
319
+
233
320
  # Checks equality by comparing each attribute.
234
321
  # @param [Object] Object to be compared
235
322
  def ==(o)
@@ -240,7 +327,11 @@ module Patch
240
327
  project_id == o.project_id &&
241
328
  metadata == o.metadata &&
242
329
  state == o.state &&
243
- vintage_year == o.vintage_year
330
+ vintage_year == o.vintage_year &&
331
+ total_price == o.total_price &&
332
+ currency == o.currency &&
333
+ amount == o.amount &&
334
+ unit == o.unit
244
335
  end
245
336
 
246
337
  # @see the `==` method
@@ -252,7 +343,7 @@ module Patch
252
343
  # Calculates hash code according to all attributes.
253
344
  # @return [Integer] Hash code
254
345
  def hash
255
- [mass_g, total_price_cents_usd, project_id, metadata, state, vintage_year].hash
346
+ [mass_g, total_price_cents_usd, project_id, metadata, state, vintage_year, total_price, currency, amount, unit].hash
256
347
  end
257
348
 
258
349
  # Builds the object from hash
@@ -0,0 +1,294 @@
1
+ =begin
2
+ #Patch API V1
3
+
4
+ #The core API used to integrate with Patch's service
5
+
6
+ The version of the OpenAPI document: v1
7
+ Contact: engineering@usepatch.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Patch
17
+ class Inventory
18
+ # The year in which the climate impacts of the project occurred, or will occur.
19
+ attr_accessor :vintage_year
20
+
21
+ # The amount available for this vintage year.
22
+ attr_accessor :amount_available
23
+
24
+ # The price per tonne (1,000,000 g) or MWh (1,000,000 Wh) of inventory. Prices are always represented in the smallest currency unit (ie cents for USD).
25
+ attr_accessor :price
26
+
27
+ # The currency code for `price`.
28
+ attr_accessor :currency
29
+
30
+ # The unit of measurement (ie \"g\" or \"Wh\") for `amount_available`.
31
+ attr_accessor :unit
32
+
33
+ # Attribute mapping from ruby-style variable name to JSON key.
34
+ def self.attribute_map
35
+ {
36
+ :'vintage_year' => :'vintage_year',
37
+ :'amount_available' => :'amount_available',
38
+ :'price' => :'price',
39
+ :'currency' => :'currency',
40
+ :'unit' => :'unit'
41
+ }
42
+ end
43
+
44
+ # Returns all the JSON keys this model knows about
45
+ def self.acceptable_attributes
46
+ attribute_map.values
47
+ end
48
+
49
+ # Attribute type mapping.
50
+ def self.openapi_types
51
+ {
52
+ :'vintage_year' => :'Integer',
53
+ :'amount_available' => :'Integer',
54
+ :'price' => :'Integer',
55
+ :'currency' => :'String',
56
+ :'unit' => :'String'
57
+ }
58
+ end
59
+
60
+ # List of attributes with nullable: true
61
+ def self.openapi_nullable
62
+ Set.new([
63
+ ])
64
+ end
65
+
66
+
67
+ # Allows models with corresponding API classes to delegate API operations to those API classes
68
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
69
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
70
+ def self.method_missing(message, *args, &block)
71
+ if Object.const_defined?('Patch::InventorysApi::OPERATIONS') && Patch::InventorysApi::OPERATIONS.include?(message)
72
+ Patch::InventorysApi.new.send(message, *args)
73
+ else
74
+ super
75
+ end
76
+ end
77
+
78
+ # Initializes the object
79
+ # @param [Hash] attributes Model attributes in the form of hash
80
+ def initialize(attributes = {})
81
+ if (!attributes.is_a?(Hash))
82
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::Inventory` initialize method"
83
+ end
84
+
85
+ # check to see if the attribute exists and convert string to symbol for hash key
86
+ attributes = attributes.each_with_object({}) { |(k, v), h|
87
+ if (!self.class.attribute_map.key?(k.to_sym))
88
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::Inventory`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
89
+ end
90
+ h[k.to_sym] = v
91
+ }
92
+
93
+ if attributes.key?(:'vintage_year')
94
+ self.vintage_year = attributes[:'vintage_year']
95
+ end
96
+
97
+ if attributes.key?(:'amount_available')
98
+ self.amount_available = attributes[:'amount_available']
99
+ end
100
+
101
+ if attributes.key?(:'price')
102
+ self.price = attributes[:'price']
103
+ end
104
+
105
+ if attributes.key?(:'currency')
106
+ self.currency = attributes[:'currency']
107
+ end
108
+
109
+ if attributes.key?(:'unit')
110
+ self.unit = attributes[:'unit']
111
+ end
112
+ end
113
+
114
+ # Show invalid properties with the reasons. Usually used together with valid?
115
+ # @return Array for valid properties with the reasons
116
+ def list_invalid_properties
117
+ invalid_properties = Array.new
118
+ if @vintage_year.nil?
119
+ invalid_properties.push('invalid value for "vintage_year", vintage_year cannot be nil.')
120
+ end
121
+
122
+ if @amount_available.nil?
123
+ invalid_properties.push('invalid value for "amount_available", amount_available cannot be nil.')
124
+ end
125
+
126
+ if @price.nil?
127
+ invalid_properties.push('invalid value for "price", price cannot be nil.')
128
+ end
129
+
130
+ if @currency.nil?
131
+ invalid_properties.push('invalid value for "currency", currency cannot be nil.')
132
+ end
133
+
134
+ if @unit.nil?
135
+ invalid_properties.push('invalid value for "unit", unit cannot be nil.')
136
+ end
137
+
138
+ invalid_properties
139
+ end
140
+
141
+ # Check to see if the all the properties in the model are valid
142
+ # @return true if the model is valid
143
+ def valid?
144
+ return false if @vintage_year.nil?
145
+ return false if @amount_available.nil?
146
+ return false if @price.nil?
147
+ return false if @currency.nil?
148
+ return false if @unit.nil?
149
+ true
150
+ end
151
+
152
+ # Checks equality by comparing each attribute.
153
+ # @param [Object] Object to be compared
154
+ def ==(o)
155
+ return true if self.equal?(o)
156
+ self.class == o.class &&
157
+ vintage_year == o.vintage_year &&
158
+ amount_available == o.amount_available &&
159
+ price == o.price &&
160
+ currency == o.currency &&
161
+ unit == o.unit
162
+ end
163
+
164
+ # @see the `==` method
165
+ # @param [Object] Object to be compared
166
+ def eql?(o)
167
+ self == o
168
+ end
169
+
170
+ # Calculates hash code according to all attributes.
171
+ # @return [Integer] Hash code
172
+ def hash
173
+ [vintage_year, amount_available, price, currency, unit].hash
174
+ end
175
+
176
+ # Builds the object from hash
177
+ # @param [Hash] attributes Model attributes in the form of hash
178
+ # @return [Object] Returns the model itself
179
+ def self.build_from_hash(attributes)
180
+ new.build_from_hash(attributes)
181
+ end
182
+
183
+ # Builds the object from hash
184
+ # @param [Hash] attributes Model attributes in the form of hash
185
+ # @return [Object] Returns the model itself
186
+ def build_from_hash(attributes)
187
+ return nil unless attributes.is_a?(Hash)
188
+ self.class.openapi_types.each_pair do |key, type|
189
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
190
+ self.send("#{key}=", nil)
191
+ elsif type =~ /\AArray<(.*)>/i
192
+ # check to ensure the input is an array given that the attribute
193
+ # is documented as an array but the input is not
194
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
195
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
196
+ end
197
+ elsif !attributes[self.class.attribute_map[key]].nil?
198
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
199
+ end
200
+ end
201
+
202
+ self
203
+ end
204
+
205
+ # Deserializes the data based on type
206
+ # @param string type Data type
207
+ # @param string value Value to be deserialized
208
+ # @return [Object] Deserialized data
209
+ def _deserialize(type, value)
210
+ case type.to_sym
211
+ when :Time
212
+ Time.parse(value)
213
+ when :Date
214
+ Date.parse(value)
215
+ when :String
216
+ value.to_s
217
+ when :Integer
218
+ value.to_i
219
+ when :Float
220
+ value.to_f
221
+ when :Boolean
222
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
223
+ true
224
+ else
225
+ false
226
+ end
227
+ when :Object
228
+ # generic object (usually a Hash), return directly
229
+ value
230
+ when /\AArray<(?<inner_type>.+)>\z/
231
+ inner_type = Regexp.last_match[:inner_type]
232
+ value.map { |v| _deserialize(inner_type, v) }
233
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
234
+ k_type = Regexp.last_match[:k_type]
235
+ v_type = Regexp.last_match[:v_type]
236
+ {}.tap do |hash|
237
+ value.each do |k, v|
238
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
239
+ end
240
+ end
241
+ else # model
242
+ # models (e.g. Pet) or oneOf
243
+ klass = Patch.const_get(type)
244
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
245
+ end
246
+ end
247
+
248
+ # Returns the string representation of the object
249
+ # @return [String] String presentation of the object
250
+ def to_s
251
+ to_hash.to_s
252
+ end
253
+
254
+ # to_body is an alias to to_hash (backward compatibility)
255
+ # @return [Hash] Returns the object in the form of hash
256
+ def to_body
257
+ to_hash
258
+ end
259
+
260
+ # Returns the object in the form of hash
261
+ # @return [Hash] Returns the object in the form of hash
262
+ def to_hash
263
+ hash = {}
264
+ self.class.attribute_map.each_pair do |attr, param|
265
+ value = self.send(attr)
266
+ if value.nil?
267
+ is_nullable = self.class.openapi_nullable.include?(attr)
268
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
269
+ end
270
+
271
+ hash[param] = _to_hash(value)
272
+ end
273
+ hash
274
+ end
275
+
276
+ # Outputs non-array value in the form of hash
277
+ # For object, use to_hash. Otherwise, just return the value
278
+ # @param [Object] value Any valid value
279
+ # @return [Hash] Returns the value in the form of hash
280
+ def _to_hash(value)
281
+ if value.is_a?(Array)
282
+ value.compact.map { |v| _to_hash(v) }
283
+ elsif value.is_a?(Hash)
284
+ {}.tap do |hash|
285
+ value.each { |k, v| hash[k] = _to_hash(v) }
286
+ end
287
+ elsif value.respond_to? :to_hash
288
+ value.to_hash
289
+ else
290
+ value
291
+ end
292
+ end
293
+ end
294
+ end