class Proxima::Request

Attributes

body[R]
headers[R]
method[R]
response[R]
uri[R]

Public Class Methods

new(api, method, path, opts = {}) click to toggle source
# 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

Private Instance Methods

to_header(symbol_or_string) click to toggle source
# File lib/proxima/request.rb, line 42
def to_header symbol_or_string
  symbol_or_string.to_s.split(/[_ -]/).map!{ |w| w.downcase.capitalize }.join '-'
end