Class: Seam::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/seam/request.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, base_uri:, debug: false) ⇒ Request

Returns a new instance of Request.



19
20
21
22
23
# File 'lib/seam/request.rb', line 19

def initialize(api_key:, base_uri:, debug: false)
  @api_key = api_key
  @base_uri = base_uri
  @debug = debug
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/seam/request.rb', line 7

def api_key
  @api_key
end

#base_uriObject (readonly)

Returns the value of attribute base_uri.



7
8
9
# File 'lib/seam/request.rb', line 7

def base_uri
  @base_uri
end

#debugObject (readonly)

Returns the value of attribute debug.



7
8
9
# File 'lib/seam/request.rb', line 7

def debug
  @debug
end

Instance Method Details

#perform(method, uri, config = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/seam/request.rb', line 25

def perform(method, uri, config = {})
  Logger.info("Request: #{method} #{uri} #{config}") if debug

  config[:body] = config[:body].to_json if config[:body]

  response = HTTP.request(
    method,
    build_url(uri),
    {headers: headers}.merge(config)
  )

  return response.parse if response.status.success?

  handle_error_response(response, method, uri)
end