Class: WeatherApiTask::FindWeatherController
- Inherits:
-
BaseController
- Object
- BaseController
- WeatherApiTask::FindWeatherController
- Defined in:
- lib/weather_api_task/controllers/find_weather_controller.rb
Overview
FindWeatherController
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Attributes inherited from BaseController
Instance Method Summary collapse
-
#find(q) ⇒ Object
The endpoint to get data of a specific city.
- #instance ⇒ Object
Methods inherited from BaseController
#execute_request, #initialize, #validate_parameters, #validate_response
Constructor Details
This class inherits a constructor from WeatherApiTask::BaseController
Class Attribute Details
.instance ⇒ Object
Returns the value of attribute instance.
12 13 14 |
# File 'lib/weather_api_task/controllers/find_weather_controller.rb', line 12 def instance @instance end |
Instance Method Details
#find(q) ⇒ Object
The endpoint to get data of a specific city.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/weather_api_task/controllers/find_weather_controller.rb', line 22 def find(q) # Prepare query url. _path_url = '/find' _query_builder = Configuration.base_uri.dup _query_builder << _path_url _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, { 'q' => q }, array_serialization: Configuration.array_serialization ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = @http_client.get( _query_url, headers: _headers ) CustomQueryAuth.apply(_request) _context = execute_request(_request) validate_response(_context) # Return appropriate response type. decoded = APIHelper.json_deserialize(_context.response.raw_body) CityWeather.from_hash(decoded) end |
#instance ⇒ Object
15 16 17 |
# File 'lib/weather_api_task/controllers/find_weather_controller.rb', line 15 def instance self.class.instance end |