Class: FrederickAPI::V2::Helpers::Requestor

Inherits:
JsonApiClient::Query::Requestor
  • Object
show all
Defined in:
lib/frederick_api/v2/helpers/requestor.rb

Overview

Requestor for v2 client to use built on top of JsonApiClient::Query::Requestor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, path = nil) ⇒ Requestor



10
11
12
13
# File 'lib/frederick_api/v2/helpers/requestor.rb', line 10

def initialize(klass, path = nil)
  @klass = klass
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/frederick_api/v2/helpers/requestor.rb', line 8

def path
  @path
end

Instance Method Details

#request(type, path, params) ⇒ Object

Retry once on unhandled server errors



25
26
27
28
29
30
# File 'lib/frederick_api/v2/helpers/requestor.rb', line 25

def request(type, path, params)
  super
rescue JsonApiClient::Errors::ConnectionError, JsonApiClient::Errors::ServerError => ex
  raise ex if ex.is_a?(JsonApiClient::Errors::NotFound) || ex.is_a?(JsonApiClient::Errors::Conflict)
  super
end

#resource_path(parameters) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/frederick_api/v2/helpers/requestor.rb', line 15

def resource_path(parameters)
  base_path = path || klass.path(parameters)
  if (resource_id = parameters[klass.primary_key])
    File.join(base_path, encode_part(resource_id))
  else
    base_path
  end
end