Class: Myra::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/myra/request.rb,
lib/myra/request/http.rb,
lib/myra/request/signature.rb

Defined Under Namespace

Classes: HTTP, Signature

Constant Summary collapse

ALLOWED_TYPES =
[
  :get,
  :post,
  :put,
  :options,
  :head,
  :delete
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, type: :get) ⇒ Request

Returns a new instance of Request.



21
22
23
24
25
26
27
# 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

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



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

def api_secret
  @api_secret
end

#dateObject (readonly)

Returns the value of attribute date.



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

def date
  @date
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#payloadObject

Returns the value of attribute payload.



10
11
12
# File 'lib/myra/request.rb', line 10

def payload
  @payload
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/myra/request.rb', line 10

def type
  @type
end

Instance Method Details

#content_typeObject



48
49
50
# File 'lib/myra/request.rb', line 48

def content_type
  'application/json'
end

#doObject



44
45
46
# File 'lib/myra/request.rb', line 44

def do
  HTTP.new(self).response
end

#signing_stringObject



29
30
31
32
33
34
35
36
37
# File 'lib/myra/request.rb', line 29

def signing_string
  [
    md5.(payload),
    verb,
    "#{Myra::PATH}#{path}",
    content_type,
    date
  ].join '#'
end

#uriObject



52
53
54
# File 'lib/myra/request.rb', line 52

def uri
  "#{Myra::BASE_URL}#{Myra::PATH}#{path}"
end

#with_payload?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/myra/request.rb', line 61

def with_payload?
  [:post, :put, :delete].include?(type)
end