Class: Routemaster::APIClient
- Inherits:
-
Object
- Object
- Routemaster::APIClient
- Defined in:
- lib/routemaster/api_client.rb
Instance Method Summary collapse
- #discover(url) ⇒ Object
-
#get(url, params: {}, headers: {}) ⇒ Object
Performs a GET HTTP request for the
url
, with optional query parameters (params
) and additional headers (headers
). -
#initialize(middlewares: [], listener: nil, response_class: nil) ⇒ APIClient
constructor
A new instance of APIClient.
- #post(url, body: {}, headers: {}) ⇒ Object
Constructor Details
#initialize(middlewares: [], listener: nil, response_class: nil) ⇒ APIClient
Returns a new instance of APIClient.
11 12 13 14 15 |
# File 'lib/routemaster/api_client.rb', line 11 def initialize(middlewares: [], listener: nil, response_class: nil) @listener = listener @middlewares = middlewares @response_class = response_class end |
Instance Method Details
#discover(url) ⇒ Object
41 42 43 |
# File 'lib/routemaster/api_client.rb', line 41 def discover(url) get(url) end |
#get(url, params: {}, headers: {}) ⇒ 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.
23 24 25 26 27 28 |
# File 'lib/routemaster/api_client.rb', line 23 def get(url, params: {}, headers: {}) host = URI.parse(url).host response_wrapper do connection.get(url, params, headers.merge(auth_header(host))) end end |
#post(url, body: {}, headers: {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/routemaster/api_client.rb', line 30 def post(url, body: {}, headers: {}) host = URI.parse(url).host response_wrapper do connection.post do |req| req.url url req.headers = headers.merge(auth_header(host)) req.body = body.to_json end end end |