From 82828c7c11953ae1e51ed2cba93120f33613637c Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Thu, 24 Sep 2020 09:35:17 -0700 Subject: [PATCH 01/17] WIP From 00b581f452bc4a29afc749184e1d88b027f055eb Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Thu, 24 Sep 2020 12:12:12 -0700 Subject: [PATCH 02/17] makefile --- Makefile | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9162086 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +SHELL = /bin/bash + +build: + rubocop -a && \ + bundle install + +test: + bundle exec rspec + +.PHONY: build test \ No newline at end of file From 3ebb6e79ccc843c81c4decf55440e9f657d54121 Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Thu, 24 Sep 2020 12:12:27 -0700 Subject: [PATCH 03/17] linter fix --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index df46058..d32b2b1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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. From ae596275274ffe1c52447937d1c4cbbf14ca6c52 Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Thu, 24 Sep 2020 12:21:21 -0700 Subject: [PATCH 04/17] adds patch_fee, changes type of price to integer --- lib/patch_ruby/models/order.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/patch_ruby/models/order.rb b/lib/patch_ruby/models/order.rb index 8f74da2..b065006 100644 --- a/lib/patch_ruby/models/order.rb +++ b/lib/patch_ruby/models/order.rb @@ -26,6 +26,8 @@ class Order attr_accessor :price_cents_usd + attr_accessor :patch_fee_cents_usd + attr_accessor :allocations attr_accessor :metadata @@ -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' } @@ -74,7 +77,8 @@ def self.openapi_types :'production' => :'Boolean', :'state' => :'String', :'allocation_state' => :'String', - :'price_cents_usd' => :'String', + :'price_cents_usd' => :'Integer', + :'patch_fee_cents_usd' => :'Integer', :'allocations' => :'Array', :'metadata' => :'Object' } @@ -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 @@ -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 @@ -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 From 27f4ab5d6c270e2ee4ef5208680f9ac693c40bb9 Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Thu, 24 Sep 2020 12:32:42 -0700 Subject: [PATCH 05/17] url validation --- lib/patch_ruby/models/photo.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/patch_ruby/models/photo.rb b/lib/patch_ruby/models/photo.rb index 9028c4b..fb9671b 100644 --- a/lib/patch_ruby/models/photo.rb +++ b/lib/patch_ruby/models/photo.rb @@ -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 From 6f3c914ab1e28a7fbc4d4b99ed93805a362e5e7c Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Thu, 24 Sep 2020 13:18:18 -0700 Subject: [PATCH 06/17] bump version to 1.3.0 --- CHANGELOG.md | 10 ++++++++++ Gemfile.lock | 2 +- lib/patch_ruby/version.rb | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53b47b7..54215b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.3.0] - 2020-09-24 + +### Added + +- `patch_fee_cents_usd` `integer` field to `orders` + +## Changed + +- `price_cents_usd` type changed from `string` to `integer` + ## [1.2.2] - 2020-09-18 ### Added diff --git a/Gemfile.lock b/Gemfile.lock index 56dfdcb..7d0d327 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - patch_ruby (1.2.2) + patch_ruby (1.3.0) json (~> 2.1, >= 2.1.0) typhoeus (~> 1.0, >= 1.0.1) diff --git a/lib/patch_ruby/version.rb b/lib/patch_ruby/version.rb index d0708e9..ceacad6 100644 --- a/lib/patch_ruby/version.rb +++ b/lib/patch_ruby/version.rb @@ -11,5 +11,5 @@ =end module Patch - VERSION = '1.2.2' + VERSION = '1.3.0' end From 39bef4043e4d01aa1a53d99b80a3a8059ce515f5 Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Thu, 24 Sep 2020 13:24:34 -0700 Subject: [PATCH 07/17] add more checkboxes --- .github/PULL_REQUEST_TEMPLATE.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6785041..b3f9d31 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -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? +- [ ] 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? From 66da3c5990ddc0c503bb9614f07f86624a1f9317 Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Thu, 24 Sep 2020 16:33:48 -0700 Subject: [PATCH 08/17] patch fee integration test --- spec/integration/orders_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/integration/orders_spec.rb b/spec/integration/orders_spec.rb index 2c44fef..09dd3c7 100644 --- a/spec/integration/orders_spec.rb +++ b/spec/integration/orders_spec.rb @@ -29,11 +29,13 @@ retrieve_projects_response = Patch::Project.retrieve_projects(page: 1) project_id = retrieve_projects_response.data.first.id - create_order_response = Patch::Order.create_order(mass_g: 100, project_id: project_id) + create_order_response = Patch::Order.create_order(mass_g: 100_000, 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(100_000) + expect(create_order_response.data.price_cents_usd).to eq(1553) + expect(create_order_response.data.patch_fee_cents_usd).to eq(50) end it 'supports create with metadata' do From 5027cdd7171e7f5e36fa9cd12f6a8b51e2e3e873 Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Mon, 28 Sep 2020 18:03:23 -0700 Subject: [PATCH 09/17] prices and fees are strings --- lib/patch_ruby/models/order.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/patch_ruby/models/order.rb b/lib/patch_ruby/models/order.rb index b065006..55b5bb1 100644 --- a/lib/patch_ruby/models/order.rb +++ b/lib/patch_ruby/models/order.rb @@ -77,8 +77,8 @@ def self.openapi_types :'production' => :'Boolean', :'state' => :'String', :'allocation_state' => :'String', - :'price_cents_usd' => :'Integer', - :'patch_fee_cents_usd' => :'Integer', + :'price_cents_usd' => :'String', + :'patch_fee_cents_usd' => :'String', :'allocations' => :'Array', :'metadata' => :'Object' } From a151bed71e33a0be579fd48268d1e5526078388d Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Mon, 28 Sep 2020 18:14:56 -0700 Subject: [PATCH 10/17] rename to SANDBOX_API_KEY env variable --- README.md | 4 ++-- spec/integration/estimates_spec.rb | 2 +- spec/integration/orders_spec.rb | 2 +- spec/integration/preferences_spec.rb | 2 +- spec/integration/projects_spec.rb | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 56dcfcb..e258cc4 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -161,7 +161,7 @@ $ bundle install Set up required environment variables: ``` -$ export PATCH_RUBY_API_KEY= +$ export SANDBOX_API_KEY= ``` Run tests: diff --git a/spec/integration/estimates_spec.rb b/spec/integration/estimates_spec.rb index 523d0c1..caf2b9c 100644 --- a/spec/integration/estimates_spec.rb +++ b/spec/integration/estimates_spec.rb @@ -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 diff --git a/spec/integration/orders_spec.rb b/spec/integration/orders_spec.rb index 09dd3c7..9c89582 100644 --- a/spec/integration/orders_spec.rb +++ b/spec/integration/orders_spec.rb @@ -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 diff --git a/spec/integration/preferences_spec.rb b/spec/integration/preferences_spec.rb index 8aba7ef..9307033 100644 --- a/spec/integration/preferences_spec.rb +++ b/spec/integration/preferences_spec.rb @@ -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 diff --git a/spec/integration/projects_spec.rb b/spec/integration/projects_spec.rb index e623b1d..899ae2a 100644 --- a/spec/integration/projects_spec.rb +++ b/spec/integration/projects_spec.rb @@ -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 From a98dea686cb48e8839684c763668c192e7f9e0cd Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Mon, 28 Sep 2020 18:15:47 -0700 Subject: [PATCH 11/17] fix order test --- spec/integration/orders_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/integration/orders_spec.rb b/spec/integration/orders_spec.rb index 9c89582..bcd8919 100644 --- a/spec/integration/orders_spec.rb +++ b/spec/integration/orders_spec.rb @@ -34,8 +34,8 @@ 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_000) - expect(create_order_response.data.price_cents_usd).to eq(1553) - expect(create_order_response.data.patch_fee_cents_usd).to eq(50) + expect(create_order_response.data.price_cents_usd).to eq("10.0") + expect(create_order_response.data.patch_fee_cents_usd).to eq("1.0") end it 'supports create with metadata' do From ac18378f3b1aaeb49b13b00ce626139dbd978452 Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Mon, 28 Sep 2020 18:17:33 -0700 Subject: [PATCH 12/17] fix changelog --- CHANGELOG.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54215b0..a723171 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- `patch_fee_cents_usd` `integer` field to `orders` - -## Changed - -- `price_cents_usd` type changed from `string` to `integer` +- `patch_fee_cents_usd` field to `orders` ## [1.2.2] - 2020-09-18 From f4ccce32be0aec23384914afc10a238f762bdcaf Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Mon, 28 Sep 2020 18:20:49 -0700 Subject: [PATCH 13/17] fix version - no breaking changes --- CHANGELOG.md | 2 +- Gemfile.lock | 2 +- lib/patch_ruby/version.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a723171..bb8e2df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [1.3.0] - 2020-09-24 +## [1.2.3] - 2020-09-28 ### Added diff --git a/Gemfile.lock b/Gemfile.lock index 7d0d327..1e8c94d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - patch_ruby (1.3.0) + patch_ruby (1.2.3) json (~> 2.1, >= 2.1.0) typhoeus (~> 1.0, >= 1.0.1) diff --git a/lib/patch_ruby/version.rb b/lib/patch_ruby/version.rb index ceacad6..d073ba8 100644 --- a/lib/patch_ruby/version.rb +++ b/lib/patch_ruby/version.rb @@ -11,5 +11,5 @@ =end module Patch - VERSION = '1.3.0' + VERSION = '1.2.3' end From e8f0e000ca56f2f283814e25a27859ad7ef0f3dd Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Mon, 5 Oct 2020 12:39:49 -0700 Subject: [PATCH 14/17] a better spec --- spec/integration/orders_spec.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/spec/integration/orders_spec.rb b/spec/integration/orders_spec.rb index bcd8919..4cb1c72 100644 --- a/spec/integration/orders_spec.rb +++ b/spec/integration/orders_spec.rb @@ -26,16 +26,24 @@ 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 + # biomass project + retrieve_project_response = Patch::Project.retrieve_project("pro_test_c3a9feba769fc7a8806377266ca9ff6a") - create_order_response = Patch::Order.create_order(mass_g: 100_000, 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_000) - expect(create_order_response.data.price_cents_usd).to eq("10.0") - expect(create_order_response.data.patch_fee_cents_usd).to eq("1.0") + 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 From b8ec220a29bbdcc52bb22eeab102dd5ac3b5c51a Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Mon, 5 Oct 2020 16:11:39 -0700 Subject: [PATCH 15/17] test project id --- spec/integration/orders_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/integration/orders_spec.rb b/spec/integration/orders_spec.rb index 4cb1c72..967d566 100644 --- a/spec/integration/orders_spec.rb +++ b/spec/integration/orders_spec.rb @@ -1,4 +1,7 @@ RSpec.describe 'Orders Integration' do + # biomass test project + BIOMASS_TEST_PROJECT_ID = "pro_test_c3a9feba769fc7a8806377266ca9ff6a" + before do Patch.configure do |config| config.access_token = ENV['SANDBOX_API_KEY'] @@ -26,8 +29,7 @@ end it 'supports create with a project-id' do - # biomass project - retrieve_project_response = Patch::Project.retrieve_project("pro_test_c3a9feba769fc7a8806377266ca9ff6a") + retrieve_project_response = Patch::Project.retrieve_project(BIOMASS_TEST_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 From 2523546a6dedfb83224b2ff09b7956bf297d0458 Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Mon, 5 Oct 2020 16:19:05 -0700 Subject: [PATCH 16/17] constants file --- spec/constants.rb | 3 +++ spec/integration/orders_spec.rb | 7 +++---- spec/spec_helper.rb | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 spec/constants.rb diff --git a/spec/constants.rb b/spec/constants.rb new file mode 100644 index 0000000..4e8177e --- /dev/null +++ b/spec/constants.rb @@ -0,0 +1,3 @@ +module Constants + BIOMASS_TEST_PROJECT_ID = "pro_test_c3a9feba769fc7a8806377266ca9ff6a" +end diff --git a/spec/integration/orders_spec.rb b/spec/integration/orders_spec.rb index 967d566..43a489c 100644 --- a/spec/integration/orders_spec.rb +++ b/spec/integration/orders_spec.rb @@ -1,7 +1,4 @@ RSpec.describe 'Orders Integration' do - # biomass test project - BIOMASS_TEST_PROJECT_ID = "pro_test_c3a9feba769fc7a8806377266ca9ff6a" - before do Patch.configure do |config| config.access_token = ENV['SANDBOX_API_KEY'] @@ -29,7 +26,9 @@ end it 'supports create with a project-id' do - retrieve_project_response = Patch::Project.retrieve_project(BIOMASS_TEST_PROJECT_ID) + retrieve_project_response = Patch::Project.retrieve_project( + Constants::BIOMASS_TEST_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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6c652b6..2ed41b9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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`. From 09524a881e045e80e669c76a97797bbeaf84cf4b Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Tue, 6 Oct 2020 12:37:01 -0700 Subject: [PATCH 17/17] change the env name --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f1b90b..849d492 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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