Class: Stripe::APIResourceTestHelpers
- Inherits:
-
Object
- Object
- Stripe::APIResourceTestHelpers
- Includes:
- Stripe::APIOperations::Request
- Defined in:
- lib/stripe/api_resource_test_helpers.rb
Overview
The base class for nested TestHelpers classes in resource objects. The APIResourceTestHelpers handles URL generation and custom method support for test-helper methods.
class MyAPIResource < APIResource
class TestHelpers < APIResourceTestHelpers
Direct Known Subclasses
ConfirmationToken::TestHelpers, Customer::TestHelpers, Issuing::Authorization::TestHelpers, Issuing::Card::TestHelpers, Issuing::PersonalizationDesign::TestHelpers, Issuing::Transaction::TestHelpers, Refund::TestHelpers, Terminal::Reader::TestHelpers, Treasury::InboundTransfer::TestHelpers, Treasury::OutboundPayment::TestHelpers, Treasury::OutboundTransfer::TestHelpers, Treasury::ReceivedCredit::TestHelpers, Treasury::ReceivedDebit::TestHelpers
Class Method Summary collapse
-
.custom_method(name, http_verb:, http_path: nil) ⇒ Object
Adds a custom method to a test helper.
- .resource_class ⇒ Object
- .resource_url ⇒ Object
Instance Method Summary collapse
-
#initialize(resource) ⇒ APIResourceTestHelpers
constructor
A new instance of APIResourceTestHelpers.
- #resource_url ⇒ Object
Methods included from Stripe::APIOperations::Request
Constructor Details
#initialize(resource) ⇒ APIResourceTestHelpers
Returns a new instance of APIResourceTestHelpers.
13 14 15 |
# File 'lib/stripe/api_resource_test_helpers.rb', line 13 def initialize(resource) @resource = resource end |
Class Method Details
.custom_method(name, http_verb:, http_path: nil) ⇒ Object
Adds a custom method to a test helper. This is used to add support for non-CRUDL API requests, e.g. capturing charges. custom_method takes the following parameters:
-
name: the name of the custom method to create (as a symbol)
-
http_verb: the HTTP verb for the API request (:get, :post, or :delete)
-
http_path: the path to append to the resource’s URL. If not provided,
the name is used as the path
For example, this call:
custom_method :capture, http_verb: post
adds a ‘capture` class method to the resource class that, when called, will send a POST request to `/v1/<object_name>/capture`.
33 34 35 |
# File 'lib/stripe/api_resource_test_helpers.rb', line 33 def self.custom_method(name, http_verb:, http_path: nil) Util.custom_method resource_class, self, name, http_verb, http_path end |
.resource_class ⇒ Object
17 18 19 |
# File 'lib/stripe/api_resource_test_helpers.rb', line 17 def self.resource_class nil end |
.resource_url ⇒ Object
37 38 39 40 |
# File 'lib/stripe/api_resource_test_helpers.rb', line 37 def self.resource_url "/v1/test_helpers/" \ "#{resource_class.object_name.downcase.tr('.', '/')}s" end |
Instance Method Details
#resource_url ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/stripe/api_resource_test_helpers.rb', line 42 def resource_url unless (id = @resource["id"]) raise InvalidRequestError.new( "Could not determine which URL to request: #{self.class} instance " \ "has invalid ID: #{id.inspect}", "id" ) end "#{self.class.resource_url}/#{CGI.escape(id)}" end |