Class: Caplinked::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, request_method, path, options = {}) ⇒ Request

Returns a new instance of Request.



10
11
12
13
14
15
16
# File 'lib/caplinked/request.rb', line 10

def initialize(client, request_method, path, options = {})
  @client = client
  @request_method = request_method
  @uri = Addressable::URI.parse("#{client.api_scheme}://#{client.api_host}#{path}")
  @path = @uri.path
  @options = options
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/caplinked/request.rb', line 8

def client
  @client
end

#headersObject

Returns the value of attribute headers.



8
9
10
# File 'lib/caplinked/request.rb', line 8

def headers
  @headers
end

#paramsObject

Returns the value of attribute params.



8
9
10
# File 'lib/caplinked/request.rb', line 8

def params
  @params
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/caplinked/request.rb', line 8

def path
  @path
end

#request_methodObject

Returns the value of attribute request_method.



8
9
10
# File 'lib/caplinked/request.rb', line 8

def request_method
  @request_method
end

#uriObject

Returns the value of attribute uri.



8
9
10
# File 'lib/caplinked/request.rb', line 8

def uri
  @uri
end

Instance Method Details

#performObject



18
19
20
21
22
23
24
# File 'lib/caplinked/request.rb', line 18

def perform
  @uri.query_values = @options.delete(:params)
  response = HTTP.headers(req_headers).request(@request_method, @uri.to_s, @options)
  response_body = response.body.empty? ? '' : change_keys_to_symbols(response.parse)
  response_headers = response.headers
  fail_or_return_response_body(response.code, response_body, response_headers)
end