Skip to content

Commit ae67c8d

Browse files
authored
Metadata query params for Orders endpoint (#34)
1 parent 8f3adf9 commit ae67c8d

File tree

14 files changed

+94
-48
lines changed

14 files changed

+94
-48
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
ruby-version: [3.0.1, 2.7.4, 2.6.8]
16+
max-parallel: 1
1617

1718
steps:
1819
- name: Check out code

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0.0

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.9.0] - 2021-08-17
9+
10+
### Added
11+
12+
- Add support for querying Orders by `metadata`
13+
- Added `transaction_value_eth_gwei` as an alternative way to compute transaction level emissions for ethereum
14+
815
## [1.8.0] - 2021-07-20
916

1017
### Added

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
patch_ruby (1.8.0)
4+
patch_ruby (1.9.0)
55
json (~> 2.1, >= 2.1.0)
66
typhoeus (~> 1.0, >= 1.0.1)
77

bin/rspec

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rspec' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
14+
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
16+
17+
if File.file?(bundle_binstub)
18+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19+
load(bundle_binstub)
20+
else
21+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23+
end
24+
end
25+
26+
require "rubygems"
27+
require "bundler/setup"
28+
29+
load Gem.bin_path("rspec-core", "rspec")

lib/patch_ruby/api/orders_api.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ def retrieve_order_with_http_info(id, opts = {})
281281
# 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.
282282
# @param [Hash] opts the optional parameters
283283
# @option opts [Integer] :page
284+
# @option opts [String] :metadata
285+
# @option opts [String] :metadata_example1
286+
# @option opts [String] :metadata_example2
284287
# @return [OrderListResponse]
285288
def retrieve_orders(opts = {})
286289
data, _status_code, _headers = retrieve_orders_with_http_info(opts)
@@ -291,6 +294,9 @@ def retrieve_orders(opts = {})
291294
# 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.
292295
# @param [Hash] opts the optional parameters
293296
# @option opts [Integer] :page
297+
# @option opts [String] :metadata
298+
# @option opts [String] :metadata_example1
299+
# @option opts [String] :metadata_example2
294300
# @return [Array<(OrderListResponse, Integer, Hash)>] OrderListResponse data, response status code and response headers
295301
def retrieve_orders_with_http_info(opts = {})
296302
if @api_client.config.debugging
@@ -302,6 +308,9 @@ def retrieve_orders_with_http_info(opts = {})
302308
# query parameters
303309
query_params = opts[:query_params] || {}
304310
query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
311+
query_params[:'metadata'] = opts[:'metadata'] if !opts[:'metadata'].nil?
312+
query_params[:'metadata[example1]'] = opts[:'metadata_example1'] if !opts[:'metadata_example1'].nil?
313+
query_params[:'metadata[example2]'] = opts[:'metadata_example2'] if !opts[:'metadata_example2'].nil?
305314

306315
# header parameters
307316
header_params = opts[:header_params] || {}

lib/patch_ruby/models/create_ethereum_estimate_request.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class CreateEthereumEstimateRequest
1818

1919
attr_accessor :gas_used
2020

21+
attr_accessor :transaction_value_eth_gwei
22+
2123
attr_accessor :project_id
2224

2325
attr_accessor :create_order
@@ -27,6 +29,7 @@ def self.attribute_map
2729
{
2830
:'timestamp' => :'timestamp',
2931
:'gas_used' => :'gas_used',
32+
:'transaction_value_eth_gwei' => :'transaction_value_eth_gwei',
3033
:'project_id' => :'project_id',
3134
:'create_order' => :'create_order'
3235
}
@@ -37,6 +40,7 @@ def self.openapi_types
3740
{
3841
:'timestamp' => :'String',
3942
:'gas_used' => :'Integer',
43+
:'transaction_value_eth_gwei' => :'Integer',
4044
:'project_id' => :'String',
4145
:'create_order' => :'Boolean'
4246
}
@@ -50,6 +54,8 @@ def self.openapi_nullable
5054

