Skip to content

adds patch_fee_cents_usd field #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@

- [ ] Have you added an integration test for the changes?
- [ ] Have you built the gem locally and made queries against it successfully?
- [ ] Did you update the changelog?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏🏻

- [ ] Did you bump the package version?
- [ ] For breaking changes, did you plan for the release of the new SDK versions and deploy the API to production?
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ jobs:

- name: Run RSpec
env:
PATCH_RUBY_API_KEY: ${{ secrets.SANDBOX_API_KEY }}
SANDBOX_API_KEY: ${{ secrets.SANDBOX_API_KEY }}
run: bundle exec rspec
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Layout/SpaceInsideParens:
# EnforcedStyle: single_quotes

# Detect hard tabs, no hard tabs.
Layout/Tab:
Layout/IndentationStyle:
Enabled: true

# Blank lines should not have any spaces.
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.2.3] - 2020-09-28

### Added

- `patch_fee_cents_usd` field to `orders`

## [1.2.2] - 2020-09-18

### 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.2.2)
patch_ruby (1.2.3)
json (~> 2.1, >= 2.1.0)
typhoeus (~> 1.0, >= 1.0.1)

Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SHELL = /bin/bash

build:
rubocop -a && \
bundle install

test:
bundle exec rspec

.PHONY: build test
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require 'patch_ruby'

Patch.configure do |config|
# Configure the Patch gem with your API key here
config.access_token = ENV['PATCH_RUBY_API_KEY']
config.access_token = ENV['SANDBOX_API_KEY']
end
```

Expand Down Expand Up @@ -161,7 +161,7 @@ $ bundle install

Set up required environment variables:
```
$ export PATCH_RUBY_API_KEY=<SANDBOX API KEY>
$ export SANDBOX_API_KEY=<SANDBOX API KEY>
```

Run tests:
Expand Down
11 changes: 10 additions & 1 deletion lib/patch_ruby/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Order

attr_accessor :price_cents_usd

attr_accessor :patch_fee_cents_usd

attr_accessor :allocations

attr_accessor :metadata
Expand Down Expand Up @@ -61,6 +63,7 @@ def self.attribute_map
:'state' => :'state',
:'allocation_state' => :'allocation_state',
:'price_cents_usd' => :'price_cents_usd',
:'patch_fee_cents_usd' => :'patch_fee_cents_usd',
:'allocations' => :'allocations',
:'metadata' => :'metadata'
}
Expand All @@ -75,6 +78,7 @@ def self.openapi_types
:'state' => :'String',
:'allocation_state' => :'String',
:'price_cents_usd' => :'String',
:'patch_fee_cents_usd' => :'String',
:'allocations' => :'Array<Allocation>',
:'metadata' => :'Object'
}
Expand Down Expand Up @@ -130,6 +134,10 @@ def initialize(attributes = {})
self.price_cents_usd = attributes[:'price_cents_usd']
end

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

if attributes.key?(:'allocations')
if (value = attributes[:'allocations']).is_a?(Array)
self.allocations = value
Expand Down Expand Up @@ -252,6 +260,7 @@ def ==(o)
state == o.state &&
allocation_state == o.allocation_state &&
price_cents_usd == o.price_cents_usd &&
patch_fee_cents_usd == o.patch_fee_cents_usd &&
allocations == o.allocations &&
metadata == o.metadata
end
Expand All @@ -265,7 +274,7 @@ def eql?(o)
# Calculates hash code according to all attributes.
# @return [Integer] Hash code
def hash
[id, mass_g, production, state, allocation_state, price_cents_usd, allocations, metadata].hash
[id, mass_g, production, state, allocation_state, price_cents_usd, patch_fee_cents_usd, allocations, metadata].hash
end

# Builds the object from hash
Expand Down
5 changes: 5 additions & 0 deletions lib/patch_ruby/models/photo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,17 @@ def initialize(attributes = {})
# @return Array for valid properties with the reasons
def list_invalid_properties
invalid_properties = Array.new
if @url.nil?
invalid_properties.push('invalid value for "url", url cannot be nil.')
end

invalid_properties
end

# Check to see if the all the properties in the model are valid
# @return true if the model is valid
def valid?
return false if @url.nil?
true
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.2.2'
VERSION = '1.2.3'
end
3 changes: 3 additions & 0 deletions spec/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Constants
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

BIOMASS_TEST_PROJECT_ID = "pro_test_c3a9feba769fc7a8806377266ca9ff6a"
end
2 changes: 1 addition & 1 deletion spec/integration/estimates_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RSpec.describe 'Estimates Integration' do
before do
Patch.configure do |config|
config.access_token = ENV['PATCH_RUBY_API_KEY']
config.access_token = ENV['SANDBOX_API_KEY']
end
end

Expand Down
21 changes: 16 additions & 5 deletions spec/integration/orders_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RSpec.describe 'Orders Integration' do
before do
Patch.configure do |config|
config.access_token = ENV['PATCH_RUBY_API_KEY']
config.access_token = ENV['SANDBOX_API_KEY']
end
end

Expand All @@ -26,14 +26,25 @@
end

it 'supports create with a project-id' do
retrieve_projects_response = Patch::Project.retrieve_projects(page: 1)
project_id = retrieve_projects_response.data.first.id
retrieve_project_response = Patch::Project.retrieve_project(
Constants::BIOMASS_TEST_PROJECT_ID
)

create_order_response = Patch::Order.create_order(mass_g: 100, project_id: project_id)
project_id = retrieve_project_response.data.id
average_price_per_tonne_cents_usd = retrieve_project_response.data.average_price_per_tonne_cents_usd

order_mass_g = 100_000
tonne_per_gram = 1_000_000

expected_price = (average_price_per_tonne_cents_usd.to_f / tonne_per_gram) * order_mass_g

create_order_response = Patch::Order.create_order(mass_g: order_mass_g, project_id: project_id)

expect(create_order_response.success).to eq true
expect(create_order_response.data.id).not_to be_nil
expect(create_order_response.data.mass_g).to eq(100)
expect(create_order_response.data.mass_g).to eq(order_mass_g)
expect(create_order_response.data.price_cents_usd.to_i).to eq(expected_price)
expect(create_order_response.data.patch_fee_cents_usd).not_to be_empty
end

it 'supports create with metadata' do
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/preferences_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RSpec.describe 'Preferences Integration' do
before do
Patch.configure do |config|
config.access_token = ENV['PATCH_RUBY_API_KEY']
config.access_token = ENV['SANDBOX_API_KEY']
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/projects_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.describe 'Projects Integration' do
Patch.configure do |config|
config.access_token = ENV['PATCH_RUBY_API_KEY']
config.access_token = ENV['SANDBOX_API_KEY']
end

it 'supports retrieve and list' do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# load the gem
require 'patch_ruby'
require 'constants'

# The following was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
Expand Down