Class: Barchart::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method:, path:, body: nil) ⇒ Request

Returns a new instance of Request.



5
6
7
8
9
10
# File 'lib/barchart/request.rb', line 5

def initialize(method:, path:, body: nil)
  Barchart.configuration.validate!
  @method = method
  @path = path
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/barchart/request.rb', line 3

def body
  @body
end

#methodObject (readonly)

Returns the value of attribute method.



3
4
5
# File 'lib/barchart/request.rb', line 3

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/barchart/request.rb', line 3

def path
  @path
end

Instance Method Details

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/barchart/request.rb', line 19

def execute
  p url
  response = RestClient::Request.new({
    url: url,
    method: method,
    headers: {
      'Content-Type': 'application/json',
      'Date': Time.now.utc.httpdate,
    },
    payload: body_to_json,
  }).execute

  convert_hash_keys(JSON.parse(response))
end