Class: Routemaster::Fetcher
- Inherits:
-
Object
- Object
- Routemaster::Fetcher
- Extended by:
- ClassMethods
- Defined in:
- lib/routemaster/fetcher.rb
Overview
Fetches URLs from JSON APIs.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#get(url, params: nil, headers: nil) ⇒ Object
Performs a GET HTTP request for the
url, with optional query parameters (params) and additional headers (headers). -
#initialize(host) ⇒ Fetcher
constructor
A new instance of Fetcher.
Constructor Details
#initialize(host) ⇒ Fetcher
Returns a new instance of Fetcher.
26 27 28 |
# File 'lib/routemaster/fetcher.rb', line 26 def initialize(host) @host = host end |
Instance Method Details
#get(url, params: nil, headers: nil) ⇒ Object
Performs a GET HTTP request for the url, with optional
query parameters (params) and additional headers (headers).
and body. The body is a Hashie::Mash if the response was JSON, a
string otherwise.
36 37 38 39 |
# File 'lib/routemaster/fetcher.rb', line 36 def get(url, params:nil, headers:nil) r = _connection.get(url, params, headers) Hashie::Mash.new(status: r.status, headers: r.headers, body: r.body) end |