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

Lines changed: 1 addition & 4 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 9 additions & 4 deletions
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

Lines changed: 9 additions & 5 deletions
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

Lines changed: 9 additions & 5 deletions
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

Lines changed: 9 additions & 5 deletions
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

Lines changed: 9 additions & 5 deletions
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

Lines changed: 9 additions & 4 deletions
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

0 commit comments

Comments
 (0)