Class: Proxima::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, method, path, opts = {}) ⇒ Request

Returns a new instance of Request.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/proxima/request.rb', line 11

def initialize(api, method, path, opts = {})
  @api    = api
  @method = method.to_s.upcase

  headers = opts[:headers] || {}

  @body = if opts[:json]
    headers[:content_type] = 'application/json'
    opts[:json].to_json
  elsif opts[:body]
    opts[:body]
  end

  headers = @api.headers.merge headers

  @headers  = headers.map{ |name, val| [to_header(name), val.to_s] }.to_h
  query_str = opts[:query] ? "?#{opts[:query].to_query}" : ''
  @uri      = URI.join(@api.base_uri, path, query_str)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



9
10
11
# File 'lib/proxima/request.rb', line 9

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



6
7
8
# File 'lib/proxima/request.rb', line 6

def method
  @method
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/proxima/request.rb', line 5

def response
  @response
end

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end