class Myfinance::Request

Attributes

args[R]

Public Class Methods

new(args) click to toggle source
# File lib/myfinance/request.rb, line 3
def initialize(args)
  @args = args
end

Public Instance Methods

run() click to toggle source
# File lib/myfinance/request.rb, line 7
def run
  request.run
  request.response
end

Private Instance Methods

authorization_hash() click to toggle source
# File lib/myfinance/request.rb, line 49
def authorization_hash
  ::Base64.strict_encode64("#{args[:token]}:X")
end
body() click to toggle source
# File lib/myfinance/request.rb, line 43
def body
  body = args[:body]
  body = MultiJson.dump(body) if body.is_a?(Hash) && !args[:multipart]
  body
end
content_type() click to toggle source
# File lib/myfinance/request.rb, line 53
def content_type
  args[:multipart] ? nil : "application/json"
end
headers() click to toggle source
# File lib/myfinance/request.rb, line 31
def headers
  headers = args.fetch(:headers) { {} }

  {
    "Accept"         => "application/json",
    "Content-Type"   => content_type,
    "User-Agent"     => args[:user_agent],
    "Authorization"  => "Basic #{authorization_hash}",
    "ACCOUNT_ID"     => args[:account_id]
  }.merge(headers).delete_if { |_, v| v.nil? || v.to_s.empty? }
end
options() click to toggle source
# File lib/myfinance/request.rb, line 20
def options
  {
    method:           args[:method],
    params:           args[:params],
    body:             body,
    headers:          headers,
    accept_encoding:  "gzip",
    params_encoding: :rack
  }.reject { |_k, v| v.nil? }
end
request() click to toggle source
# File lib/myfinance/request.rb, line 16
def request
  @request ||= Typhoeus::Request.new(args[:url], options)
end