patch_ruby 1.2.3 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -3
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +19 -3
  5. data/README.md +86 -9
  6. data/lib/patch_ruby/api/estimates_api.rb +195 -0
  7. data/lib/patch_ruby/api/projects_api.rb +9 -0
  8. data/lib/patch_ruby/configuration.rb +2 -2
  9. data/lib/patch_ruby/models/allocation.rb +10 -0
  10. data/lib/patch_ruby/models/create_mass_estimate_request.rb +19 -1
  11. data/lib/patch_ruby/models/create_order_request.rb +38 -16
  12. data/lib/patch_ruby/models/create_preference_request.rb +7 -0
  13. data/lib/patch_ruby/models/error_response.rb +9 -0
  14. data/lib/patch_ruby/models/estimate.rb +24 -1
  15. data/lib/patch_ruby/models/estimate_list_response.rb +9 -0
  16. data/lib/patch_ruby/models/estimate_response.rb +9 -0
  17. data/lib/patch_ruby/models/meta_index_object.rb +11 -0
  18. data/lib/patch_ruby/models/order.rb +20 -0
  19. data/lib/patch_ruby/models/order_list_response.rb +9 -0
  20. data/lib/patch_ruby/models/order_response.rb +9 -0
  21. data/lib/patch_ruby/models/photo.rb +25 -4
  22. data/lib/patch_ruby/models/preference.rb +10 -0
  23. data/lib/patch_ruby/models/preference_list_response.rb +9 -0
  24. data/lib/patch_ruby/models/preference_response.rb +9 -0
  25. data/lib/patch_ruby/models/project.rb +40 -4
  26. data/lib/patch_ruby/models/project_list_response.rb +9 -0
  27. data/lib/patch_ruby/models/project_response.rb +9 -0
  28. data/lib/patch_ruby/models/sdg.rb +269 -0
  29. data/lib/patch_ruby/models/standard.rb +10 -0
  30. data/lib/patch_ruby/version.rb +1 -1
  31. data/patch_ruby.gemspec +1 -1
  32. data/spec/configuration_spec.rb +3 -3
  33. data/spec/factories/allocations.rb +7 -0
  34. data/spec/factories/create_mass_estimate_requests.rb +6 -0
  35. data/spec/factories/create_order_requests.rb +8 -0
  36. data/spec/factories/create_preference_requests.rb +5 -0
  37. data/spec/factories/error_responses.rb +7 -0
  38. data/spec/factories/estimate_list_responses.rb +8 -0
  39. data/spec/factories/estimate_responses.rb +7 -0
  40. data/spec/factories/estimates.rb +8 -0
  41. data/spec/factories/meta_index_objects.rb +6 -0
  42. data/spec/factories/order_list_responses.rb +8 -0
  43. data/spec/factories/order_responses.rb +7 -0
  44. data/spec/factories/orders.rb +12 -0
  45. data/spec/factories/preference_list_responses.rb +8 -0
  46. data/spec/factories/preference_responses.rb +7 -0
  47. data/spec/factories/preferences.rb +7 -0
  48. data/spec/factories/project_list_responses.rb +8 -0
  49. data/spec/factories/project_responses.rb +7 -0
  50. data/spec/factories/projects.rb +15 -0
  51. data/spec/integration/estimates_spec.rb +52 -8
  52. data/spec/integration/orders_spec.rb +26 -0
  53. data/spec/integration/preferences_spec.rb +6 -2
  54. data/spec/integration/projects_spec.rb +20 -0
  55. data/spec/models/allocation_spec.rb +8 -1
  56. data/spec/models/create_mass_estimate_request_spec.rb +7 -1
  57. data/spec/models/create_order_request_spec.rb +7 -1
  58. data/spec/models/create_preference_request_spec.rb +8 -1
  59. data/spec/models/error_response_spec.rb +7 -1
  60. data/spec/models/estimate_list_response_spec.rb +7 -1
  61. data/spec/models/estimate_response_spec.rb +7 -1
  62. data/spec/models/estimate_spec.rb +8 -1
  63. data/spec/models/meta_index_object_spec.rb +7 -1
  64. data/spec/models/order_list_response_spec.rb +7 -1
  65. data/spec/models/order_response_spec.rb +7 -1
  66. data/spec/models/order_spec.rb +18 -1
  67. data/spec/models/preference_list_response_spec.rb +7 -1
  68. data/spec/models/preference_response_spec.rb +7 -1
  69. data/spec/models/preference_spec.rb +7 -1
  70. data/spec/models/project_list_response_spec.rb +7 -1
  71. data/spec/models/project_response_spec.rb +7 -1
  72. data/spec/models/project_spec.rb +21 -1
  73. data/spec/spec_helper.rb +10 -0
  74. data/spec/support/shared/generated_classes.rb +13 -0
  75. metadata +56 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5a1eec7fccc6caad29eefa746c0318b3ee7c2b52ff3694e999bb1bf8086595a
