Skip to content

Commit 8112fed

Browse files
committed
Add models
1 parent 050daf5 commit 8112fed

File tree

5 files changed

+334
-5
lines changed

5 files changed

+334
-5
lines changed

lib/patch_ruby.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
# Models
2020
require 'patch_ruby/models/allocation'
21+
require 'patch_ruby/models/create_bitcoin_estimate_request'
2122
require 'patch_ruby/models/create_mass_estimate_request'
2223
require 'patch_ruby/models/create_order_request'
2324
require 'patch_ruby/models/create_preference_request'

lib/patch_ruby/api/estimates_api.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
module Patch
1616
class EstimatesApi
1717
OPERATIONS = [
18+
:create_bitcoin_estimate,
1819
:create_flight_estimate,
1920
:create_mass_estimate,
2021
:create_shipping_estimate,
@@ -28,6 +29,70 @@ class EstimatesApi
2829
def initialize(api_client = ApiClient.default)
2930
@api_client = api_client
3031
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 `draft` 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+
3196
# Create a flight estimate given the distance traveled in meters
3297
# 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.
3398
# @param create_flight_estimate_request [CreateFlightEstimateRequest]

lib/patch_ruby/api/orders_api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def initialize(api_client = ApiClient.default)
2828
@api_client = api_client
2929
end
3030
# 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.
3232
# @param id [String]
3333
# @param [Hash] opts the optional parameters
3434
# @return [OrderResponse]
@@ -38,7 +38,7 @@ def cancel_order(id, opts = {})
3838
end
3939

4040
# 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.
4242
# @param id [String]
4343
# @param [Hash] opts the optional parameters
4444
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
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 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 commit comments

Comments
 (0)