Class: ADPDownloader::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/adp-downloader/http_client.rb

Instance Method Summary collapse

Constructor Details

#initializeHttpClient

Returns a new instance of HttpClient.



6
7
8
9
10
11
# File 'lib/adp-downloader/http_client.rb', line 6

def initialize
  headers = {"Accept" => "application/json, text/plain, */*"}
  @agent = Mechanize.new {|a| a.request_headers = headers}
  res = (Config.credentials)
  _raise_on_error(res)
end

Instance Method Details

#download(url) ⇒ Object



22
23
24
# File 'lib/adp-downloader/http_client.rb', line 22

def download(url)
  @agent.get(url).body
end

#get(url) ⇒ Object



13
14
15
16
# File 'lib/adp-downloader/http_client.rb', line 13

def get(url)
  contents = download(url)
  contents.to_s.empty? ? {} : JSON.parse(contents)
end

#post(url, data) ⇒ Object



18
19
20
# File 'lib/adp-downloader/http_client.rb', line 18

def post(url, data)
  @agent.post(url, data)
end