Class: Teilashare::APIResource

Inherits:
Object
  • Object
show all
Defined in:
lib/teilashare/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.



10
11
12
13
14
# File 'lib/teilashare/api_resource.rb', line 10

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.



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

def client
  @client
end

#optsObject (readonly)

Returns the value of attribute opts.



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

def opts
  @opts
end

Instance Method Details

#action_verbObject

Raises:

  • (NotImplementedError)


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

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

#callObject



16
17
18
19
20
21
22
# File 'lib/teilashare/api_resource.rb', line 16

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