5155
nullable_properties.add("gas_used")
5256

57+
nullable_properties.add("transaction_value_eth_gwei")
58+
5359
nullable_properties.add("project_id")
5460

5561
nullable_properties.add("create_order")
@@ -91,6 +97,10 @@ def initialize(attributes = {})
9197
self.gas_used = attributes[:'gas_used']
9298
end
9399

100+
if attributes.key?(:'transaction_value_eth_gwei')
101+
self.transaction_value_eth_gwei = attributes[:'transaction_value_eth_gwei']
102+
end
103+
94104
if attributes.key?(:'project_id')
95105
self.project_id = attributes[:'project_id']
96106
end
@@ -120,6 +130,7 @@ def ==(o)
120130
self.class == o.class &&
121131
timestamp == o.timestamp &&
122132
gas_used == o.gas_used &&
133+
transaction_value_eth_gwei == o.transaction_value_eth_gwei &&
123134
project_id == o.project_id &&
124135
create_order == o.create_order
125136
end
@@ -133,7 +144,7 @@ def eql?(o)
133144
# Calculates hash code according to all attributes.
134145
# @return [Integer] Hash code
135146
def hash
136-
[timestamp, gas_used, project_id, create_order].hash
147+
[timestamp, gas_used, transaction_value_eth_gwei, project_id, create_order].hash
137148
end
138149

139150
# Builds the object from hash

lib/patch_ruby/models/estimate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Estimate
2020
# A boolean indicating if this estimate is a production or test mode estimate.
2121
attr_accessor :production
2222

23-
# The type of estimate. Available types are mass, flight, shipping, and vehicle.
23+
# The type of estimate. Available types are mass, flight, shipping, vehicle, and crypto.
2424
attr_accessor :type
2525

2626
# The estimated mass in grams for this estimate.

lib/patch_ruby/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
=end
1212

1313
module Patch
14-
VERSION = '1.8.0'
14+
VERSION = '1.9.0'
1515
end

spec/integration/estimates_spec.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
RSpec.describe 'Estimates Integration' do
2-
before do
3-
Patch.configure do |config|
4-
config.access_token = ENV['SANDBOX_API_KEY']
5-
end
6-
end
7-
82
it 'supports create, retrieve and list' do
93
create_estimate_response = Patch::Estimate.create_mass_estimate(mass_g: 100)
104
estimate_id = create_estimate_response.data.id
@@ -33,7 +27,7 @@
3327
)
3428

3529
expect(flight_estimate.data.type).to eq 'flight'
36-
expect(flight_estimate.data.mass_g).to eq 1_031_697
30+
expect(flight_estimate.data.mass_g).to eq 1_000_622
3731
end
3832

3933
it 'supports creating vehicle estimates' do

spec/integration/orders_spec.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
RSpec.describe 'Orders Integration' do
2-
before do
3-
Patch.configure do |config|
4-
config.access_token = ENV['SANDBOX_API_KEY']
5-
end
6-
end
7-
82
it 'supports create, place, cancel, retrieve and list' do
93
create_order_response = Patch::Order.create_order(mass_g: 100)
104
order_id = create_order_response.data.id
@@ -71,15 +65,24 @@
7165
expect(order.registry_url).not_to be_empty
7266
end
7367

74-
it 'supports create with metadata' do
68+
it 'supports creation with and querying by metadata' do
7569
metadata = { user: 'john doe' }
7670

77-
create_order_response = Patch::Order.create_order(mass_g: 100, metadata: metadata)
71+
create_order_response =
72+
Patch::Order.create_order(mass_g: 100, metadata: metadata)
7873

