Class: ADPDownloader::HttpClient
- Inherits:
-
Object
- Object
- ADPDownloader::HttpClient
- Defined in:
- lib/adp-downloader/http_client.rb
Instance Method Summary collapse
- #download(url) ⇒ Object
- #get(url) ⇒ Object
-
#initialize ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(url, data) ⇒ Object
Constructor Details
#initialize ⇒ HttpClient
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 = _login(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 |