Class: Routemaster::Fetcher

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Defined in:
lib/routemaster/fetcher.rb

Overview

Fetches URLs from JSON APIs.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

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.

Returns:

  • an object that responds to status (integer), headers (hash),



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