4
- data.tar.gz: f3acf2fe8fdf86c68b9d4bce4b4e399e9137aae7414fac9e89f96ddecd8f25a5
3
+ metadata.gz: dad4b825fa4e046cac94a1672e5b89d5fc1edd0ab48e414d35449e71137a1b01
4
+ data.tar.gz: 8a23b9c1d27d6dd8b32da5f064e7aaef3bd4c2452d3b9e4934c2dd9877d97c6b
5
5
  SHA512:
6
- metadata.gz: 5e21d7cb2d176d1b5620f1d44a1c2df35cdea882e888ec7a894dbeb1991734508fe54f2b9be71153022d5f29755925d2e06217f9c50c1405471bed819efd4ded
7
- data.tar.gz: c10d3372f00070ede5a70b39fe248c5065d8e5fd8fb1ef890add6581fa6ab374487d8594728d437d8aacf34e4b9cba0c71c0de69c89e4eb0259750f55140e621
6
+ metadata.gz: ee4a8a1abc63aea00bff1b795340ab44bad333e539f89d39733d74d8645907796afdbc2a72f0ab93a84bdde82ec2d9dc825c8fe7ebd3715337fc82a606edab12
7
+ data.tar.gz: 96376448d26040c8ce8be567a9ff9110964f1fb380ab7852029274508ce2b9ab599a809f927918dd0661dc153f2eee6f03315f4486b3ce7d4ebadf76e08cc951
data/CHANGELOG.md CHANGED
@@ -5,9 +5,50 @@ 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
- ## [Unreleased]
8
+ ## [1.5.0] - 2021-03-01
9
9
 
