Class: Teilashare::Resources::APIResource

Inherits:
Object
  • Object
show all
Defined in:
lib/teilashare/resources/api_resource.rb

Constant Summary collapse

PATH =
'/x.cfm'
HOST =
'api.shareasale.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/teilashare/resources/api_resource.rb', line 9

def client
  @client
end

#optsObject (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_verbObject

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/teilashare/resources/api_resource.rb', line 25

def action_verb
  raise NotImplementedError, 'please define in a subclass'
end

#callObject



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