Skip to content

Commit 8f3adf9

Browse files
authored
Merge pull request #33 from patch-technology/pc/171
Add ETH estimates
2 parents c28dd53 + 6350103 commit 8f3adf9

File tree

7 files changed

+362
-4
lines changed

7 files changed

+362
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.8.0] - 2021-07-20
9+
10+
### Added
11+
12+
- Add support for Ethereum estimates
13+
814
## [1.7.0] - 2021-07-14
915

1016
### Changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
patch_ruby (1.7.0)
4+
patch_ruby (1.8.0)
55
json (~> 2.1, >= 2.1.0)
66
typhoeus (~> 1.0, >= 1.0.1)
77

lib/patch_ruby.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# Models
2020
require 'patch_ruby/models/allocation'
2121
require 'patch_ruby/models/create_bitcoin_estimate_request'
22+
require 'patch_ruby/models/create_ethereum_estimate_request'
2223
require 'patch_ruby/models/create_mass_estimate_request'
2324
require 'patch_ruby/models/create_order_request'
2425
require 'patch_ruby/models/create_preference_request'

lib/patch_ruby/api/estimates_api.rb

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Patch
1616
class EstimatesApi
1717
OPERATIONS = [
1818
:create_bitcoin_estimate,
19+
:create_ethereum_estimate,
1920
:create_flight_estimate,
2021
:create_mass_estimate,
2122
:create_shipping_estimate,
@@ -30,7 +31,7 @@ def initialize(api_client = ApiClient.default)
3031
@api_client = api_client
3132
end
3233
# 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.
3435
# @param create_bitcoin_estimate_request [CreateBitcoinEstimateRequest]
3536
# @param [Hash] opts the optional parameters
3637
# @return [EstimateResponse]
@@ -40,7 +41,7 @@ def create_bitcoin_estimate(create_bitcoin_estimate_request, opts = {})
4041
end
4142

4243
# 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.
4445
# @param create_bitcoin_estimate_request [CreateBitcoinEstimateRequest]
4546
# @param [Hash] opts the optional parameters
4647
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
@@ -93,6 +94,70 @@ def create_bitcoin_estimate_with_http_info(create_bitcoin_estimate_request, opts
9394
return data, status_code, headers
9495
end
9596

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+
96161
# Create a flight estimate given the distance traveled in meters
97162
# 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.
98163
# @param create_flight_estimate_request [CreateFlightEstimateRequest]
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
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

lib/patch_ruby/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
=end
1212

1313
module Patch
14-
VERSION = '1.7.0'
14+
VERSION = '1.8.0'
1515
end

0 commit comments

Comments
 (0)