Module: Weese::Requests::Requester
- Included in:
- Bus::MetroBus, Bus::RequiresRoute, Bus::RequiresStop, Weese::Rail::MetroRail, Weese::Rail::RequiresLine, Weese::Rail::RequiresStation
- Defined in:
- lib/weese/requests.rb
Overview
Actually making the HTTP request
Instance Method Summary collapse
-
#fetch(wmata_request) ⇒ Hash
Makes a request to WMATA API & deserializes the response into a Hash.
-
#request(wmata_request) ⇒ String
Make a request to WMATA API.
Instance Method Details
#fetch(wmata_request) ⇒ Hash
Makes a request to WMATA API & deserializes the response into a Hash
63 64 65 |
# File 'lib/weese/requests.rb', line 63 def fetch(wmata_request) request(wmata_request).deserialize end |
#request(wmata_request) ⇒ String
Make a request to WMATA API
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/weese/requests.rb', line 43 def request(wmata_request) response = Faraday.get(wmata_request.path) do |request| request.params = wmata_request.query request.headers['api_key'] = wmata_request.api_key end return response.body if response.success? raise WeeseError, "#{response.status}, #{response.body}" end |