Class: Cryptopay::Request

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

Constant Summary collapse

DEFAULT_HEADERS =
{
  'Accept' => 'application/json',
  'User-Agent' => "Cryptopay Ruby v#{VERSION}"
}.freeze
CONTENT_TYPE =
'application/json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method:, path:, query_params: {}, body_params: {}) ⇒ Request

Returns a new instance of Request.



14
15
16
17
18
19
20
21
# File 'lib/cryptopay/request.rb', line 14

def initialize(method:, path:, query_params: {}, body_params: {})
  @method = method
  @path = prepare_query(path, query_params)
  @body = prepare_body(body_params.to_hash)
  @date = Time.now.httpdate
  @content_type = CONTENT_TYPE
  @headers = DEFAULT_HEADERS.merge(Date: date, 'Content-Type': @content_type)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



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

def content_type
  @content_type
end

#dateObject (readonly)

Returns the value of attribute date.



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

def date
  @date
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#add_header(key, value) ⇒ Object



23
24
25
# File 'lib/cryptopay/request.rb', line 23

def add_header(key, value)
  @headers = headers.merge(key => value)
end