Class: Requester

Inherits:
Object
  • Object
show all
Defined in:
lib/esp-commons/requester.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, headers_accept = nil) ⇒ Requester

Returns a new instance of Requester.



4
5
6
7
8
# File 'lib/esp-commons/requester.rb', line 4

def initialize(url, headers_accept = nil)
  @response = Curl::Easy.perform(url) do |curl|
    curl.headers['Accept'] = headers_accept
  end
end

Instance Method Details

#responseObject



10
11
12
# File 'lib/esp-commons/requester.rb', line 10

def response
  @response
end

#response_bodyObject



22
23
24
# File 'lib/esp-commons/requester.rb', line 22

def response_body
  @response_body ||= response.body_str
end

#response_hashObject



26
27
28
# File 'lib/esp-commons/requester.rb', line 26

def response_hash
  @response_hash ||= ActiveSupport::JSON.decode(response_body)
end

#response_headersObject



14
15
16
# File 'lib/esp-commons/requester.rb', line 14

def response_headers
  @response_headers ||= Hash[response.header_str.split("\r\n").map { |s| s.split(': ').map(&:strip) }]
end

#response_statusObject



18
19
20
# File 'lib/esp-commons/requester.rb', line 18

def response_status
  @response_status ||= response.response_code
end