Skip to content

Commit

Permalink
Refactor after SDK based generation pattern (#1354)
Browse files Browse the repository at this point in the history
* Refactor after SDK based generation pattern

* update for object types & reorder
  • Loading branch information
helenye-stripe committed Mar 11, 2024
1 parent e2893a2 commit 4705a5f
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 100 deletions.
9 changes: 4 additions & 5 deletions lib/stripe/object_types.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# File generated from our OpenAPI spec
# frozen_string_literal: true

# rubocop:disable Metrics/MethodLength
Expand All @@ -11,9 +10,9 @@ def self.object_names_to_classes
# data structures
ListObject.object_name => ListObject,
SearchResultObject.object_name => SearchResultObject,

# business objects
File.object_name_alt => File,

# The beginning of the section generated from our OpenAPI spec
Account.object_name => Account,
AccountLink.object_name => AccountLink,
AccountSession.object_name => AccountSession,
Expand Down Expand Up @@ -51,8 +50,7 @@ def self.object_names_to_classes
FileLink.object_name => FileLink,
FinancialConnections::Account.object_name => FinancialConnections::Account,
FinancialConnections::AccountOwner.object_name => FinancialConnections::AccountOwner,
FinancialConnections::AccountOwnership.object_name =>
FinancialConnections::AccountOwnership,
FinancialConnections::AccountOwnership.object_name => FinancialConnections::AccountOwnership,
FinancialConnections::Session.object_name => FinancialConnections::Session,
FinancialConnections::Transaction.object_name => FinancialConnections::Transaction,
FundingInstructions.object_name => FundingInstructions,
Expand Down Expand Up @@ -130,6 +128,7 @@ def self.object_names_to_classes
UsageRecord.object_name => UsageRecord,
UsageRecordSummary.object_name => UsageRecordSummary,
WebhookEndpoint.object_name => WebhookEndpoint,
# The end of the section generated from our OpenAPI spec
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/resources/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Account < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save
extend Stripe::APIOperations::NestedResource
include Stripe::APIOperations::Save

OBJECT_NAME = "account"
def self.object_name
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/resources/charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module Stripe
class Charge < APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
extend Stripe::APIOperations::NestedResource
extend Stripe::APIOperations::Search
include Stripe::APIOperations::Save
extend Stripe::APIOperations::NestedResource

OBJECT_NAME = "charge"
def self.object_name
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/resources/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Customer < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
extend Stripe::APIOperations::NestedResource
extend Stripe::APIOperations::Search
include Stripe::APIOperations::Save
extend Stripe::APIOperations::NestedResource

OBJECT_NAME = "customer"
def self.object_name
Expand Down
48 changes: 24 additions & 24 deletions lib/stripe/resources/issuing/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ def self.capture(authorization, params = {}, opts = {})
)
end

# Capture a test-mode authorization.
def capture(params = {}, opts = {})
@resource.request_stripe_object(
method: :post,
path: format("/v1/test_helpers/issuing/authorizations/%<authorization>s/capture", { authorization: CGI.escape(@resource["id"]) }),
params: params,
opts: opts
)
end

# Create a test-mode authorization.
def self.create(params = {}, opts = {})
request_stripe_object(
Expand All @@ -121,51 +131,41 @@ def self.expire(authorization, params = {}, opts = {})
)
end

