patch_ruby 1.7.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38a97b1d48e2a6ae9a50749434d02046c07d2c29f719294f62a30f6de392ec32
4
- data.tar.gz: 5c2fdd1a90d0e41f9ada976ad4f7bdbfdbe5926cfc6892f183aee3d241ab8f3f
3
+ metadata.gz: 7ab75a1c077e255f54aa542b15eefc55ae4125994a71d8138be99a0534c1a5bd
4
+ data.tar.gz: f0cd837fc4ed2187a775a01d33711b4d54b16ca30f992386305b32a81a159c1c
5
5
  SHA512:
6
- metadata.gz: 22a036eb09ecd66937e745b0403af743bb25c712fa9c485be9dfdf4f2762247e47a0c0df5a21d5701073983af4de64abffd24889415a3f2c5b53ca4b695150e1
7
- data.tar.gz: a183b61d3de80803aae094ab765f97c19d3fd01afec70335b839d3af7796577d320c4141b25ebc0d9c732d820ecd8c8d55c4f3d8b1e7f704cc07b3347fd843ec
6
+ metadata.gz: a6706f4e0965eaa1edbed707a18609f04e85e5de5808d8ab95646a5c8d63c95cdbcb0d1b7dc7859270bbb098f28e6e094ca973b9ff13c403c08982a4d6292aea
7
+ data.tar.gz: 4fcf46077c53e8e79c72d5a2caf88200b39e9c6297c67b6709c86dcc6572e3f559332bff888872e1b2b8e4827fefd829a3990045232b89f83841bae0d7e65490
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ 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
+
8
14
  ## [1.7.0] - 2021-07-14
9
15
 
10
16
  ### Changed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- patch_ruby (1.7.0)
4
+ patch_ruby (1.8.0)
5
5
  json (~> 2.1, >= 2.1.0)
6
6
  typhoeus (~> 1.0, >= 1.0.1)
7
7
 
data/lib/patch_ruby.rb CHANGED
@@ -19,6 +19,7 @@ require 'patch_ruby/configuration'
19
19
  # Models
20
20
  require 'patch_ruby/models/allocation'
21
21
  require 'patch_ruby/models/create_bitcoin_estimate_request'
22
+ require 'patch_ruby/models/create_ethereum_estimate_request'
22
23
  require 'patch_ruby/models/create_mass_estimate_request'
23
24
  require 'patch_ruby/models/create_order_request'
24
25
  require 'patch_ruby/models/create_preference_request'
@@ -16,6 +16,7 @@ module Patch
16
16
  class EstimatesApi
17
17
  OPERATIONS = [
18
18
  :create_bitcoin_estimate,
19
+ :create_ethereum_estimate,
19
20
  :create_flight_estimate,
20
21
  :create_mass_estimate,
21
22
  :create_shipping_estimate,
@@ -30,7 +31,7 @@ module Patch
30
31
  @api_client = api_client
31
32
  end
32
33
  # 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
+ # 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
35
  # @param create_bitcoin_estimate_request [CreateBitcoinEstimateRequest]
35
36
  # @param [Hash] opts the optional parameters
36
37
  # @return [EstimateResponse]
@@ -40,7 +41,7 @@ module Patch
40
41
  end
41
42
 
42
43
  # Create a bitcoin estimate given a timestamp and transaction value
43
- # Creates a bitcoin estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate.
44
+ # Creates a bitcoin estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate.
44
45
  # @param create_bitcoin_estimate_request [CreateBitcoinEstimateRequest]
45
46
  # @param [Hash] opts the optional parameters
46
47
  # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
@@ -93,6 +94,70 @@ module Patch
93
94
  return data, status_code, headers
94
95
  end
95
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 &#x60;draft&#x60; 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
+
96
161
  # Create a flight estimate given the distance traveled in meters
97
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.
98
163
  # @param create_flight_estimate_request [CreateFlightEstimateRequest]
@@ -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
@@ -11,5 +11,5 @@ OpenAPI Generator version: 4.3.1
11
11
  =end
12
12
 
13
13
  module Patch
14
- VERSION = '1.7.0'
14
+ VERSION = '1.8.0'
15
15
  end
@@ -99,4 +99,37 @@ RSpec.describe 'Estimates Integration' do
99
99
  expect(bitcoin_estimate.data.type).to eq 'bitcoin'
100
100
  expect(bitcoin_estimate.data.mass_g).to be < bitcoin_estimate_2.data.mass_g
101
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
102
135
  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.7.0
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-07-14 00:00:00.000000000 Z
11
+ date: 2021-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -93,6 +93,7 @@ files:
93
93
  - lib/patch_ruby/configuration.rb
94
94
  - lib/patch_ruby/models/allocation.rb
95
95
  - lib/patch_ruby/models/create_bitcoin_estimate_request.rb
96
+ - lib/patch_ruby/models/create_ethereum_estimate_request.rb
96
97
  - lib/patch_ruby/models/create_mass_estimate_request.rb
97
98
  - lib/patch_ruby/models/create_order_request.rb
98
99
  - lib/patch_ruby/models/create_preference_request.rb