Skip to content

Commit

Permalink
Add average_daily_balance_btc_sats for btc (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcothenet authored Sep 10, 2021
1 parent 19fbf52 commit 7eba5a2
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.13.0] - 2021-09-10

### Added

- Adds ability to create Bitcoin and Ethereum estimates using the daily balance held.

## [1.12.0] - 2021-09-08

### Added
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
patch_ruby (1.12.0)
patch_ruby (1.13.0)
typhoeus (~> 1.0, >= 1.0.1)

GEM
Expand Down
4 changes: 2 additions & 2 deletions lib/patch_ruby/api/estimates_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def create_bitcoin_estimate_with_http_info(create_bitcoin_estimate_request, opts
return data, status_code, headers
end

# Create an ethereum estimate given a timestamp and gas used
# Create an ethereum estimate
# Creates an ethereum 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.
# @param create_ethereum_estimate_request [CreateEthereumEstimateRequest]
# @param [Hash] opts the optional parameters
Expand All @@ -107,7 +107,7 @@ def create_ethereum_estimate(create_ethereum_estimate_request = {}, opts = {})
data
end

# Create an ethereum estimate given a timestamp and gas used
# Create an ethereum estimate
# Creates an ethereum 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.
# @param create_ethereum_estimate_request [CreateEthereumEstimateRequest]
# @param [Hash] opts the optional parameters
Expand Down
2 changes: 1 addition & 1 deletion lib/patch_ruby/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ApiClient
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
def initialize(config = Configuration.default)
@config = config
@user_agent = "patch-ruby/1.12.0"
@user_agent = "patch-ruby/1.13.0"
@default_headers = {
'Content-Type' => 'application/json',
'User-Agent' => @user_agent
Expand Down
14 changes: 13 additions & 1 deletion lib/patch_ruby/models/create_bitcoin_estimate_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class CreateBitcoinEstimateRequest

attr_accessor :transaction_value_btc_sats

attr_accessor :average_daily_balance_btc_sats

attr_accessor :project_id

attr_accessor :create_order
Expand All @@ -28,6 +30,7 @@ def self.attribute_map
{
:'timestamp' => :'timestamp',
:'transaction_value_btc_sats' => :'transaction_value_btc_sats',
:'average_daily_balance_btc_sats' => :'average_daily_balance_btc_sats',
:'project_id' => :'project_id',
:'create_order' => :'create_order'
}
Expand All @@ -43,6 +46,7 @@ def self.openapi_types
{
:'timestamp' => :'Time',
:'transaction_value_btc_sats' => :'Integer',
:'average_daily_balance_btc_sats' => :'Integer',
:'project_id' => :'String',
:'create_order' => :'Boolean'
}
Expand All @@ -53,6 +57,7 @@ def self.openapi_nullable
Set.new([
:'timestamp',
:'transaction_value_btc_sats',
:'average_daily_balance_btc_sats',
:'project_id',
:'create_order'
])
Expand Down Expand Up @@ -93,12 +98,18 @@ def initialize(attributes = {})
self.transaction_value_btc_sats = attributes[:'transaction_value_btc_sats']
end

if attributes.key?(:'average_daily_balance_btc_sats')
self.average_daily_balance_btc_sats = attributes[:'average_daily_balance_btc_sats']
end

if attributes.key?(:'project_id')
self.project_id = attributes[:'project_id']
end

if attributes.key?(:'create_order')
self.create_order = attributes[:'create_order']
else
self.create_order = false
end
end

Expand All @@ -122,6 +133,7 @@ def ==(o)
self.class == o.class &&
timestamp == o.timestamp &&
transaction_value_btc_sats == o.transaction_value_btc_sats &&
average_daily_balance_btc_sats == o.average_daily_balance_btc_sats &&
project_id == o.project_id &&
create_order == o.create_order
end
Expand All @@ -135,7 +147,7 @@ def eql?(o)
# Calculates hash code according to all attributes.
# @return [Integer] Hash code
def hash
[timestamp, transaction_value_btc_sats, project_id, create_order].hash
[timestamp, transaction_value_btc_sats, average_daily_balance_btc_sats, project_id, create_order].hash
end

# Builds the object from hash
Expand Down
14 changes: 13 additions & 1 deletion lib/patch_ruby/models/create_ethereum_estimate_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class CreateEthereumEstimateRequest

attr_accessor :transaction_value_eth_gwei

attr_accessor :average_daily_balance_eth_gwei

attr_accessor :project_id

attr_accessor :create_order
Expand All @@ -31,6 +33,7 @@ def self.attribute_map
:'timestamp' => :'timestamp',
:'gas_used' => :'gas_used',
:'transaction_value_eth_gwei' => :'transaction_value_eth_gwei',
:'average_daily_balance_eth_gwei' => :'average_daily_balance_eth_gwei',
:'project_id' => :'project_id',
:'create_order' => :'create_order'
}
Expand All @@ -47,6 +50,7 @@ def self.openapi_types
:'timestamp' => :'String',
:'gas_used' => :'Integer',
:'transaction_value_eth_gwei' => :'Integer',
:'average_daily_balance_eth_gwei' => :'Integer',
:'project_id' => :'String',
:'create_order' => :'Boolean'
}
Expand All @@ -58,6 +62,7 @@ def self.openapi_nullable
:'timestamp',
:'gas_used',
:'transaction_value_eth_gwei',
:'average_daily_balance_eth_gwei',
:'project_id',
:'create_order'
])
Expand Down Expand Up @@ -102,12 +107,18 @@ def initialize(attributes = {})
self.transaction_value_eth_gwei = attributes[:'transaction_value_eth_gwei']
end