# Increment a test-mode Authorization.
def self.increment(authorization, params = {}, opts = {})
request_stripe_object(
# Expire a test-mode Authorization.
def expire(params = {}, opts = {})
@resource.request_stripe_object(
method: :post,
path: format("/v1/test_helpers/issuing/authorizations/%<authorization>s/increment", { authorization: CGI.escape(authorization) }),
path: format("/v1/test_helpers/issuing/authorizations/%<authorization>s/expire", { authorization: CGI.escape(@resource["id"]) }),
params: params,
opts: opts
)
end

# Reverse a test-mode Authorization.
def self.reverse(authorization, params = {}, opts = {})
# Increment a test-mode Authorization.
def self.increment(authorization, params = {}, opts = {})
request_stripe_object(
method: :post,
path: format("/v1/test_helpers/issuing/authorizations/%<authorization>s/reverse", { authorization: CGI.escape(authorization) }),
params: params,
opts: opts
)
end

# Capture a test-mode authorization.
def capture(params = {}, opts = {})
@resource.request_stripe_object(
method: :post,
path: format("/v1/test_helpers/issuing/authorizations/%<authorization>s/capture", { authorization: CGI.escape(@resource["id"]) }),
path: format("/v1/test_helpers/issuing/authorizations/%<authorization>s/increment", { authorization: CGI.escape(authorization) }),
params: params,
opts: opts
)
end

# Expire a test-mode Authorization.
def expire(params = {}, opts = {})
# Increment a test-mode Authorization.
def increment(params = {}, opts = {})
@resource.request_stripe_object(
method: :post,
path: format("/v1/test_helpers/issuing/authorizations/%<authorization>s/expire", { authorization: CGI.escape(@resource["id"]) }),
path: format("/v1/test_helpers/issuing/authorizations/%<authorization>s/increment", { authorization: CGI.escape(@resource["id"]) }),
params: params,
opts: opts
)
end

# Increment a test-mode Authorization.
def increment(params = {}, opts = {})
@resource.request_stripe_object(
# Reverse a test-mode Authorization.
def self.reverse(authorization, params = {}, opts = {})
request_stripe_object(
method: :post,
path: format("/v1/test_helpers/issuing/authorizations/%<authorization>s/increment", { authorization: CGI.escape(@resource["id"]) }),
path: format("/v1/test_helpers/issuing/authorizations/%<authorization>s/reverse", { authorization: CGI.escape(authorization) }),
params: params,
opts: opts
)
Expand Down
44 changes: 22 additions & 22 deletions lib/stripe/resources/issuing/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,61 +54,61 @@ def self.deliver_card(card, params = {}, opts = {})
)
end

# Updates the shipping status of the specified Issuing Card object to failure.
def self.fail_card(card, params = {}, opts = {})
request_stripe_object(
# Updates the shipping status of the specified Issuing Card object to delivered.
def deliver_card(params = {}, opts = {})
@resource.request_stripe_object(
method: :post,
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/fail", { card: CGI.escape(card) }),
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/deliver", { card: CGI.escape(@resource["id"]) }),
params: params,
opts: opts
)
end

# Updates the shipping status of the specified Issuing Card object to returned.
def self.return_card(card, params = {}, opts = {})
# Updates the shipping status of the specified Issuing Card object to failure.
def self.fail_card(card, params = {}, opts = {})
request_stripe_object(
method: :post,
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/return", { card: CGI.escape(card) }),
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/fail", { card: CGI.escape(card) }),
params: params,
opts: opts
)
end

# Updates the shipping status of the specified Issuing Card object to shipped.
def self.ship_card(card, params = {}, opts = {})
request_stripe_object(
# Updates the shipping status of the specified Issuing Card object to failure.
def fail_card(params = {}, opts = {})
@resource.request_stripe_object(
method: :post,
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/ship", { card: CGI.escape(card) }),
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/fail", { card: CGI.escape(@resource["id"]) }),
params: params,
opts: opts
)
end

# Updates the shipping status of the specified Issuing Card object to delivered.
def deliver_card(params = {}, opts = {})
@resource.request_stripe_object(
# Updates the shipping status of the specified Issuing Card object to returned.
def self.return_card(card, params = {}, opts = {})
request_stripe_object(
method: :post,
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/deliver", { card: CGI.escape(@resource["id"]) }),
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/return", { card: CGI.escape(card) }),
params: params,
opts: opts
)
end

# Updates the shipping status of the specified Issuing Card object to failure.
def fail_card(params = {}, opts = {})
# Updates the shipping status of the specified Issuing Card object to returned.
def return_card(params = {}, opts = {})
@resource.request_stripe_object(
method: :post,
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/fail", { card: CGI.escape(@resource["id"]) }),
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/return", { card: CGI.escape(@resource["id"]) }),
params: params,
opts: opts
)
end

# Updates the shipping status of the specified Issuing Card object to returned.
def return_card(params = {}, opts = {})
@resource.request_stripe_object(
# Updates the shipping status of the specified Issuing Card object to shipped.
def self.ship_card(card, params = {}, opts = {})
request_stripe_object(
method: :post,
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/return", { card: CGI.escape(@resource["id"]) }),
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/ship", { card: CGI.escape(card) }),
params: params,
opts: opts
)
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/resources/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module Stripe
# Related guides: [Sources API](https://stripe.com/docs/sources) and [Sources & Customers](https://stripe.com/docs/sources/customers).
class Source < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Save
extend Stripe::APIOperations::NestedResource
include Stripe::APIOperations::Save

OBJECT_NAME = "source"
def self.object_name
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/resources/subscription_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class SubscriptionItem < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save
extend Stripe::APIOperations::NestedResource
include Stripe::APIOperations::Save

OBJECT_NAME = "subscription_item"
def self.object_name
Expand Down
1 change: 0 additions & 1 deletion lib/stripe/resources/tax/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module Tax
# Related guide: [Using the Settings API](https://stripe.com/docs/tax/settings-api)
class Settings < SingletonAPIResource
include Stripe::APIOperations::SingletonSave

OBJECT_NAME = "tax.settings"
def self.object_name
"tax.settings"
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/resources/transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module Stripe
class Transfer < APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save
extend Stripe::APIOperations::NestedResource
include Stripe::APIOperations::Save

OBJECT_NAME = "transfer"
def self.object_name
Expand Down
28 changes: 14 additions & 14 deletions lib/stripe/resources/treasury/inbound_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,41 +73,41 @@ def self.fail(id, params = {}, opts = {})
)
end

# Marks the test mode InboundTransfer object as returned and links the InboundTransfer to a ReceivedDebit. The InboundTransfer must already be in the succeeded state.
def self.return_inbound_transfer(id, params = {}, opts = {})
request_stripe_object(
# Transitions a test mode created InboundTransfer to the failed status. The InboundTransfer must already be in the processing state.
def fail(params = {}, opts = {})
@resource.request_stripe_object(
method: :post,
path: format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/return", { id: CGI.escape(id) }),
path: format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/fail", { id: CGI.escape(@resource["id"]) }),
params: params,
opts: opts
)
end

# Transitions a test mode created InboundTransfer to the succeeded status. The InboundTransfer must already be in the processing state.
def self.succeed(id, params = {}, opts = {})
# Marks the test mode InboundTransfer object as returned and links the InboundTransfer to a ReceivedDebit. The InboundTransfer must already be in the succeeded state.
def self.return_inbound_transfer(id, params = {}, opts = {})
request_stripe_object(
method: :post,
path: format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/succeed", { id: CGI.escape(id) }),
path: format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/return", { id: CGI.escape(id) }),
params: params,
opts: opts
)
end

# Transitions a test mode created InboundTransfer to the failed status. The InboundTransfer must already be in the processing state.
def fail(params = {}, opts = {})
# Marks the test mode InboundTransfer object as returned and links the InboundTransfer to a ReceivedDebit. The InboundTransfer must already be in the succeeded state.
def return_inbound_transfer(params = {}, opts = {})
@resource.request_stripe_object(
method: :post,
path: format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/fail", { id: CGI.escape(@resource["id"]) }),
path: format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/return", { id: CGI.escape(@resource["id"]) }),
params: params,
opts: opts
)
end

# Marks the test mode InboundTransfer object as returned and links the InboundTransfer to a ReceivedDebit. The InboundTransfer must already be in the succeeded state.
def return_inbound_transfer(params = {}, opts = {})
@resource.request_stripe_object(
# Transitions a test mode created InboundTransfer to the succeeded status. The InboundTransfer must already be in the processing state.
def self.succeed(id, params = {}, opts = {})
request_stripe_object(
method: :post,
path: format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/return", { id: CGI.escape(@resource["id"]) }),
path: format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/succeed", { id: CGI.escape(id) }),
params: params,
opts: opts
)
Expand Down
28 changes: 14 additions & 14 deletions lib/stripe/resources/treasury/outbound_payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,41 +75,41 @@ def self.fail(id, params = {}, opts = {})
)
end

# Transitions a test mode created OutboundPayment to the posted status. The OutboundPayment must already be in the processing state.
def self.post(id, params = {}, opts = {})
request_stripe_object(
# Transitions a test mode created OutboundPayment to the failed status. The OutboundPayment must already be in the processing state.
def fail(params = {}, opts = {})
@resource.request_stripe_object(
method: :post,
path: format("/v1/test_helpers/treasury/outbound_payments/%<id>s/post", { id: CGI.escape(id) }),
path: format("/v1/test_helpers/treasury/outbound_payments/%<id>s/fail", { id: CGI.escape(@resource["id"]) }),
params: params,
opts: opts
)
end

# Transitions a test mode created OutboundPayment to the returned status. The OutboundPayment must already be in the processing state.
def self.return_outbound_payment(id, params = {}, opts = {})
# Transitions a test mode created OutboundPayment to the posted status. The OutboundPayment must already be in the processing state.
def self.post(id, params = {}, opts = {})
request_stripe_object(
method: :post,
path: format("/v1/test_helpers/treasury/outbound_payments/%<id>s/return", { id: CGI.escape(id) }),
path: format("/v1/test_helpers/treasury/outbound_payments/%<id>s/post", { id: CGI.escape(id) }),
params: params,
opts: opts
)
end

# Transitions a test mode created OutboundPayment to the failed status. The OutboundPayment must already be in the processing state.
def fail(params = {}, opts = {})
# Transitions a test mode created OutboundPayment to the posted status. The OutboundPayment must already be in the processing state.
def post(params = {}, opts = {})
@resource.request_stripe_object(
method: :post,
path: format("/v1/test_helpers/treasury/outbound_payments/%<id>s/fail", { id: CGI.escape(@resource["id"]) }),
path: format("/v1/test_helpers/treasury/outbound_payments/%<id>s/post", { id: CGI.escape(@resource["id"]) }),
params: params,
opts: opts
)
end

# Transitions a test mode created OutboundPayment to the posted status. The OutboundPayment must already be in the processing state.
def post(params = {}, opts = {})
@resource.request_stripe_object(
# Transitions a test mode created OutboundPayment to the returned status. The OutboundPayment must already be in the processing state.
def self.return_outbound_payment(id, params = {}, opts = {})
request_stripe_object(
method: :post,
path: format("/v1/test_helpers/treasury/outbound_payments/%<id>s/post", { id: CGI.escape(@resource["id"]) }),
path: format("/v1/test_helpers/treasury/outbound_payments/%<id>s/return", { id: CGI.escape(id) }),
params: params,
opts: opts
)
Expand Down

0 comments on commit 4705a5f

Please sign in to comment.