Skip to content

Commit 88e34d0

Browse files
authored
Merge pull request #20 from patch-technology/lovisa/version-1.2.6
[v1.3.0] Add Flight/Shipping/Vehicle estimates
2 parents d0d3893 + c4ee047 commit 88e34d0

File tree

11 files changed

+308
-11
lines changed

11 files changed

+308
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ 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-
## [Unreleased]
8+
## [1.3.0] - 2021-02-08
9+
10+
### Added
11+
12+
- Adds support for creating carbon emission estimates for flights, shipping, and vehicles. See the [docs](https://docs.usepatch.com/#/?id=estimates) for more information.
913

1014
## [1.2.5] - 2020-01-08
1115

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.2.5)
4+
patch_ruby (1.3.0)
55
json (~> 2.1, >= 2.1.0)
66
typhoeus (~> 1.0, >= 1.0.1)
77

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,36 @@ Estimates allow API users to get a quote for the cost of compensating a certain
9898

9999
#### Examples
100100
```ruby
101-
# Create an estimate
101+
# Create a mass estimate
102102
mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
103103
Patch::Estimate.create_mass_estimate(mass_g: mass)
104104

105+
# Create a flight estimate
106+
distance_m = 1_000_000 # Pass in the distance traveled in meters
107+
Patch::Estimate.create_flight_estimate(distance_m: distance_m)
108+
109+
# Create a shipping estimate
110+
distance_m = 1_000_000 # Pass in the shipping distance in meters
111+
package_mass_g = 10_000 # Pass in the weight of the package shipped in grams
112+
transportation_method = "air" # Pass in the transportation method (air, rail, road, sea)
113+
Patch::Estimate.create_shipping_estimate(
114+
distance_m: distance_m,
115+
package_mass_g: package_mass_g,
116+
transportation_method: transportation_method
117+
)
118+
119+
# Create a vehicle estimate
120+
distance_m = 1_000_000 # Pass in the shipping distance in meters
121+
make = "Toyota" # Pass in the car make
122+
model = "Corolla" # Pass in the car model
123+
year = 2000 # Pass in the car year
124+
Patch::Estimate.create_vehicle_estimate(
125+
distance_m: distance_m,
126+
make: make,
127+
model: model,
128+
year: year
129+
)
130+
105131
## You can also specify a project-id field (optional) to be used instead of the preferred one
106132
project_id = 'pro_test_1234' # Pass in the project's ID
107133
Patch::Estimate.create_mass_estimate(mass_g: mass, project_id: project_id)

lib/patch_ruby/api/estimates_api.rb

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
module Patch
1616
class EstimatesApi
1717
OPERATIONS = [
18+
:create_flight_estimate,
1819
:create_mass_estimate,
20+
:create_shipping_estimate,
21+
:create_vehicle_estimate,
1922
:retrieve_estimate,
2023
:retrieve_estimates,
2124
]
@@ -25,6 +28,70 @@ class EstimatesApi
2528
def initialize(api_client = ApiClient.default)
2629
@api_client = api_client
2730
end
31+
# Create a flight estimate given the distance traveled in meters
32+
# 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+
# @param create_flight_estimate_request [CreateFlightEstimateRequest]
34+
# @param [Hash] opts the optional parameters
35+
# @return [EstimateResponse]
36+
def create_flight_estimate(create_flight_estimate_request, opts = {})
37+
data, _status_code, _headers = create_flight_estimate_with_http_info(create_flight_estimate_request, opts)
38+
data
39+
end
40+
41+
# Create a flight estimate given the distance traveled in meters
42+
# 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.
43+
# @param create_flight_estimate_request [CreateFlightEstimateRequest]
44+
# @param [Hash] opts the optional parameters
45+
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
46+
def create_flight_estimate_with_http_info(create_flight_estimate_request, opts = {})
47+
if @api_client.config.debugging
48+
@api_client.config.logger.debug 'Calling API: EstimatesApi.create_flight_estimate ...'
49+
end
50+
# verify the required parameter 'create_flight_estimate_request' is set
51+
if @api_client.config.client_side_validation && create_flight_estimate_request.nil?
52+
fail ArgumentError, "Missing the required parameter 'create_flight_estimate_request' when calling EstimatesApi.create_flight_estimate"
53+
end
54+
# resource path
55+
local_var_path = '/v1/estimates/flight'
56+
57+
# query parameters
58+
query_params = opts[:query_params] || {}
59+
60+
# header parameters
61+
header_params = opts[:header_params] || {}
62+
# HTTP header 'Accept' (if needed)
63+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
64+
# HTTP header 'Content-Type'
65+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
66+
67+
# form parameters
68+
form_params = opts[:form_params] || {}
69+
70+
# http body (model)
71+
post_body = opts[:body] || @api_client.object_to_http_body(create_flight_estimate_request)
72+
73+
# return_type
74+
return_type = opts[:return_type] || 'EstimateResponse'
75+
76+
# auth_names
77+
auth_names = opts[:auth_names] || ['bearer_auth']
78+
79+
new_options = opts.merge(
80+
:header_params => header_params,
81+
:query_params => query_params,
82+
:form_params => form_params,
83+
:body => post_body,
84+
:auth_names => auth_names,
85+
:return_type => return_type
86+
)
87+
88+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
89+
if @api_client.config.debugging
90+
@api_client.config.logger.debug "API called: EstimatesApi#create_flight_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
91+
end
92+
return data, status_code, headers
93+
end
94+
2895
# Create an estimate based on mass of CO2
2996
# Creates an estimate for the mass of CO2 to be compensated. An order in the `draft` state will also be created, linked to the estimate.
3097
# @param create_mass_estimate_request [CreateMassEstimateRequest]
@@ -89,6 +156,134 @@ def create_mass_estimate_with_http_info(create_mass_estimate_request, opts = {})
89156
return data, status_code, headers
90157
end
91158

159+
# Create a shipping estimate given the distance traveled in meters, package weight, and transportation method.
160+
# Creates a shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters.
161+
# @param create_shipping_estimate_request [CreateShippingEstimateRequest]
162+
# @param [Hash] opts the optional parameters
163+
# @return [EstimateResponse]
164+
def create_shipping_estimate(create_shipping_estimate_request, opts = {})
165+
data, _status_code, _headers = create_shipping_estimate_with_http_info(create_shipping_estimate_request, opts)
166+
data
167+
end
168+
169+
# Create a shipping estimate given the distance traveled in meters, package weight, and transportation method.
170+
# Creates a shipping estimate for the amount of CO2 to be compensated. An order in the &#x60;draft&#x60; state may be created based on the parameters.
171+
# @param create_shipping_estimate_request [CreateShippingEstimateRequest]
172+
# @param [Hash] opts the optional parameters
173+
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
174+
def create_shipping_estimate_with_http_info(create_shipping_estimate_request, opts = {})
175+
if @api_client.config.debugging
176+
@api_client.config.logger.debug 'Calling API: EstimatesApi.create_shipping_estimate ...'
177+
end
178+
# verify the required parameter 'create_shipping_estimate_request' is set
179+
if @api_client.config.client_side_validation && create_shipping_estimate_request.nil?
180+
fail ArgumentError, "Missing the required parameter 'create_shipping_estimate_request' when calling EstimatesApi.create_shipping_estimate"
181+
end
182+
# resource path
183+
local_var_path = '/v1/estimates/shipping'
184+
185+
# query parameters
186+
query_params = opts[:query_params] || {}
187+
188+
# header parameters
189+
header_params = opts[:header_params] || {}
190+
# HTTP header 'Accept' (if needed)
191+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
192+
# HTTP header 'Content-Type'
193+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
194+
195+
# form parameters
196+
form_params = opts[:form_params] || {}
197+
198+
# http body (model)
199+
post_body = opts[:body] || @api_client.object_to_http_body(create_shipping_estimate_request)
200+
201+
# return_type
202+
return_type = opts[:return_type] || 'EstimateResponse'
203+
204+
# auth_names
205+
auth_names = opts[:auth_names] || ['bearer_auth']
206+
207+
new_options = opts.merge(
208+
:header_params => header_params,
209+
:query_params => query_params,
210+
:form_params => form_params,
211+
:body => post_body,
212+
:auth_names => auth_names,
213+
:return_type => return_type
214+
)
215+
216+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
217+
if @api_client.config.debugging
218+
@api_client.config.logger.debug "API called: EstimatesApi#create_shipping_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
219+
end
220+
return data, status_code, headers
221+
end
222+
223+
# Create a vehicle estimate given the distance traveled in meters and the type of vehicle
224+
# Creates an estimate and calculates the amount of CO2 to be compensated depending on the distance and the vehicle. An order in the `draft` state may be created based on the parameters, linked to the estimate.
225+
# @param create_vehicle_estimate_request [CreateVehicleEstimateRequest]
226+
# @param [Hash] opts the optional parameters
227+
# @return [EstimateResponse]
228+
def create_vehicle_estimate(create_vehicle_estimate_request, opts = {})
229+
data, _status_code, _headers = create_vehicle_estimate_with_http_info(create_vehicle_estimate_request, opts)
230+
data
231+
end
232+
233+
# Create a vehicle estimate given the distance traveled in meters and the type of vehicle
234+
# Creates an estimate and calculates the amount of CO2 to be compensated depending on the distance and the vehicle. An order in the &#x60;draft&#x60; state may be created based on the parameters, linked to the estimate.
235+
# @param create_vehicle_estimate_request [CreateVehicleEstimateRequest]
236+
# @param [Hash] opts the optional parameters
237+
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
238+
def create_vehicle_estimate_with_http_info(create_vehicle_estimate_request, opts = {})
239+
if @api_client.config.debugging
240+
@api_client.config.logger.debug 'Calling API: EstimatesApi.create_vehicle_estimate ...'
241+
end
242+
# verify the required parameter 'create_vehicle_estimate_request' is set
243+
if @api_client.config.client_side_validation && create_vehicle_estimate_request.nil?
244+
fail ArgumentError, "Missing the required parameter 'create_vehicle_estimate_request' when calling EstimatesApi.create_vehicle_estimate"
245+
end
246+
# resource path
247+
local_var_path = '/v1/estimates/vehicle'
248+
249+
# query parameters
250+
query_params = opts[:query_params] || {}
251+
252+
# header parameters
253+
header_params = opts[:header_params] || {}
254+
# HTTP header 'Accept' (if needed)
255+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
256+
# HTTP header 'Content-Type'
257+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
258+
259+
# form parameters
260+
form_params = opts[:form_params] || {}
261+
262+
# http body (model)
263+
post_body = opts[:body] || @api_client.object_to_http_body(create_vehicle_estimate_request)
264+
265+
# return_type
266+
return_type = opts[:return_type] || 'EstimateResponse'
267+
268+
# auth_names
269+
auth_names = opts[:auth_names] || ['bearer_auth']
270+
271+
new_options = opts.merge(
272+
:header_params => header_params,
273+
:query_params => query_params,
274+
:form_params => form_params,
275+
:body => post_body,
276+
:auth_names => auth_names,
277+
:return_type => return_type
278+
)
279+
280+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
281+
if @api_client.config.debugging
282+
@api_client.config.logger.debug "API called: EstimatesApi#create_vehicle_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
283+
end
284+
return data, status_code, headers
285+
end
286+
92287
# Retrieves an estimate
93288
# Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for.
94289
# @param id [String]

lib/patch_ruby/models/create_mass_estimate_request.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ module Patch
1616
class CreateMassEstimateRequest
1717
attr_accessor :mass_g
1818

19+
attr_accessor :create_order
20+
1921
attr_accessor :project_id
2022

2123
# Attribute mapping from ruby-style variable name to JSON key.
2224
def self.attribute_map
2325
{
2426
:'mass_g' => :'mass_g',
27+
:'create_order' => :'create_order',
2528
:'project_id' => :'project_id'
2629
}
2730
end
@@ -30,6 +33,7 @@ def self.attribute_map
3033
def self.openapi_types
3134
{
3235
:'mass_g' => :'Integer',
36+
:'create_order' => :'Boolean',
3337
:'project_id' => :'String'
3438
}
3539
end
@@ -38,6 +42,8 @@ def self.openapi_types
3842
def self.openapi_nullable
3943
nullable_properties = Set.new
4044

45+
nullable_properties.add("create_order")
46+
4147
nullable_properties
4248
end
4349

@@ -71,6 +77,10 @@ def initialize(attributes = {})
7177
self.mass_g = attributes[:'mass_g']
7278
end
7379

80+
if attributes.key?(:'create_order')
81+
self.create_order = attributes[:'create_order']
82+
end
83+
7484
if attributes.key?(:'project_id')
7585
self.project_id = attributes[:'project_id']
7686
end
@@ -128,6 +138,7 @@ def ==(o)
128138
return true if self.equal?(o)
129139
self.class == o.class &&
130140
mass_g == o.mass_g &&
141+
create_order == o.create_order &&
131142
project_id == o.project_id
132143
end
133144

@@ -140,7 +151,7 @@ def eql?(o)
140151
# Calculates hash code according to all attributes.
141152
# @return [Integer] Hash code
142153
def hash
143-
[mass_g, project_id].hash
154+
[mass_g, create_order, project_id].hash
144155
end
145156

146157
# Builds the object from hash

0 commit comments

Comments
 (0)