-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the Capability resource and APIs
- Loading branch information
1 parent
793a61c
commit ff34036
Showing
9 changed files
with
119 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stripe | ||
class Capability < APIResource | ||
extend Stripe::APIOperations::List | ||
include Stripe::APIOperations::Save | ||
|
||
OBJECT_NAME = "capability".freeze | ||
|
||
def resource_url | ||
if !respond_to?(:account) || account.nil? | ||
raise NotImplementedError, | ||
"Capabilities cannot be accessed without an account ID." | ||
end | ||
"#{Account.resource_url}/#{CGI.escape(account)}/capabilities/#{CGI.escape(id)}" | ||
end | ||
|
||
def self.retrieve(_id, _opts = {}) | ||
raise NotImplementedError, "Capabilities cannot be retrieved without an account ID. Retrieve a capability using account.retrieve_capability('acct_123', 'acap_123')" | ||
end | ||
|
||
def self.update(_id, _params = nil, _opts = nil) | ||
raise NotImplementedError, "Capabilities cannot be updated without an account ID. Update a capability using `p = account.update_capability('acct_123', 'acap_123', params)" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require ::File.expand_path("../../test_helper", __FILE__) | ||
|
||
module Stripe | ||
class CapabilityTest < Test::Unit::TestCase | ||
context "#resource_url" do | ||
should "return a resource URL" do | ||
capability = Stripe::Capability.construct_from( | ||
id: "acap_123", | ||
account: "acct_123" | ||
) | ||
assert_equal "/v1/accounts/acct_123/capabilities/acap_123", | ||
capability.resource_url | ||
end | ||
|
||
should "raise without an account" do | ||
capability = Stripe::Capability.construct_from(id: "acap_123") | ||
assert_raises NotImplementedError do | ||
capability.resource_url | ||
end | ||
end | ||
end | ||
|
||
should "raise on #retrieve" do | ||
assert_raises NotImplementedError do | ||
Stripe::Capability.retrieve("acap_123") | ||
end | ||
end | ||
|
||
should "raise on #update" do | ||
assert_raises NotImplementedError do | ||
Stripe::Capability.update("acap_123", {}) | ||
end | ||
end | ||
|
||
should "be saveable" do | ||
capability = Stripe::Account.retrieve_capability("acct_123", "acap_123") | ||
capability.requested = true | ||
capability.save | ||
assert_requested :post, | ||
"#{Stripe.api_base}/v1/accounts/#{capability.account}/capabilities/#{capability.id}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters