Skip to content

Metadata query params #34

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 8 commits into from
Aug 18, 2021
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
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
strategy:
matrix:
ruby-version: [3.0.1, 2.7.4, 2.6.8]
max-parallel: 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this will slow down CI but reduce the amount of "collisions" we may see due to the same tests running on the same endpoints in parallel. Considering we don't run CI on these projects very frequently, I feel the stability is worth the extra 2 minutes until we change up the test suite to not hit the real API

Copy link
Contributor

Choose a reason for hiding this comment

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

This makes sense!


steps:
- name: Check out code
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.0
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on having this be Unreleased until we tag main ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bspellacy not sure I follow. What's the release flow you have in mind? I'm planning on releasing all the SDKs then the changes to patch (docs)


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

Expand Down
29 changes: 29 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -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")
9 changes: 9 additions & 0 deletions lib/patch_ruby/api/orders_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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] || {}
Expand Down
13 changes: 12 additions & 1 deletion lib/patch_ruby/models/create_ethereum_estimate_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CreateEthereumEstimateRequest

attr_accessor :gas_used

attr_accessor :transaction_value_eth_gwei

attr_accessor :project_id

attr_accessor :create_order
Expand All @@ -27,6 +29,7 @@ def self.attribute_map
{
:'timestamp' => :'timestamp',
:'gas_used' => :'gas_used',
:'transaction_value_eth_gwei' => :'transaction_value_eth_gwei',
Copy link
Contributor

Choose a reason for hiding this comment

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

@kleinjm can you add this one to the changelog?

:'project_id' => :'project_id',
:'create_order' => :'create_order'
}
Expand All @@ -37,6 +40,7 @@ def self.openapi_types
{
:'timestamp' => :'String',
:'gas_used' => :'Integer',
:'transaction_value_eth_gwei' => :'Integer',
:'project_id' => :'String',
:'create_order' => :'Boolean'
}
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/patch_ruby/models/estimate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.8.0'
VERSION = '1.9.0'
end
8 changes: 1 addition & 7 deletions spec/integration/estimates_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I confirmed this change is correct with Brendan

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, we will probably want to remove this type of tests from the SDK itself.

end

it 'supports creating vehicle estimates' do
Expand Down
19 changes: 11 additions & 8 deletions spec/integration/orders_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel this is the most stable strategy for now. Creating an order with metadata and then querying for it in the same spec reduces the chance of the order being on a following page

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
Expand Down
6 changes: 0 additions & 6 deletions spec/integration/preferences_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
RSpec.describe 'Preferences Integration' do
before do
Patch.configure do |config|
config.access_token = ENV['SANDBOX_API_KEY']
end
end
Comment on lines -2 to -6
Copy link
Contributor

Choose a reason for hiding this comment

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

Moved to the helper


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
Expand Down
22 changes: 5 additions & 17 deletions spec/integration/projects_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -43,20 +39,12 @@
end

describe 'returned fields' do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

combining specs here for performance and stability

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
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

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
21 changes: 15 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Comment on lines +45 to +46
Copy link
Contributor Author

Choose a reason for hiding this comment

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

set these 2 env vars to run tests against your local patch instance

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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down