Skip to content

Commit a68186a

Browse files
authored
Integration Specs (#1)
- Adds integration specs to test each endpoint and pagination for endpoints that support it - Uses VCR to prevent calls to the actual API. - Regenerates code to add estimates, the new `meta` schema, required `responseBody` for create operations, and request objects.
1 parent 896276e commit a68186a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3777
-49
lines changed

.github/workflows/test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ jobs:
2222
run: bundle install
2323

2424
- name: Run RSpec
25+
env:
26+
PATCH_RUBY_HOST: 'https://api.staging-patch.com/'
27+
PATCH_RUBY_API_KEY: 'key_test_1234'
2528
run: bundle exec rspec
2629

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ group :development, :test do
66
gem 'rake', '~> 13.0.1'
77
gem 'pry-byebug'
88
gem 'rubocop', '~> 0.66.0'
9+
gem 'vcr', '~> 6.0'
910
end

Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ GEM
5555
typhoeus (1.4.0)
5656
ethon (>= 0.9.0)
5757
unicode-display_width (1.5.0)
58+
vcr (6.0.0)
5859

5960
PLATFORMS
6061
ruby
@@ -65,6 +66,7 @@ DEPENDENCIES
6566
rake (~> 13.0.1)
6667
rspec (~> 3.6, >= 3.6.0)
6768
rubocop (~> 0.66.0)
69+
vcr (~> 6.0)
6870

6971
BUNDLED WITH
7072
2.1.4

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ require 'patch_ruby'
3535

3636
Patch.configure do |config|
3737
# Configure the Patch gem with your API key here
38-
config.access_token = 'key_test_1234'
38+
config.access_token = ENV['PATCH_RUBY_API_KEY']
3939
end
4040
```
4141

lib/patch_ruby.rb

+8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@
1818

1919
# Models
2020
require 'patch_ruby/models/allocation'
21+
require 'patch_ruby/models/create_mass_estimate_request'
22+
require 'patch_ruby/models/create_order_request'
23+
require 'patch_ruby/models/create_preference_request'
2124
require 'patch_ruby/models/error_response'
25+
require 'patch_ruby/models/estimate'
26+
require 'patch_ruby/models/estimate_list_response'
27+
require 'patch_ruby/models/estimate_response'
28+
require 'patch_ruby/models/meta_index_object'
2229
require 'patch_ruby/models/order'
2330
require 'patch_ruby/models/order_list_response'
2431
require 'patch_ruby/models/order_response'
@@ -30,6 +37,7 @@
3037
require 'patch_ruby/models/project_response'
3138

3239
# APIs
40+
require 'patch_ruby/api/estimates_api'
3341
require 'patch_ruby/api/orders_api'
3442
require 'patch_ruby/api/preferences_api'
3543
require 'patch_ruby/api/projects_api'

lib/patch_ruby/api/estimates_api.rb

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
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 'cgi'
14+
15+
module Patch
16+
class EstimatesApi
17+
OPERATIONS = [
18+
:create_mass_estimate,
19+
:retrieve_estimate,
20+
:retrieve_estimates,
21+
]
22+
23+
attr_accessor :api_client
24+
25+
def initialize(api_client = ApiClient.default)
26+
@api_client = api_client
27+
end
28+
# Create an estimate based on mass of CO2
29+
# 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+
# @param create_mass_estimate_request [CreateMassEstimateRequest]
31+
# @param [Hash] opts the optional parameters
32+
# @return [EstimateResponse]
33+
def create_mass_estimate(create_mass_estimate_request, opts = {})
34+
data, _status_code, _headers = create_mass_estimate_with_http_info(create_mass_estimate_request, opts)
35+
data
36+
end
37+
38+
# Create an estimate based on mass of CO2
39+
# 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.
40+
# @param create_mass_estimate_request [CreateMassEstimateRequest]
41+
# @param [Hash] opts the optional parameters
42+
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
43+
def create_mass_estimate_with_http_info(create_mass_estimate_request, opts = {})
44+
if @api_client.config.debugging
45+
@api_client.config.logger.debug 'Calling API: EstimatesApi.create_mass_estimate ...'
46+
end
47+
# verify the required parameter 'create_mass_estimate_request' is set
48+
if @api_client.config.client_side_validation && create_mass_estimate_request.nil?
49+
fail ArgumentError, "Missing the required parameter 'create_mass_estimate_request' when calling EstimatesApi.create_mass_estimate"
50+
end
51+
# resource path
52+
local_var_path = '/v1/estimates/mass'
53+
54+
# query parameters
55+
query_params = opts[:query_params] || {}
56+
57+
# header parameters
58+
header_params = opts[:header_params] || {}
59+
# HTTP header 'Accept' (if needed)
60+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
61+
# HTTP header 'Content-Type'
62+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
63+
64+
# form parameters
65+
form_params = opts[:form_params] || {}
66+
67+
# http body (model)
68+
post_body = opts[:body] || @api_client.object_to_http_body(create_mass_estimate_request)
69+
70+
# return_type
71+
return_type = opts[:return_type] || 'EstimateResponse'
72+
73+
# auth_names
74+
auth_names = opts[:auth_names] || ['bearer_auth']
75+
76+
new_options = opts.merge(
77+
:header_params => header_params,
78+
:query_params => query_params,
79+
:form_params => form_params,
80+
:body => post_body,
81+
:auth_names => auth_names,
82+
:return_type => return_type
83+
)
84+
85+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
86+
if @api_client.config.debugging
87+
@api_client.config.logger.debug "API called: EstimatesApi#create_mass_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
88+
end
89+
return data, status_code, headers
90+
end
91+
92+
# Retrieves an estimate
93+
# Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for.
94+
# @param id [String]
95+
# @param [Hash] opts the optional parameters
96+
# @return [EstimateResponse]
97+
def retrieve_estimate(id, opts = {})
98+
data, _status_code, _headers = retrieve_estimate_with_http_info(id, opts)
99+
data
100+
end
101+
102+
# Retrieves an estimate
103+
# Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for.
104+
# @param id [String]
105+
# @param [Hash] opts the optional parameters
106+
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
107+
def retrieve_estimate_with_http_info(id, opts = {})
108+
if @api_client.config.debugging
109+
@api_client.config.logger.debug 'Calling API: EstimatesApi.retrieve_estimate ...'
110+
end
111+
# verify the required parameter 'id' is set
112+
if @api_client.config.client_side_validation && id.nil?
113+
fail ArgumentError, "Missing the required parameter 'id' when calling EstimatesApi.retrieve_estimate"
114+
end
115+
# resource path
116+
local_var_path = '/v1/estimates/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
117+
118+
# query parameters
119+
query_params = opts[:query_params] || {}
120+
121+
# header parameters
122+
header_params = opts[:header_params] || {}
123+
# HTTP header 'Accept' (if needed)
124+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
125+
126+
# form parameters
127+
form_params = opts[:form_params] || {}
128+
129+
# http body (model)
130+
post_body = opts[:body]
131+
132+
# return_type
133+
return_type = opts[:return_type] || 'EstimateResponse'
134+
135+
# auth_names
136+
auth_names = opts[:auth_names] || ['bearer_auth']
137+
138+
new_options = opts.merge(
139+
:header_params => header_params,
140+
:query_params => query_params,
141+
:form_params => form_params,
142+
:body => post_body,
143+
:auth_names => auth_names,
144+
:return_type => return_type
145+
)
146+
147+
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
148+
if @api_client.config.debugging
149+
@api_client.config.logger.debug "API called: EstimatesApi#retrieve_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
150+
end
151+
return data, status_code, headers
152+
end
153+
154+
# Retrieves a list of estimates
155+
# Retrieves a list of estimates and their associated orders. You can only retrieve estimates associated with the organization you are querying for.
156+
# @param [Hash] opts the optional parameters
157+
# @option opts [Integer] :page
158+
# @return [EstimateListResponse]
159+
def retrieve_estimates(opts = {})
160+
data, _status_code, _headers = retrieve_estimates_with_http_info(opts)
161+
data
162+
end
163+
164+
# Retrieves a list of estimates
165+
# Retrieves a list of estimates and their associated orders. You can only retrieve estimates associated with the organization you are querying for.
166+
# @param [Hash] opts the optional parameters
167+
# @option opts [Integer] :page
168+
# @return [Array<(EstimateListResponse, Integer, Hash)>] EstimateListResponse data, response status code and response headers
169+
def retrieve_estimates_with_http_info(opts = {})
170+
if @api_client.config.debugging
171+
@api_client.config.logger.debug 'Calling API: EstimatesApi.retrieve_estimates ...'
172+
end
173+
# resource path
174+
local_var_path = '/v1/estimates'
175+
176+
# query parameters
177+
query_params = opts[:query_params] || {}
178+
query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
179+
180+
# header parameters
181+
header_params = opts[:header_params] || {}
182+
# HTTP header 'Accept' (if needed)
183+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
184+
185+
# form parameters
186+
form_params = opts[:form_params] || {}
187+
188+
# http body (model)
189+
post_body = opts[:body]
190+
191+
# return_type
192+
return_type = opts[:return_type] || 'EstimateListResponse'
193+
194+
# auth_names
195+
auth_names = opts[:auth_names] || ['bearer_auth']
196+
197+
new_options = opts.merge(
198+
:header_params => header_params,
199+
:query_params => query_params,
200+
:form_params => form_params,
201+
:body => post_body,
202+
:auth_names => auth_names,
203+
:return_type => return_type
204+
)
205+
206+
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
207+
if @api_client.config.debugging
208+
@api_client.config.logger.debug "API called: EstimatesApi#retrieve_estimates\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
209+
end
210+
return data, status_code, headers
211+
end
212+
end
213+
end

lib/patch_ruby/api/orders_api.rb

+15-11
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,27 @@ def cancel_order_with_http_info(id, opts = {})
9191

9292
# Creates an order
9393
# Creates an order in the `placed` state. To create a `draft` order, create an estimate first.
94+
# @param create_order_request [CreateOrderRequest]
9495
# @param [Hash] opts the optional parameters
95-
# @option opts [UNKNOWN_BASE_TYPE] :unknown_base_type
9696
# @return [OrderResponse]
97-
def create_order(opts = {})
98-
data, _status_code, _headers = create_order_with_http_info(opts)
97+
def create_order(create_order_request, opts = {})
98+
data, _status_code, _headers = create_order_with_http_info(create_order_request, opts)
9999
data
100100
end
101101

102102
# Creates an order
103103
# Creates an order in the &#x60;placed&#x60; state. To create a &#x60;draft&#x60; order, create an estimate first.
104+
# @param create_order_request [CreateOrderRequest]
104105
# @param [Hash] opts the optional parameters
105-
# @option opts [UNKNOWN_BASE_TYPE] :unknown_base_type
106106
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
107-
def create_order_with_http_info(opts = {})
107+
def create_order_with_http_info(create_order_request, opts = {})
108108
if @api_client.config.debugging
109109
@api_client.config.logger.debug 'Calling API: OrdersApi.create_order ...'
110110
end
111+
# verify the required parameter 'create_order_request' is set
112+
if @api_client.config.client_side_validation && create_order_request.nil?
113+
fail ArgumentError, "Missing the required parameter 'create_order_request' when calling OrdersApi.create_order"
114+
end
111115
# resource path
112116
local_var_path = '/v1/orders'
113117

@@ -125,7 +129,7 @@ def create_order_with_http_info(opts = {})
125129
form_params = opts[:form_params] || {}
126130

127131
# http body (model)
128-
post_body = opts[:body] || @api_client.object_to_http_body(opts[:'unknown_base_type'])
132+
post_body = opts[:body] || @api_client.object_to_http_body(create_order_request)
129133

130134
# return_type
131135
return_type = opts[:return_type] || 'OrderResponse'
@@ -153,17 +157,17 @@ def create_order_with_http_info(opts = {})
153157
# Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed
154158
# @param id [String]
155159
# @param [Hash] opts the optional parameters
156-
# @return [nil]
160+
# @return [OrderResponse]
157161
def place_order(id, opts = {})
158-
place_order_with_http_info(id, opts)
159-
nil
162+
data, _status_code, _headers = place_order_with_http_info(id, opts)
163+
data
160164
end
161165

162166
# Place an order
163167
# Placing an order confirms an order&#39;s allocation of offsets. Only orders that are in the &#x60;draft&#x60; state can be placed
164168
# @param id [String]
165169
# @param [Hash] opts the optional parameters
166-
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
170+
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
167171
def place_order_with_http_info(id, opts = {})
168172
if @api_client.config.debugging
169173
@api_client.config.logger.debug 'Calling API: OrdersApi.place_order ...'
@@ -190,7 +194,7 @@ def place_order_with_http_info(id, opts = {})
190194
post_body = opts[:body]
191195

192196
# return_type
193-
return_type = opts[:return_type]
197+
return_type = opts[:return_type] || 'OrderResponse'
194198

195199
# auth_names
196200
auth_names = opts[:auth_names] || ['bearer_auth']

lib/patch_ruby/api/preferences_api.rb

+10-6
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,27 @@ def initialize(api_client = ApiClient.default)
2828
end
2929
# creates a project preference
3030
# Creates a project preference for the given organization. If you have a `preference` in place, all of your orders will be directed to the project the preference points to.
31+
# @param create_preference_request [CreatePreferenceRequest]
3132
# @param [Hash] opts the optional parameters
32-
# @option opts [UNKNOWN_BASE_TYPE] :unknown_base_type
3333
# @return [PreferenceResponse]
34-
def create_preference(opts = {})
35-
data, _status_code, _headers = create_preference_with_http_info(opts)
34+
def create_preference(create_preference_request, opts = {})
35+
data, _status_code, _headers = create_preference_with_http_info(create_preference_request, opts)
3636
data
3737
end
3838

3939
# creates a project preference
4040
# Creates a project preference for the given organization. If you have a &#x60;preference&#x60; in place, all of your orders will be directed to the project the preference points to.
41+
# @param create_preference_request [CreatePreferenceRequest]
4142
# @param [Hash] opts the optional parameters
42-
# @option opts [UNKNOWN_BASE_TYPE] :unknown_base_type
4343
# @return [Array<(PreferenceResponse, Integer, Hash)>] PreferenceResponse data, response status code and response headers
44-
def create_preference_with_http_info(opts = {})
44+
def create_preference_with_http_info(create_preference_request, opts = {})
4545
if @api_client.config.debugging
4646
@api_client.config.logger.debug 'Calling API: PreferencesApi.create_preference ...'
4747
end
48+
# verify the required parameter 'create_preference_request' is set
49+
if @api_client.config.client_side_validation && create_preference_request.nil?
50+
fail ArgumentError, "Missing the required parameter 'create_preference_request' when calling PreferencesApi.create_preference"
51+
end
4852
# resource path
4953
local_var_path = '/v1/preferences'
5054

@@ -62,7 +66,7 @@ def create_preference_with_http_info(opts = {})
6266
form_params = opts[:form_params] || {}
6367

6468
# http body (model)
65-
post_body = opts[:body] || @api_client.object_to_http_body(opts[:'unknown_base_type'])
69+
post_body = opts[:body] || @api_client.object_to_http_body(create_preference_request)
6670

6771
# return_type
6872
return_type = opts[:return_type] || 'PreferenceResponse'

0 commit comments

Comments
 (0)