From ae67c8d7d0523cab1f5b5b9ccaf6692707c8f235 Mon Sep 17 00:00:00 2001 From: James Klein Date: Wed, 18 Aug 2021 11:15:50 -0600 Subject: [PATCH] Metadata query params for Orders endpoint (#34) --- .github/workflows/test.yml | 1 + .ruby-version | 1 + CHANGELOG.md | 7 +++++ Gemfile.lock | 2 +- bin/rspec | 29 +++++++++++++++++++ lib/patch_ruby/api/orders_api.rb | 9 ++++++ .../create_ethereum_estimate_request.rb | 13 ++++++++- lib/patch_ruby/models/estimate.rb | 2 +- lib/patch_ruby/version.rb | 2 +- spec/integration/estimates_spec.rb | 8 +---- spec/integration/orders_spec.rb | 19 +++++++----- spec/integration/preferences_spec.rb | 6 ---- spec/integration/projects_spec.rb | 22 ++++---------- spec/spec_helper.rb | 21 ++++++++++---- 14 files changed, 94 insertions(+), 48 deletions(-) create mode 100644 .ruby-version create mode 100755 bin/rspec diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1937123..fad8453 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,7 @@ jobs: strategy: matrix: ruby-version: [3.0.1, 2.7.4, 2.6.8] + max-parallel: 1 steps: - name: Check out code diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..4a36342 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.0.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 788affe..91a394f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ 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.9.0] - 2021-08-17 + +### Added + +- Add support for querying Orders by `metadata` +- Added `transaction_value_eth_gwei` as an alternative way to compute transaction level emissions for ethereum + ## [1.8.0] - 2021-07-20 ### Added diff --git a/Gemfile.lock b/Gemfile.lock index dc279d7..31a2694 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - patch_ruby (1.8.0) + patch_ruby (1.9.0) json (~> 2.1, >= 2.1.0) typhoeus (~> 1.0, >= 1.0.1) diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 0000000..a6c7852 --- /dev/null +++ b/bin/rspec @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") diff --git a/lib/patch_ruby/api/orders_api.rb b/lib/patch_ruby/api/orders_api.rb index 20f8b64..901c8ad 100644 --- a/lib/patch_ruby/api/orders_api.rb +++ b/lib/patch_ruby/api/orders_api.rb @@ -281,6 +281,9 @@ def retrieve_order_with_http_info(id, opts = {}) # Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. # @param [Hash] opts the optional parameters # @option opts [Integer] :page + # @option opts [String] :metadata + # @option opts [String] :metadata_example1 + # @option opts [String] :metadata_example2 # @return [OrderListResponse] def retrieve_orders(opts = {}) data, _status_code, _headers = retrieve_orders_with_http_info(opts) @@ -291,6 +294,9 @@ def retrieve_orders(opts = {}) # Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. # @param [Hash] opts the optional parameters # @option opts [Integer] :page + # @option opts [String] :metadata + # @option opts [String] :metadata_example1 + # @option opts [String] :metadata_example2 # @return [Array<(OrderListResponse, Integer, Hash)>] OrderListResponse data, response status code and response headers def retrieve_orders_with_http_info(opts = {}) if @api_client.config.debugging @@ -302,6 +308,9 @@ def retrieve_orders_with_http_info(opts = {}) # query parameters query_params = opts[:query_params] || {} query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil? + query_params[:'metadata'] = opts[:'metadata'] if !opts[:'metadata'].nil? + query_params[:'metadata[example1]'] = opts[:'metadata_example1'] if !opts[:'metadata_example1'].nil? + query_params[:'metadata[example2]'] = opts[:'metadata_example2'] if !opts[:'metadata_example2'].nil? # header parameters header_params = opts[:header_params] || {} diff --git a/lib/patch_ruby/models/create_ethereum_estimate_request.rb b/lib/patch_ruby/models/create_ethereum_estimate_request.rb index 3521122..b5d30bf 100644 --- a/lib/patch_ruby/models/create_ethereum_estimate_request.rb +++ b/lib/patch_ruby/models/create_ethereum_estimate_request.rb @@ -18,6 +18,8 @@ class CreateEthereumEstimateRequest attr_accessor :gas_used + attr_accessor :transaction_value_eth_gwei + attr_accessor :project_id attr_accessor :create_order @@ -27,6 +29,7 @@ def self.attribute_map { :'timestamp' => :'timestamp', :'gas_used' => :'gas_used', + :'transaction_value_eth_gwei' => :'transaction_value_eth_gwei', :'project_id' => :'project_id', :'create_order' => :'create_order' } @@ -37,6 +40,7 @@ def self.openapi_types { :'timestamp' => :'String', :'gas_used' => :'Integer', + :'transaction_value_eth_gwei' => :'Integer', :'project_id' => :'String', :'create_order' => :'Boolean' } @@ -50,6 +54,8 @@ def self.openapi_nullable nullable_properties.add("gas_used") + nullable_properties.add("transaction_value_eth_gwei") + nullable_properties.add("project_id") nullable_properties.add("create_order") @@ -91,6 +97,10 @@ def initialize(attributes = {}) self.gas_used = attributes[:'gas_used'] end + if attributes.key?(:'transaction_value_eth_gwei') + self.transaction_value_eth_gwei = attributes[:'transaction_value_eth_gwei'] + end + if attributes.key?(:'project_id') self.project_id = attributes[:'project_id'] end @@ -120,6 +130,7 @@ def ==(o) self.class == o.class && timestamp == o.timestamp && gas_used == o.gas_used && + transaction_value_eth_gwei == o.transaction_value_eth_gwei && project_id == o.project_id && create_order == o.create_order end @@ -133,7 +144,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [timestamp, gas_used, project_id, create_order].hash + [timestamp, gas_used, transaction_value_eth_gwei, project_id, create_order].hash end # Builds the object from hash diff --git a/lib/patch_ruby/models/estimate.rb b/lib/patch_ruby/models/estimate.rb index 69f2bd7..3ab7b3d 100644 --- a/lib/patch_ruby/models/estimate.rb +++ b/lib/patch_ruby/models/estimate.rb @@ -20,7 +20,7 @@ class Estimate # A boolean indicating if this estimate is a production or test mode estimate. attr_accessor :production - # The type of estimate. Available types are mass, flight, shipping, and vehicle. + # The type of estimate. Available types are mass, flight, shipping, vehicle, and crypto. attr_accessor :type # The estimated mass in grams for this estimate. diff --git a/lib/patch_ruby/version.rb b/lib/patch_ruby/version.rb index b68ae7e..f992fe1 100644 --- a/lib/patch_ruby/version.rb +++ b/lib/patch_ruby/version.rb @@ -11,5 +11,5 @@ =end module Patch - VERSION = '1.8.0' + VERSION = '1.9.0' end diff --git a/spec/integration/estimates_spec.rb b/spec/integration/estimates_spec.rb index 49e3c70..4aea197 100644 --- a/spec/integration/estimates_spec.rb +++ b/spec/integration/estimates_spec.rb @@ -1,10 +1,4 @@ RSpec.describe 'Estimates Integration' do - before do - Patch.configure do |config| - config.access_token = ENV['SANDBOX_API_KEY'] - end - end - it 'supports create, retrieve and list' do create_estimate_response = Patch::Estimate.create_mass_estimate(mass_g: 100) estimate_id = create_estimate_response.data.id @@ -33,7 +27,7 @@ ) expect(flight_estimate.data.type).to eq 'flight' - expect(flight_estimate.data.mass_g).to eq 1_031_697 + expect(flight_estimate.data.mass_g).to eq 1_000_622 end it 'supports creating vehicle estimates' do diff --git a/spec/integration/orders_spec.rb b/spec/integration/orders_spec.rb index 19daf8a..0ebf711 100644 --- a/spec/integration/orders_spec.rb +++ b/spec/integration/orders_spec.rb @@ -1,10 +1,4 @@ RSpec.describe 'Orders Integration' do - before do - Patch.configure do |config| - config.access_token = ENV['SANDBOX_API_KEY'] - end - end - it 'supports create, place, cancel, retrieve and list' do create_order_response = Patch::Order.create_order(mass_g: 100) order_id = create_order_response.data.id @@ -71,15 +65,24 @@ expect(order.registry_url).not_to be_empty end - it 'supports create with metadata' do + it 'supports creation with and querying by metadata' do metadata = { user: 'john doe' } - create_order_response = Patch::Order.create_order(mass_g: 100, metadata: metadata) + create_order_response = + Patch::Order.create_order(mass_g: 100, metadata: metadata) 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.metadata).to eq(metadata) + + retrieve_orders_response = Patch::Order.retrieve_orders( + page: 1, metadata: { user: 'john' } + ) + expect(retrieve_orders_response.success).to eq true + expect(retrieve_orders_response.data.count).to be >= 1 + expect(retrieve_orders_response.data.map(&:metadata)) + .to all(have_key(:user)) end it 'supports place and cancel for orders created via an estimate' do diff --git a/spec/integration/preferences_spec.rb b/spec/integration/preferences_spec.rb index 979b149..55021f6 100644 --- a/spec/integration/preferences_spec.rb +++ b/spec/integration/preferences_spec.rb @@ -1,10 +1,4 @@ RSpec.describe 'Preferences Integration' do - before do - Patch.configure do |config| - config.access_token = ENV['SANDBOX_API_KEY'] - end - end - it 'supports create, delete, retrieve and list' do retrieve_projects_response = Patch::Project.retrieve_projects expect(retrieve_projects_response.data.length).not_to be_zero diff --git a/spec/integration/projects_spec.rb b/spec/integration/projects_spec.rb index c91d6c3..2ef98e8 100644 --- a/spec/integration/projects_spec.rb +++ b/spec/integration/projects_spec.rb @@ -1,8 +1,4 @@ RSpec.describe 'Projects Integration' do - Patch.configure do |config| - config.access_token = ENV['SANDBOX_API_KEY'] - end - it 'supports retrieve and list' do page_limit = 1 next_page = 1 @@ -43,20 +39,12 @@ end describe 'returned fields' do - before do - @project = Patch::Project.retrieve_projects(page: 1).data.first - end - - it 'returns photos' do - expect(@project.photos).to be_an_instance_of(Array) - end - - it 'returns average_price_per_tonne_cents_usd' do - expect(@project.average_price_per_tonne_cents_usd).to be_an_instance_of(Integer) - end + it 'returns the expected fields' do + project = Patch::Project.retrieve_projects(page: 1).data.first - it 'returns remaining_mass_g' do - expect(@project.remaining_mass_g).to be_an_instance_of(Integer) + expect(project.photos).to be_an_instance_of(Array) + expect(project.average_price_per_tonne_cents_usd).to be_an_instance_of(Integer) + expect(project.remaining_mass_g).to be_an_instance_of(Integer) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f9bc511..7dd5a5d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -41,6 +41,15 @@ config.include FactoryBot::Syntax::Methods config.before(:suite) do FactoryBot.find_definitions + Patch.configure do |config| + if ENV.fetch('LOCAL_SDK_TEST', false) + config.access_token = ENV.fetch('LOCAL_PATCH_API_KEY') + config.scheme = 'http' + config.host = 'api.patch.test:3000' + else + config.access_token = ENV.fetch('SANDBOX_API_KEY') + end + end end # rspec-expectations config goes here. You can use an alternate @@ -66,6 +75,12 @@ mocks.verify_partial_doubles = true end + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. =begin @@ -107,12 +122,6 @@ # particularly slow. config.profile_examples = 10 - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - # Seed global randomization in this process using the `--seed` CLI option. # Setting this allows you to use `--seed` to deterministically reproduce # test failures related to randomization by passing the same `--seed` value