Skip to content

Commit 4dc45af

Browse files
committed
Expose API operations on model classes
1 parent 035d0bd commit 4dc45af

16 files changed

+146
-57
lines changed

README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ end
4141

4242
Once configured, you can test it out:
4343
```ruby
44-
# Retrieve and print all your orders
45-
orders_api = Patch::OrdersApi.new
46-
4744
begin
48-
orders_response = orders_api.retrieve_orders
45+
orders_response = Patch::Order.retrieve_orders
4946

5047
orders_response.data.each do |order|
5148
puts "Order ID: #{order.id}, Order State: #{order.state}"

lib/patch_ruby/api/orders_api.rb

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414

1515
module Patch
1616
class OrdersApi
17+
OPERATIONS = [
18+
:cancel_order,
19+
:create_order,
20+
:place_order,
21+
:retrieve_order,
22+
:retrieve_orders,
23+
]
24+
1725
attr_accessor :api_client
1826

1927
def initialize(api_client = ApiClient.default)

lib/patch_ruby/api/preferences_api.rb

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414

1515
module Patch
1616
class PreferencesApi
17+
OPERATIONS = [
18+
:create_preference,
19+
:delete_preference,
20+
:retrieve_preference,
21+
:retrieve_preferences,
22+
]
23+
1724
attr_accessor :api_client
1825

1926
def initialize(api_client = ApiClient.default)

lib/patch_ruby/api/projects_api.rb

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
module Patch
1616
class ProjectsApi
17+
OPERATIONS = [
18+
:retrieve_project,
19+
:retrieve_projects,
20+
]
21+
1722
attr_accessor :api_client
1823

1924
def initialize(api_client = ApiClient.default)

lib/patch_ruby/models/allocation.rb

+9-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ def self.openapi_types
3838
}
3939
end
4040

41-
# List of attributes with nullable: true
42-
def self.openapi_nullable
43-
Set.new([
44-
])
41+
# Allows models with corresponding API classes to delegate API operations to those API classes
42+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
44+
def self.method_missing(message, *args, &block)
45+
if Object.const_defined?('Patch::AllocationsApi::OPERATIONS') && Patch::AllocationsApi::OPERATIONS.include?(message)
46+
Patch::AllocationsApi.new.send(message, *args)
47+
else
48+
super
49+
end
4550
end
4651

4752
# Initializes the object

lib/patch_ruby/models/error_response.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ def self.openapi_types
3838
}
3939
end
4040

41-
# List of attributes with nullable: true
42-
def self.openapi_nullable
43-
Set.new([
44-
:'data'
45-
])
41+
# Allows models with corresponding API classes to delegate API operations to those API classes
42+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
44+
def self.method_missing(message, *args, &block)
45+
if Object.const_defined?('Patch::ErrorResponsesApi::OPERATIONS') && Patch::ErrorResponsesApi::OPERATIONS.include?(message)
46+
Patch::ErrorResponsesApi.new.send(message, *args)
47+
else
48+
super
49+
end
4650
end
4751

4852
# Initializes the object

lib/patch_ruby/models/order.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,15 @@ def self.openapi_types
7676
}
7777
end
7878

79-
# List of attributes with nullable: true
80-
def self.openapi_nullable
81-
Set.new([
82-
:'price_cents_usd',
83-
])
79+
# Allows models with corresponding API classes to delegate API operations to those API classes
80+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
81+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
82+
def self.method_missing(message, *args, &block)
83+
if Object.const_defined?('Patch::OrdersApi::OPERATIONS') && Patch::OrdersApi::OPERATIONS.include?(message)
84+
Patch::OrdersApi.new.send(message, *args)
85+
else
86+
super
87+
end
8488
end
8589

8690
# Initializes the object

lib/patch_ruby/models/order_list_response.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ def self.openapi_types
3838
}
3939
end
4040

41-
# List of attributes with nullable: true
42-
def self.openapi_nullable
43-
Set.new([
44-
:'error',
45-
])
41+
# Allows models with corresponding API classes to delegate API operations to those API classes
42+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
44+
def self.method_missing(message, *args, &block)
45+
if Object.const_defined?('Patch::OrderListResponsesApi::OPERATIONS') && Patch::OrderListResponsesApi::OPERATIONS.include?(message)
46+
Patch::OrderListResponsesApi.new.send(message, *args)
47+
else
48+
super
49+
end
4650
end
4751

4852
# Initializes the object

lib/patch_ruby/models/order_response.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ def self.openapi_types
3838
}
3939
end
4040

41-
# List of attributes with nullable: true
42-
def self.openapi_nullable
43-
Set.new([
44-
:'error',
45-
])
41+
# Allows models with corresponding API classes to delegate API operations to those API classes
42+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
44+
def self.method_missing(message, *args, &block)
45+
if Object.const_defined?('Patch::OrderResponsesApi::OPERATIONS') && Patch::OrderResponsesApi::OPERATIONS.include?(message)
46+
Patch::OrderResponsesApi.new.send(message, *args)
47+
else
48+
super
49+
end
4650
end
4751

4852
# Initializes the object

lib/patch_ruby/models/preference.rb

+9-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ def self.openapi_types
3838
}
3939
end
4040

41-
# List of attributes with nullable: true
42-
def self.openapi_nullable
43-
Set.new([
44-
])
41+
# Allows models with corresponding API classes to delegate API operations to those API classes
42+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
44+
def self.method_missing(message, *args, &block)
45+
if Object.const_defined?('Patch::PreferencesApi::OPERATIONS') && Patch::PreferencesApi::OPERATIONS.include?(message)
46+
Patch::PreferencesApi.new.send(message, *args)
47+
else
48+
super
49+
end
4550
end
4651

4752
# Initializes the object

lib/patch_ruby/models/preference_list_response.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ def self.openapi_types
3838
}
3939
end
4040

41-
# List of attributes with nullable: true
42-
def self.openapi_nullable
43-
Set.new([
44-
:'error',
45-
])
41+
# Allows models with corresponding API classes to delegate API operations to those API classes
42+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
44+
def self.method_missing(message, *args, &block)
45+
if Object.const_defined?('Patch::PreferenceListResponsesApi::OPERATIONS') && Patch::PreferenceListResponsesApi::OPERATIONS.include?(message)
46+
Patch::PreferenceListResponsesApi.new.send(message, *args)
47+
else
48+
super
49+
end
4650
end
4751

4852
# Initializes the object

lib/patch_ruby/models/preference_response.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ def self.openapi_types
3838
}
3939
end
4040

41-
# List of attributes with nullable: true
42-
def self.openapi_nullable
43-
Set.new([
44-
:'error',
45-
])
41+
# Allows models with corresponding API classes to delegate API operations to those API classes
42+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
44+
def self.method_missing(message, *args, &block)
45+
if Object.const_defined?('Patch::PreferenceResponsesApi::OPERATIONS') && Patch::PreferenceResponsesApi::OPERATIONS.include?(message)
46+
Patch::PreferenceResponsesApi.new.send(message, *args)
47+
else
48+
super
49+
end
4650
end
4751

4852
# Initializes the object

lib/patch_ruby/models/project.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ def self.openapi_types
6262
}
6363
end
6464

65-
# List of attributes with nullable: true
66-
def self.openapi_nullable
67-
Set.new([
68-
:'verifier',
69-
])
65+
# Allows models with corresponding API classes to delegate API operations to those API classes
66+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
67+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
68+
def self.method_missing(message, *args, &block)
69+
if Object.const_defined?('Patch::ProjectsApi::OPERATIONS') && Patch::ProjectsApi::OPERATIONS.include?(message)
70+
Patch::ProjectsApi.new.send(message, *args)
71+
else
72+
super
73+
end
7074
end
7175

7276
# Initializes the object

lib/patch_ruby/models/project_list_response.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ def self.openapi_types
3838
}
3939
end
4040

41-
# List of attributes with nullable: true
42-
def self.openapi_nullable
43-
Set.new([
44-
:'error',
45-
])
41+
# Allows models with corresponding API classes to delegate API operations to those API classes
42+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
44+
def self.method_missing(message, *args, &block)
45+
if Object.const_defined?('Patch::ProjectListResponsesApi::OPERATIONS') && Patch::ProjectListResponsesApi::OPERATIONS.include?(message)
46+
Patch::ProjectListResponsesApi.new.send(message, *args)
47+
else
48+
super
49+
end
4650
end
4751

4852
# Initializes the object

lib/patch_ruby/models/project_response.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ def self.openapi_types
3838
}
3939
end
4040

41-
# List of attributes with nullable: true
42-
def self.openapi_nullable
43-
Set.new([
44-
:'error',
45-
])
41+
# Allows models with corresponding API classes to delegate API operations to those API classes
42+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
44+
def self.method_missing(message, *args, &block)
45+
if Object.const_defined?('Patch::ProjectResponsesApi::OPERATIONS') && Patch::ProjectResponsesApi::OPERATIONS.include?(message)
46+
Patch::ProjectResponsesApi.new.send(message, *args)
47+
else
48+
super
49+
end
4650
end
4751

4852
# Initializes the object

spec/integration/orders_spec.rb

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe 'Orders Integration' do
4+
xit "supports create, place, cancel, retrieve and list" do
5+
Patch.configure do |config|
6+
# TODO replace with an environment variable
7+
config.access_token = 'key_test_123'
8+
config.host = 'https://api.staging-patch.com/'
9+
end
10+
11+
create_order_response = Patch::Order.create_order(body: { mass_g: 100 })
12+
order_id = create_order_response.data.id
13+
14+
retrieve_order_response = Patch::Order.retrieve_order(order_id)
15+
expect(retrieve_order_response.data.id).to eq order_id
16+
17+
# place_order_response = Patch::Order.place_order(order_id)
18+
# expect(place_order_response.data.state).to eq 'placed'
19+
20+
# place_order_response = Patch::Order.cancel_order(order_id)
21+
# expect(place_order_response.data.state).to eq 'cancelled'
22+
23+
retrieve_orders_response = Patch::Order.retrieve_orders
24+
expect(retrieve_orders_response.data).to be_a(Array)
25+
end
26+
end

0 commit comments

Comments
 (0)