10
- ## [1.2.3] - 2020-09-28
10
+ ### Changed
11
+
12
+ - Changed base URL from https://api.usepatch.com to https://api.patch.io
13
+
14
+ ## [1.4.0] - 2021-02-15
15
+
16
+ ### Added
17
+
18
+ - Adds Sustainable Development Goals (SDGs) field to projects
19
+ - Adds filtering to Projects by country, type, minimum_available_mass
20
+
21
+ ### Changed
22
+
23
+ - vehicle estimates now support optional `make`, `model` and `year` fields.
24
+
25
+ ## [1.3.0] - 2021-02-08
26
+
27
+ ### Added
28
+
29
+ - Adds support for creating carbon emission estimates for flights, shipping, and vehicles. See the [docs](https://docs.patch.io/#/?id=estimates) for more information.
30
+
31
+ ## [1.2.5] - 2020-01-08
32
+
33
+ ### Fixed
34
+
35
+ - Fixes [issues/5](https://github.com/patch-technology/patch-ruby/issues/5). Adds method `.openapi_nullable` which returns a set with all nullable properties. This method is referenced in `#to_hash` which returns a hash representation of the resource.
36
+ - Removes non-deterministic integration spec that is creating an Estimate with a specific project-id. Since we do not control the test data (yet) and make queries against our Test projects, we cannot be sure that we will have offsets available for a project ID. Instead we can rely on Patch core specs to cover this.
37
+ - Fixes a spec that was failing due to a Patch core change.
38
+ - Add spec factories and refactor generated method specs to shared examples.
39
+
40
+ ## [1.2.4] - 2020-10-14
41
+
42
+ ### Added
43
+
44
+ - `total_price_cents_usd` field to `orders`
45
+ - allows users to create an order by total price
46
+
47
+ ### Changed
48
+
49
+ - order creation requires either `mass_g` or `total_price_cents_usd`, but not both
50
+
51
+ ## [1.2.3] - 2020-10-05
11
52
 
12
53
  ### Added
13
54
 
@@ -55,4 +96,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55
96
 
56
97
  - Pre-release of v1 Gem
57
98
  - Adds support for Orders, Estimates, Projects and Preferences
58
-
data/Gemfile CHANGED
@@ -6,4 +6,5 @@ group :development, :test do
6
6
  gem 'rake', '~> 13.0.1'
7
7
  gem 'pry-byebug'
8
8
  gem 'rubocop'
9
+ gem 'factory_bot'
9
10
  end
data/Gemfile.lock CHANGED
@@ -1,22 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- patch_ruby (1.2.3)
4
+ patch_ruby (1.4.0)
5
5
  json (~> 2.1, >= 2.1.0)
6
6
  typhoeus (~> 1.0, >= 1.0.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ activesupport (6.1.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
11
17
  ast (2.4.1)
12
18
  byebug (11.1.3)
13
19
  coderay (1.1.3)
20
+ concurrent-ruby (1.1.7)
14
21
  diff-lcs (1.4.3)
15
22
  ethon (0.12.0)
16
23
  ffi (>= 1.3.0)
17
- ffi (1.13.1)
18
- json (2.3.1)
24
+ factory_bot (6.1.0)
25
+ activesupport (>= 5.0.0)
26
+ ffi (1.14.2)
27
+ i18n (1.8.7)
28
+ concurrent-ruby (~> 1.0)
29
+ json (2.5.1)
19
30
  method_source (1.0.0)
31
+ minitest (5.14.3)
20
32
  parallel (1.19.2)
21
33
  parser (2.7.1.4)
22
34
  ast (~> 2.4.1)
@@ -57,12 +69,16 @@ GEM
57
69
  ruby-progressbar (1.10.1)
58
70
  typhoeus (1.4.0)
59
71
  ethon (>= 0.9.0)
72
+ tzinfo (2.0.4)
73
+ concurrent-ruby (~> 1.0)
60
74
  unicode-display_width (1.7.0)
75
+ zeitwerk (2.4.2)
61
76
 
62
77
  PLATFORMS
63
78
  ruby
64
79
 
65
80
  DEPENDENCIES
81
+ factory_bot
66
82
  patch_ruby!
67
83
  pry-byebug
68
84
  rake (~> 13.0.1)
data/README.md CHANGED
@@ -1,31 +1,37 @@
1
1
  # Patch Ruby SDK
2
+
2
3
  ![Test](https://github.com/patch-technology/patch-ruby/workflows/Test/badge.svg)
3
4
  [![Gem Version](https://badge.fury.io/rb/patch_ruby.svg)](https://badge.fury.io/rb/patch_ruby)
4
5
  [![Discord](https://img.shields.io/discord/733029448558837792)](https://discord.gg/AU8543D)
5
6
 
6
- The official Ruby gem for the [Patch API](https://www.usepatch.com)
7
+ The official Ruby gem for the [Patch API](https://www.patch.io)
7
8
 
8
9
  ## Documentation
9
- For a complete API reference, check out [Patch's API Reference.](https://docs.usepatch.com/)
10
+
11
+ For a complete API reference, check out [Patch's API Reference.](https://docs.patch.io/)
10
12
 
11
13
  ## Installation
12
14
 
13
15
  Add the gem to your Gemfile:
16
+
14
17
  ```ruby
15
18
  gem 'patch_ruby'
16
19
  ```
17
20
 
18
21
  Then run:
22
+
19
23
  ```shell
20
24
  bundle
21
25
  ```
22
26
 
23
27
  Or install it directly with
28
+
24
29
  ```shell
25
30
  gem install patch_ruby
26
31
  ```
27
32
 
28
33
  ### Requirements
34
+
29
35
  - Ruby 1.9+
30
36
 
31
37
  ## Usage
@@ -33,6 +39,7 @@ gem install patch_ruby
33
39
  ### Configuration
34
40
 
35
41
  After installing the gem, you'll have to configure it with your API key which is available from the API key page in the Patch dashboard:
42
+
36
43
  ```ruby
37
44
  require 'patch_ruby'
38
45
 
@@ -43,16 +50,31 @@ end
43
50
  ```
44
51
 
45
52
  ### Orders
53
+
46
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.
47
55
 
48
- [API Reference](https://docs.usepatch.com/#/?id=orders)
56
+ In Patch, orders represent a purchase of carbon offsets or negative emissions by mass.
57
+ Place orders directly if you know the amount of carbon dioxide you would like to sequester.
58
+ If you do not know how much to purchase, use an estimate.
59
+ You can also create an order with a maximum desired price, and we'll allocate enough mass to
60
+ fulfill the order for you.
61
+
62
+ [API Reference](https://docs.patch.io/#/?id=orders)
49
63
 
50
64
  #### Examples
65
+
51
66
  ```ruby
52
- # Create an order
67
+ # Create an order - you can create an order
68
+ # providing either mass_g or total_price_cents_usd, but not both
69
+
70
+ # Create order with mass
53
71
  mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
54
72
  Patch::Order.create_order(mass_g: mass)
55
73
 
74
+ # Create an order with maximum total price
75
+ total_price_cents_usd = 5_00 # Pass in the total price in cents (i.e. 5 dollars)
76
+ Patch::Order.create_order(total_price_cents_usd: total_price_cents_usd)
77
+
56
78
  ## You can also specify a project-id field (optional) to be used instead of the preferred one
57
79
  project_id = 'pro_test_1234' # Pass in the project's ID
58
80
  Patch::Order.create_order(mass_g: mass, project_id: project_id)
@@ -79,16 +101,44 @@ Patch::Order.retrieve_orders(page: page)
79
101
  ```
80
102
 
81
103
  ### Estimates
104
+
82
105
  Estimates allow API users to get a quote for the cost of compensating a certain amount of CO2. When creating an estimate, an order in the `draft` state will also be created, reserving the allocation of a project for 5 minutes. If you don't place your draft order within those 5 minutes, the order will automatically be cancelled.
83
106
 
84
- [API Reference](https://docs.usepatch.com/#/?id=estimates)
107
+ [API Reference](https://docs.patch.io/#/?id=estimates)
85
108
 
86
109
  #### Examples
110
+
87
111
  ```ruby
88
- # Create an estimate
112
+ # Create a mass estimate
89
113
  mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
90
114
  Patch::Estimate.create_mass_estimate(mass_g: mass)
91
115
 
116
+ # Create a flight estimate
117
+ distance_m = 1_000_000 # Pass in the distance traveled in meters
118
+ Patch::Estimate.create_flight_estimate(distance_m: distance_m)
119
+
120
+ # Create a shipping estimate
121
+ distance_m = 1_000_000 # Pass in the shipping distance in meters
122
+ package_mass_g = 10_000 # Pass in the weight of the package shipped in grams
123
+ transportation_method = "air" # Pass in the transportation method (air, rail, road, sea)
124
+ Patch::Estimate.create_shipping_estimate(
125
+ distance_m: distance_m,
126
+ package_mass_g: package_mass_g,
127
+ transportation_method: transportation_method
128
+ )
129
+
130
+ # Create a vehicle estimate
131
+ distance_m = 1_000_000 # Pass in the shipping distance in meters
132
+ make = "Toyota" # Pass in the car make
133
+ model = "Corolla" # Pass in the car model
134
+ year = 2000 # Pass in the car year
135
+ Patch::Estimate.create_vehicle_estimate(
136
+ distance_m: distance_m,
137
+ make: make,
138
+ model: model,
139
+ year: year
140
+ )
141
+
92
142
  ## You can also specify a project-id field (optional) to be used instead of the preferred one
93
143
  project_id = 'pro_test_1234' # Pass in the project's ID
94
144
  Patch::Estimate.create_mass_estimate(mass_g: mass, project_id: project_id)
@@ -103,11 +153,19 @@ Patch::Estimate.retrieve_estimates(page: page)
103
153
  ```
104
154
 
105
155
  ### Projects
156
+
106
157
  Projects are the ways Patch takes CO2 out of the air. They can represent reforestation, enhanced weathering, direct air carbon capture, etc. When you place an order via Patch, it is allocated to a project.
107
158
 
108
- [API Reference](https://docs.usepatch.com/#/?id=projects)
159
+ When fetching Projects, you can add filters to the query to narrow the result. Currently supported filters are:
160
+
161
+ - `country`
162
+ - `type`
163
+ - `minimum_available_mass`
164
+
165
+ [API Reference](https://docs.patch.io/#/?id=projects)
109
166
 
110
167
  #### Examples
168
+
111
169
  ```ruby
112
170
  # Retrieve a project
113
171
  project_id = 'pro_test_1234' # Pass in the project's ID
@@ -116,14 +174,28 @@ Patch::Project.retrieve_project(project_id)
116
174
  # Retrieve a list of projects
117
175
  page = 1 # Pass in which page of projects you'd like
118
176
  Patch::Project.retrieve_projects(page: page)
177
+
178
+ # Retrieve all projects from the United States
179
+ country = 'US'
180
+ Patch::Project.retrieve_projects(country: country)
181
+
182
+ # Retrieve all biomass projects
183
+ type = 'biomass'
184
+ Patch::Project.retrieve_projects(type: type)
185
+
186
+ # Retrieve a list of projects with at least 100 grams of available offsets
187
+ minimum_available_mass = 100
188
+ Patch::Project.retrieve_projects(minimum_available_mass: minimum_available_mass)
119
189
  ```
120
190
 
121
191
  ### Preferences
122
- Preferences are how you route your orders in Patch. If you don't have a preference, Patch will allocate your order to the least expensive option. If you do have a preference, all of your orders will be sent to that project. You can set your preferences via API, or through the [Patch Dashboard](https://dashboard.usepatch.com/projects).
123
192
 
124
- [API Reference](https://docs.usepatch.com/#/?id=preferences)
193
+ Preferences are how you route your orders in Patch. If you don't have a preference, Patch will allocate your order to the least expensive option. If you do have a preference, all of your orders will be sent to that project. You can set your preferences via API, or through the [Patch Dashboard](https://dashboard.patch.io/projects).
194
+
195
+ [API Reference](https://docs.patch.io/#/?id=preferences)
125
196
 
126
197
  #### Examples
198
+
127
199
  ```ruby
128
200
  # Create a preference
129
201
  project_id = 'pro_test_1234' # Pass in the project_id for your preference
@@ -145,26 +217,31 @@ Patch::Preference.retrieve_preferences(page: page)
145
217
  ## Development
146
218
 
147
219
  To build the gem locally, run:
220
+
148
221
  ```
149
222
  $ gem build patch_ruby.gemspec
150
223
  ```
151
224
 
152
225
  This will create a .gem file. To install the local gem:
226
+
153
227
  ```
154
228
  $ gem install patch_ruby-1.x.x.gem
155
229
  ```
156
230
 
157
231
  Install dependencies:
232
+
158
233
  ```
159
234
  $ bundle install
160
235
  ```
161
236
 
162
237
  Set up required environment variables:
238
+
163
239
  ```
164
240
  $ export SANDBOX_API_KEY=<SANDBOX API KEY>
165
241
  ```
166
242
 
167
243
  Run tests:
244
+
168
245
  ```
169
246
  $ bundle exec rspec
170
247
  ```
@@ -15,7 +15,10 @@ require 'cgi'
15
15
  module Patch
16
16
  class EstimatesApi
17
17
  OPERATIONS = [
18
+ :create_flight_estimate,
18
19
  :create_mass_estimate,
20
+ :create_shipping_estimate,
21
+ :create_vehicle_estimate,
19
22
  :retrieve_estimate,
20
23
  :retrieve_estimates,
21
24
  ]
@@ -25,6 +28,70 @@ module Patch
25
28
  def initialize(api_client = ApiClient.default)
26
29
  @api_client = api_client
27
30
  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 &#x60;draft&#x60; 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
+
28
95
  # Create an estimate based on mass of CO2
29
96
  # 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.
30
97
  # @param create_mass_estimate_request [CreateMassEstimateRequest]
@@ -89,6 +156,134 @@ module Patch
89
156
  return data, status_code, headers
90
157
  end
91
158
 
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
+
92
287
  # Retrieves an estimate
93
288
  # Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for.
94
289
  # @param id [String]