Skip to content

Commit 7e9dfc0

Browse files
authored
Merge pull request #31 from patch-technology/pc/16
Add bitcoin estimates and registry_url
2 parents 050daf5 + 60691b6 commit 7e9dfc0

File tree

11 files changed

+388
-20
lines changed

11 files changed

+388
-20
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ jobs:
99
build-and-test:
1010
name: Build and Test
1111
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
ruby-version: [3.0.1, 2.7.4, 2.6.8]
16+
1217
steps:
1318
- name: Check out code
1419
uses: actions/checkout@v2
1520

16-
- name: Setup Ruby
21+
- name: Setup Ruby ${{ matrix.ruby-version }}
1722
uses: ruby/setup-ruby@v1
1823
with:
19-
ruby-version: 2.7.1
24+
ruby-version: ${{ matrix.ruby-version }}
2025

2126
- name: Install Ruby Dependencies
2227
run: bundle install

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ 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.6.0] - 2021-07-14
9+
10+
### Added
11+
12+
- Order responses return a `registry_url` field
13+
- Add support for Bitcoin estimates
14+
815
## [1.5.2] - 2021-03-30
916

1017
### Changed

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ Patch::Estimate.create_vehicle_estimate(
139139
year: year
140140
)
141141

142+
# Create a flight estimate
143+
transaction_value_btc_sats = 1000; # [Optional] Pass in the transaction value in satoshis
144+
Patch::Estimate.create_bitcoin_estimate(transaction_value_btc_sats: transaction_value_btc_sats)
145+
142146
## You can also specify a project-id field (optional) to be used instead of the preferred one
143147
project_id = 'pro_test_1234' # Pass in the project's ID
144148
Patch::Estimate.create_mass_estimate(mass_g: mass, project_id: project_id)
@@ -218,30 +222,30 @@ Patch::Preference.retrieve_preferences(page: page)
218222

219223
To build the gem locally, run:
220224

221-
```
222-
$ gem build patch_ruby.gemspec
225+
```bash
226+
gem build patch_ruby.gemspec
223227
```
224228

225229
This will create a .gem file. To install the local gem:
226230

227-
```
228-
$ gem install patch_ruby-1.x.x.gem
231+
```bash
232+
gem install patch_ruby-1.x.x.gem
229233
```
230234

231235
Install dependencies:
232236

233-
```
234-
$ bundle install
237+
```bash
238+
bundle install
235239
```
236240

237241
Set up required environment variables:
238242

239-
```
240-
$ export SANDBOX_API_KEY=<SANDBOX API KEY>
243+
```bash
244+
export SANDBOX_API_KEY=<SANDBOX API KEY>
241245
```
242246

243247
Run tests:
244248

245-
```
246-
$ bundle exec rspec
249+
```bash
250+
bundle exec rspec
247251
```

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 &#x60;draft&#x60; 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

0 commit comments

Comments
 (0)