Skip to content

Commit

Permalink
Revert API resources back to singular
Browse files Browse the repository at this point in the history
  • Loading branch information
joeltaylor committed Apr 6, 2021
1 parent e3ed0a2 commit ce4a205
Show file tree
Hide file tree
Showing 72 changed files with 463 additions and 460 deletions.
11 changes: 6 additions & 5 deletions lib/stripe/client_api_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def self.included(base)
sigma_class = api_resources.delete("scheduled_query_run")
api_resources["sigma.scheduled_query_run"] = sigma_class

# Update `invoiceitems` to match snakecase convention
invoice_item_class = api_resources.delete("invoiceitem")
api_resources["invoice_item"] = invoice_item_class

# Group namespaces that have mutiple resourses
grouped_resources = api_resources.group_by do |key, _|
key.include?(".") ? key.split(".").first : key
Expand All @@ -76,13 +80,10 @@ def self.included(base)
# Defines the methods required for chaining calls for resources that
# are namespaced. A proxy object is created so that all resource
# methods can be defined at once.
#
# NOTE: At some point, a smarter pluralization scheme may be
# necessary for resource names with complex pluralization rules.
proxy = ClientProxy.new(client: nil)
resources.each do |resource_name, resource_class|
method_name = resource_name.split(".").last
proxy.define_singleton_method("#{method_name}s") do
proxy.define_singleton_method(method_name) do
ClientProxy.new(client: proxy.client, resource: resource_class)
end
end
Expand All @@ -95,7 +96,7 @@ def self.included(base)
end
else
# Defines plural methods for non-namespaced resources
define_method("#{resource_namespace}s".to_sym) do
define_method(resource_namespace.to_sym) do
ClientProxy.new(client: self, resource: resources[0][1])
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/stripe/account_link_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Stripe
class AccountLinkTest < Test::Unit::TestCase
should "be creatable" do
link = StripeClient.new.account_links.create(
link = StripeClient.new.account_link.create(
account: "acct_123",
refresh_url: "https://stripe.com/refresh",
return_url: "https://stripe.com/return",
Expand Down
56 changes: 28 additions & 28 deletions test/stripe/account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,61 @@
module Stripe
class AccountTest < Test::Unit::TestCase
should "be listable" do
accounts = StripeClient.new.accounts.list
accounts = StripeClient.new.account.list
assert_requested :get, "#{Stripe.api_base}/v1/accounts"
assert accounts.data.is_a?(Array)
assert accounts.data[0].is_a?(Stripe::Account)
end

should "be retrievable using singular endpoint" do
account = StripeClient.new.accounts.retrieve
account = StripeClient.new.account.retrieve
assert_requested :get, "#{Stripe.api_base}/v1/account"
assert account.is_a?(Stripe::Account)
end

should "be retrievable using plural endpoint" do
account = StripeClient.new.accounts.retrieve("acct_123")
account = StripeClient.new.account.retrieve("acct_123")
assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_123"
assert account.is_a?(Stripe::Account)
end

should "be rejectable" do
account = StripeClient.new.accounts.retrieve("acct_foo")
account = StripeClient.new.account.retrieve("acct_foo")
account = account.reject(reason: "fraud")
assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{account.id}/reject"
assert account.is_a?(Stripe::Account)
end

context ".reject" do
should "reject the account" do
account = StripeClient.new.accounts.reject("acct_foo", reason: "fraud")
account = StripeClient.new.account.reject("acct_foo", reason: "fraud")
assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{account.id}/reject"
assert account.is_a?(Stripe::Account)
end
end

should "be creatable" do
account = StripeClient.new.accounts.create(metadata: {}, type: "standard")
account = StripeClient.new.account.create(metadata: {}, type: "standard")
assert_requested :post, "#{Stripe.api_base}/v1/accounts"
assert account.is_a?(Stripe::Account)
end

should "be saveable" do
account = StripeClient.new.accounts.retrieve("acct_123")
account = StripeClient.new.account.retrieve("acct_123")
account.metadata["key"] = "value"
account.save
assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{account.id}"
end

should "be updateable" do
account = StripeClient.new.accounts.update("acct_123", metadata: { foo: "bar" })
account = StripeClient.new.account.update("acct_123", metadata: { foo: "bar" })
assert_requested :post, "#{Stripe.api_base}/v1/accounts/acct_123"
assert account.is_a?(Stripe::Account)
end

context "#delete" do
should "be deletable" do
account = StripeClient.new.accounts.retrieve("acct_123")
account = StripeClient.new.account.retrieve("acct_123")
account = account.delete
assert_requested :delete, "#{Stripe.api_base}/v1/accounts/#{account.id}"
assert account.is_a?(Stripe::Account)
Expand All @@ -68,14 +68,14 @@ class AccountTest < Test::Unit::TestCase

context ".delete" do
should "be deletable" do
account = StripeClient.new.accounts.delete("acct_123")
account = StripeClient.new.account.delete("acct_123")
assert_requested :delete, "#{Stripe.api_base}/v1/accounts/acct_123"
assert account.is_a?(Stripe::Account)
end
end

should "be able to list Persons" do
account = StripeClient.new.accounts.retrieve("acct_123")
account = StripeClient.new.account.retrieve("acct_123")
persons = account.persons
assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_123/persons"
assert persons.data.is_a?(Array)
Expand All @@ -84,7 +84,7 @@ class AccountTest < Test::Unit::TestCase

context "#deauthorize" do
should "deauthorize an account" do
account = StripeClient.new.accounts.retrieve("acct_123")
account = StripeClient.new.account.retrieve("acct_123")

# Unfortunately, the OpenAPI spec doesn't yet cover anything under the
# Connect endpoints, so for just stub this out with Webmock.
Expand All @@ -97,7 +97,7 @@ class AccountTest < Test::Unit::TestCase
context "when the caller is a StripeClient" do
should "use the StripeClient options" do
client = Stripe::StripeClient.new(connect_base: "https://other.stripe.com")
account = client.accounts.retrieve("acct_123")
account = client.account.retrieve("acct_123")

stub_request(:post, "https://other.stripe.com/oauth/deauthorize")
.with(body: { "client_id" => "ca_1234", "stripe_user_id" => account.id })
Expand All @@ -111,7 +111,7 @@ class AccountTest < Test::Unit::TestCase

context "#legal_entity=" do
should "disallow direct overrides" do
account = StripeClient.new.accounts.construct_from(
account = StripeClient.new.account.construct_from(
id: "acct_123",
legal_entity: {
first_name: "name",
Expand Down Expand Up @@ -266,7 +266,7 @@ class AccountTest < Test::Unit::TestCase

context "#retrieve_capability" do
should "retrieve a capability" do
capability = StripeClient.new.accounts.retrieve_capability(
capability = StripeClient.new.account.retrieve_capability(
"acct_123",
"acap_123"
)
Expand All @@ -277,7 +277,7 @@ class AccountTest < Test::Unit::TestCase

context "#update_capability" do
should "update a capability" do
capability = StripeClient.new.accounts.update_capability(
capability = StripeClient.new.account.update_capability(
"acct_123",
"acap_123",
requested: true
Expand All @@ -289,7 +289,7 @@ class AccountTest < Test::Unit::TestCase

context "#list_capabilities" do
should "list the account's external accounts" do
capabilities = StripeClient.new.accounts.list_capabilities(
capabilities = StripeClient.new.account.list_capabilities(
"acct_123"
)
assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_123/capabilities"
Expand All @@ -300,7 +300,7 @@ class AccountTest < Test::Unit::TestCase

context "#create_external_account" do
should "create an external account" do
external_account = StripeClient.new.accounts.create_external_account(
external_account = StripeClient.new.account.create_external_account(
"acct_123",
external_account: "btok_123"
)
Expand All @@ -311,7 +311,7 @@ class AccountTest < Test::Unit::TestCase

context "#retrieve_external_account" do
should "retrieve an external account" do
external_account = StripeClient.new.accounts.retrieve_external_account(
external_account = StripeClient.new.account.retrieve_external_account(
"acct_123",
"ba_123"
)
Expand All @@ -322,7 +322,7 @@ class AccountTest < Test::Unit::TestCase

context "#update_external_account" do
should "update an external account" do
external_account = StripeClient.new.accounts.update_external_account(
external_account = StripeClient.new.account.update_external_account(
"acct_123",
"ba_123",
metadata: { foo: "bar" }
Expand All @@ -334,7 +334,7 @@ class AccountTest < Test::Unit::TestCase

context "#delete_external_account" do
should "delete an external_account" do
external_account = StripeClient.new.accounts.delete_external_account(
external_account = StripeClient.new.account.delete_external_account(
"acct_123",
"ba_123"
)
Expand All @@ -346,7 +346,7 @@ class AccountTest < Test::Unit::TestCase

context "#list_external_accounts" do
should "list the account's external accounts" do
external_accounts = StripeClient.new.accounts.list_external_accounts(
external_accounts = StripeClient.new.account.list_external_accounts(
"acct_123"
)
assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_123/external_accounts"
Expand All @@ -357,7 +357,7 @@ class AccountTest < Test::Unit::TestCase

context "#create_login_link" do
should "create a login link" do
login_link = StripeClient.new.accounts.create_login_link(
login_link = StripeClient.new.account.create_login_link(
"acct_123"
)
assert_requested :post, "#{Stripe.api_base}/v1/accounts/acct_123/login_links"
Expand All @@ -367,7 +367,7 @@ class AccountTest < Test::Unit::TestCase

context "#create_person" do
should "create a person" do
person = StripeClient.new.accounts.create_person(
person = StripeClient.new.account.create_person(
"acct_123",
first_name: "John",
last_name: "Doe"
Expand All @@ -379,7 +379,7 @@ class AccountTest < Test::Unit::TestCase

context "#retrieve_person" do
should "retrieve a person" do
person = StripeClient.new.accounts.retrieve_person(
person = StripeClient.new.account.retrieve_person(
"acct_123",
"person_123"
)
Expand All @@ -390,7 +390,7 @@ class AccountTest < Test::Unit::TestCase

context "#update_person" do
should "update a person" do
person = StripeClient.new.accounts.update_person(
person = StripeClient.new.account.update_person(
"acct_123",
"person_123",
first_name: "John"
Expand All @@ -402,7 +402,7 @@ class AccountTest < Test::Unit::TestCase

context "#delete_person" do
should "delete an person" do
person = StripeClient.new.accounts.delete_person(
person = StripeClient.new.account.delete_person(
"acct_123",
"person_123"
)
Expand All @@ -414,7 +414,7 @@ class AccountTest < Test::Unit::TestCase

context "#list_persons" do
should "list the account's external accounts" do
persons = StripeClient.new.accounts.list_persons(
persons = StripeClient.new.account.list_persons(
"acct_123"
)
assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_123/persons"
Expand Down
8 changes: 4 additions & 4 deletions test/stripe/alipay_account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Stripe
class AlipayAccountTest < Test::Unit::TestCase
context "#resource_url" do
should "return a resource URL" do
alipay_account = StripeClient.new.alipay_accounts.construct_from(
alipay_account = StripeClient.new.alipay_account.construct_from(
id: "aliacc_123",
customer: "cus_123"
)
Expand All @@ -15,7 +15,7 @@ class AlipayAccountTest < Test::Unit::TestCase
end

should "raise without a customer" do
alipay_account = StripeClient.new.alipay_accounts.construct_from(id: "aliacc_123")
alipay_account = StripeClient.new.alipay_account.construct_from(id: "aliacc_123")
assert_raises NotImplementedError do
alipay_account.resource_url
end
Expand All @@ -24,13 +24,13 @@ class AlipayAccountTest < Test::Unit::TestCase

should "raise on #retrieve" do
assert_raises NotImplementedError do
StripeClient.new.alipay_accounts.retrieve("aliacc_123")
StripeClient.new.alipay_account.retrieve("aliacc_123")
end
end

should "raise on #update" do
assert_raises NotImplementedError do
StripeClient.new.alipay_accounts.update("aliacc_123", {})
StripeClient.new.alipay_account.update("aliacc_123", {})
end
end
end
Expand Down

0 comments on commit ce4a205

Please sign in to comment.