Class: Alula::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/alula/client.rb

Constant Summary collapse

DEFAULT_CUSTOM_OPTIONS =
{
  omitRelationships: true
}

Class Method Summary collapse

Class Method Details

.configObject



12
13
14
# File 'lib/alula/client.rb', line 12

def config
  @_config ||= Alula::ClientConfiguration.new
end

.configure {|config| ... } ⇒ Object

Yields:



16
17
18
# File 'lib/alula/client.rb', line 16

def configure
  yield config if block_given?
end

.request(http_method, resource_path, filters = {}, opts = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/alula/client.rb', line 20

def request(http_method, resource_path, filters = {}, opts = {})
  unless resource_path.match(%r{^/public/v1})
    validate_request!(http_method, resource_path)
  end

  request_opts = build_options(http_method, resource_path, filters, opts)
  # TODO: Handle network failures
  response = make_request(http_method, config.api_url + resource_path, request_opts)

  begin
    resp = AlulaResponse.from_httparty_response(response)
  rescue JSON::ParserError
    # TODO: Should be able to send better info up with this
    raise 'Unable to decode JSON'
  end

  resp
end