Class: Teilashare::Resources::APIResource
- Inherits:
-
Object
- Object
- Teilashare::Resources::APIResource
- Defined in:
- lib/teilashare/resources/api_resource.rb
Direct Known Subclasses
ActivityDetail, ActivitySummary, ApiTokenCount, BalanceInquiry, InvalidLinks, LedgerReport, MerchantCreative, MerchantDatafeed, MerchantGiftCard, MerchantSearch, MerchantSearchByProduct, MerchantStatus, MerchantTimespan, MonthlySummary, OrderInquiry, PaymentSummary
Constant Summary collapse
- PATH =
'/x.cfm'
- HOST =
'api.shareasale.com'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #action_verb ⇒ Object
- #call ⇒ Object
-
#initialize(client, opts = {}) ⇒ APIResource
constructor
A new instance of APIResource.
Constructor Details
#initialize(client, opts = {}) ⇒ APIResource
Returns a new instance of APIResource.
11 12 13 14 15 |
# File 'lib/teilashare/resources/api_resource.rb', line 11 def initialize(client, opts = {}) @client = client @opts = default_opts.merge(opts).with_indifferent_access validate_required_opts end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/teilashare/resources/api_resource.rb', line 9 def client @client end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
9 10 11 |
# File 'lib/teilashare/resources/api_resource.rb', line 9 def opts @opts end |
Instance Method Details
#action_verb ⇒ Object
25 26 27 |
# File 'lib/teilashare/resources/api_resource.rb', line 25 def action_verb raise NotImplementedError, 'please define in a subclass' end |
#call ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/teilashare/resources/api_resource.rb', line 17 def call response = Request.new(client, self).call # the API returns 200 OK on invalid authentication GET requests, so need to parse error from body instead raise Errors::InvalidRequestError, response.body if response.body.match?(/\AInvalid Request/) parser.parse(response.body) end |