class Myra::Request

Constants

ALLOWED_TYPES

Attributes

api_key[R]
api_secret[R]
date[R]
path[R]
payload[RW]
type[RW]

Public Class Methods

new(path:, type: :get) click to toggle source
# File lib/myra/request.rb, line 21
def initialize(path:, type: :get)
  @date = DateTime.now.to_s
  @api_key = Myra.configuration.api_key
  @api_secret = Myra.configuration.api_secret
  @type = type
  @path = path
end

Public Instance Methods

content_type() click to toggle source
# File lib/myra/request.rb, line 48
def content_type
  'application/json'
end
do() click to toggle source
# File lib/myra/request.rb, line 44
def do
  HTTP.new(self).response
end
signing_string() click to toggle source
# File lib/myra/request.rb, line 29
def signing_string
  [
    md5.(payload),
    verb,
    "#{Myra::PATH}#{path}",
    content_type,
    date
  ].join '#'
end
type=(type) click to toggle source
# File lib/myra/request.rb, line 39
def type=(type)
  raise InvalidRequestTypeError unless ALLOWED_TYPES.include?(type)
  @type = type
end
uri() click to toggle source
# File lib/myra/request.rb, line 52
def uri
  "#{Myra::BASE_URL}#{Myra::PATH}#{path}"
end
with_payload?() click to toggle source
# File lib/myra/request.rb, line 61
def with_payload?
  [:post, :put, :delete].include?(type)
end

Private Instance Methods

md5() click to toggle source
# File lib/myra/request.rb, line 67
def md5
  Digest::MD5.method(:hexdigest)
end
verb() click to toggle source
# File lib/myra/request.rb, line 71
def verb
  type.to_s.upcase
end