7974
expect(create_order_response.success).to eq true
8075
expect(create_order_response.data.id).not_to be_nil
8176
expect(create_order_response.data.mass_g).to eq(100)
8277
expect(create_order_response.data.metadata).to eq(metadata)
78+
79+
retrieve_orders_response = Patch::Order.retrieve_orders(
80+
page: 1, metadata: { user: 'john' }
81+
)
82+
expect(retrieve_orders_response.success).to eq true
83+
expect(retrieve_orders_response.data.count).to be >= 1
84+
expect(retrieve_orders_response.data.map(&:metadata))
85+
.to all(have_key(:user))
8386
end
8487

8588
it 'supports place and cancel for orders created via an estimate' do

spec/integration/preferences_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
RSpec.describe 'Preferences Integration' do
2-
before do
3-
Patch.configure do |config|
4-
config.access_token = ENV['SANDBOX_API_KEY']
5-
end
6-
end
7-
82
it 'supports create, delete, retrieve and list' do
93
retrieve_projects_response = Patch::Project.retrieve_projects
104
expect(retrieve_projects_response.data.length).not_to be_zero

spec/integration/projects_spec.rb

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
RSpec.describe 'Projects Integration' do
2-
Patch.configure do |config|
3-
config.access_token = ENV['SANDBOX_API_KEY']
4-
end
5-
62
it 'supports retrieve and list' do
73
page_limit = 1
84
next_page = 1
@@ -43,20 +39,12 @@
4339
end
4440

4541
describe 'returned fields' do
46-
before do
47-
@project = Patch::Project.retrieve_projects(page: 1).data.first
48-
end
49-
50-
it 'returns photos' do
51-
expect(@project.photos).to be_an_instance_of(Array)
52-
end
53-
54-
it 'returns average_price_per_tonne_cents_usd' do
55-
expect(@project.average_price_per_tonne_cents_usd).to be_an_instance_of(Integer)
56-
end
42+
it 'returns the expected fields' do
43+
project = Patch::Project.retrieve_projects(page: 1).data.first
5744

58-
it 'returns remaining_mass_g' do
59-
expect(@project.remaining_mass_g).to be_an_instance_of(Integer)
45+
expect(project.photos).to be_an_instance_of(Array)
46+
expect(project.average_price_per_tonne_cents_usd).to be_an_instance_of(Integer)
47+
expect(project.remaining_mass_g).to be_an_instance_of(Integer)
6048
end
6149
end
6250
end

spec/spec_helper.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141
config.include FactoryBot::Syntax::Methods
4242
config.before(:suite) do
4343
FactoryBot.find_definitions
44+
Patch.configure do |config|
45+
if ENV.fetch('LOCAL_SDK_TEST', false)
46+
config.access_token = ENV.fetch('LOCAL_PATCH_API_KEY')
47+
config.scheme = 'http'
48+
config.host = 'api.patch.test:3000'
49+
else
50+
config.access_token = ENV.fetch('SANDBOX_API_KEY')
51+
end
52+
end
4453
end
4554

4655
# rspec-expectations config goes here. You can use an alternate
@@ -66,6 +75,12 @@
6675
mocks.verify_partial_doubles = true
6776
end
6877

78+
# Run specs in random order to surface order dependencies. If you find an
79+
# order dependency and want to debug it, you can fix the order by providing
80+
# the seed, which is printed after each run.
81+
# --seed 1234
82+
config.order = :random
83+
6984
# The settings below are suggested to provide a good initial experience
7085
# with RSpec, but feel free to customize to your heart's content.
7186
=begin
@@ -107,12 +122,6 @@
107122
# particularly slow.
108123
config.profile_examples = 10
109124
110-
# Run specs in random order to surface order dependencies. If you find an
111-
# order dependency and want to debug it, you can fix the order by providing
112-
# the seed, which is printed after each run.
113-
# --seed 1234
114-
config.order = :random
115-
116125
# Seed global randomization in this process using the `--seed` CLI option.
117126
# Setting this allows you to use `--seed` to deterministically reproduce
118127
# test failures related to randomization by passing the same `--seed` value

0 commit comments

Comments
 (0)