Class: Frame::APIResource Abstract
- Inherits:
-
FrameObject
- Object
- FrameObject
- Frame::APIResource
- Includes:
- Frame::APIOperations::Request
- Defined in:
- lib/frame/api_resource.rb
Overview
Subclass and implement object_name to create a new resource type.
Base class for all Frame Payments API resources.
All API resources inherit from APIResource, which provides common functionality like retrieving resources by ID and building resource URLs.
Direct Known Subclasses
Account, BankAccount, Billing, Capability, Charge, ChargeIntent, ChargeSession, Coupon, Customer, CustomerIdentityVerification, Discount, Dispute, Geofence, Invoice, InvoiceLineItem, Onboarding, OnboardingSession, PaymentLinkSession, PaymentMethod, Payout, PhoneVerification, Product, ProductPhase, PromotionCode, Refund, SonarSession, Subscription, SubscriptionChangeLog, SubscriptionPhase, TermsOfService, ThreeDsIntent, Transfer, TransferBillingAgreement, TransferFeePlan, WebhookEndpoint
Instance Attribute Summary
Attributes inherited from FrameObject
Class Method Summary collapse
- .class_name ⇒ Object
-
.resource_url ⇒ String
Builds the base URL for this resource type.
-
.retrieve(id, opts = {}) ⇒ APIResource
Retrieves a resource by its ID.
Instance Method Summary collapse
-
#refresh(opts = {}) ⇒ APIResource
Refreshes the resource data from the API.
-
#resource_url ⇒ String
Builds the URL for this specific resource instance.
Methods included from Frame::APIOperations::Request
Methods inherited from FrameObject
#[], #[]=, construct_from, #each, #initialize, #initialize_from, #inspect, #keys, #serialize_params, #to_hash, #to_s, #update_attributes, #values
Constructor Details
This class inherits a constructor from Frame::FrameObject
Class Method Details
.class_name ⇒ Object
13 14 15 |
# File 'lib/frame/api_resource.rb', line 13 def self.class_name name.split("::")[-1] end |
.resource_url ⇒ String
Builds the base URL for this resource type
19 20 21 22 23 24 25 26 27 |
# File 'lib/frame/api_resource.rb', line 19 def self.resource_url if self == APIResource raise NotImplementedError, "APIResource is an abstract class. You should perform actions " \ "on its subclasses (Customer, etc.)" end "/v1/#{object_name.downcase}s" end |
.retrieve(id, opts = {}) ⇒ APIResource
Retrieves a resource by its ID
35 36 37 38 39 40 |
# File 'lib/frame/api_resource.rb', line 35 def self.retrieve(id, opts = {}) id = Util.normalize_id(id) instance = new(id, opts) instance.refresh(opts) instance end |
Instance Method Details
#refresh(opts = {}) ⇒ APIResource
Refreshes the resource data from the API
61 62 63 64 65 |
# File 'lib/frame/api_resource.rb', line 61 def refresh(opts = {}) response = request(:get, resource_url, {}, opts) initialize_from(response, opts) self end |
#resource_url ⇒ String
Builds the URL for this specific resource instance
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/frame/api_resource.rb', line 45 def resource_url unless (id = self["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 |