if attributes.key?(:'average_daily_balance_eth_gwei')
self.average_daily_balance_eth_gwei = attributes[:'average_daily_balance_eth_gwei']
end

if attributes.key?(:'project_id')
self.project_id = attributes[:'project_id']
end

if attributes.key?(:'create_order')
self.create_order = attributes[:'create_order']
else
self.create_order = false
end
end

Expand All @@ -132,6 +143,7 @@ def ==(o)
timestamp == o.timestamp &&
gas_used == o.gas_used &&
transaction_value_eth_gwei == o.transaction_value_eth_gwei &&
average_daily_balance_eth_gwei == o.average_daily_balance_eth_gwei &&
project_id == o.project_id &&
create_order == o.create_order
end
Expand All @@ -145,7 +157,7 @@ def eql?(o)
# Calculates hash code according to all attributes.
# @return [Integer] Hash code
def hash
[timestamp, gas_used, transaction_value_eth_gwei, project_id, create_order].hash
[timestamp, gas_used, transaction_value_eth_gwei, average_daily_balance_eth_gwei, project_id, create_order].hash
end

# Builds the object from hash
Expand Down
2 changes: 2 additions & 0 deletions lib/patch_ruby/models/create_flight_estimate_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def initialize(attributes = {})

if attributes.key?(:'create_order')
self.create_order = attributes[:'create_order']
else
self.create_order = false
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/patch_ruby/models/create_mass_estimate_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def initialize(attributes = {})

if attributes.key?(:'create_order')
self.create_order = attributes[:'create_order']
else
self.create_order = false
end

if attributes.key?(:'project_id')
Expand Down
2 changes: 2 additions & 0 deletions lib/patch_ruby/models/create_shipping_estimate_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def initialize(attributes = {})

if attributes.key?(:'create_order')
self.create_order = attributes[:'create_order']
else
self.create_order = false
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/patch_ruby/models/create_vehicle_estimate_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def initialize(attributes = {})

if attributes.key?(:'create_order')
self.create_order = attributes[:'create_order']
else
self.create_order = false
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/patch_ruby/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
=end

module Patch
VERSION = '1.12.0'
VERSION = '1.13.0'
end
15 changes: 14 additions & 1 deletion spec/integration/estimates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@


it 'supports creating bitcoin estimates with partial information' do
bitcoin_estimate = Patch::Estimate.create_bitcoin_estimate({})
bitcoin_estimate = Patch::Estimate.create_bitcoin_estimate()

expect(bitcoin_estimate.data.type).to eq 'bitcoin'
expect(bitcoin_estimate.data.mass_g).to be >= 2_000
Expand Down Expand Up @@ -124,6 +124,19 @@
expect(bitcoin_estimate_1.data.mass_g).to be > bitcoin_estimate_2.data.mass_g # Bitcoin was emitting less in July 2021 than in June
end

it 'supports creating bitcoin estimates with a average_daily_balance_btc_sats' do
bitcoin_estimate_1 = Patch::Estimate.create_bitcoin_estimate(
average_daily_balance_btc_sats: 1000000
)

bitcoin_estimate_2 = Patch::Estimate.create_bitcoin_estimate(
average_daily_balance_btc_sats: 10000000
)

expect(bitcoin_estimate_1.data.type).to eq 'bitcoin'
expect(bitcoin_estimate_1.data.mass_g).to be < bitcoin_estimate_2.data.mass_g
end

it 'supports creating ethereum estimates with a gas amount' do
ethereum_estimate = Patch::Estimate.create_ethereum_estimate(
gas_used: 100
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/orders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@
end

it 'supports place and cancel for orders created via an estimate' do
create_estimate_to_place_response = Patch::Estimate.create_mass_estimate(mass_g: 100)
create_estimate_to_place_response = Patch::Estimate.create_mass_estimate(mass_g: 100, create_order: true)
order_to_place_id = create_estimate_to_place_response.data.order.id

place_order_response = Patch::Order.place_order(order_to_place_id)
expect(place_order_response.data.state).to eq 'placed'

create_estimate_to_cancel_response = Patch::Estimate.create_mass_estimate(mass_g: 100)
create_estimate_to_cancel_response = Patch::Estimate.create_mass_estimate(mass_g: 100, create_order: true)
order_to_cancel_id = create_estimate_to_cancel_response.data.order.id

cancel_order_response = Patch::Order.cancel_order(order_to_cancel_id)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/create_mass_estimate_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

it_behaves_like "a generated class" do
let(:instance) { @instance }
let(:instance_hash) { { project_id: @instance.project_id, mass_g: @instance.mass_g } }
let(:instance_hash) { { project_id: @instance.project_id, mass_g: @instance.mass_g, create_order: @instance.create_order } }
let(:nullable_properties) { Set.new([:create_order]) }
end

Expand Down

0 comments on commit 7eba5a2

Please sign in to comment.