Class: WeatherApiAssignment::WeatherAPIsController
- Inherits:
-
BaseController
- Object
- BaseController
- WeatherApiAssignment::WeatherAPIsController
- Defined in:
- lib/weather_api_assignment/controllers/weather_ap_is_controller.rb
Overview
WeatherAPIsController
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Attributes inherited from BaseController
Instance Method Summary collapse
-
#get_weather_by_city_name(q, mode = nil, units = nil, lang = nil) ⇒ Object
This is a weather API endpoint which returns the current weather of a location by city name.
-
#get_weather_by_latitude_and_longitude(lat, lon, mode = nil, units = nil, lang = nil) ⇒ Object
This is a weather API endpoint which returns the current weather of a location by latitude and longitude.
- #instance ⇒ Object
Methods inherited from BaseController
#execute_request, #initialize, #validate_parameters, #validate_response
Constructor Details
This class inherits a constructor from WeatherApiAssignment::BaseController
Class Attribute Details
.instance ⇒ Object
Returns the value of attribute instance.
12 13 14 |
# File 'lib/weather_api_assignment/controllers/weather_ap_is_controller.rb', line 12 def instance @instance end |
Instance Method Details
#get_weather_by_city_name(q, mode = nil, units = nil, lang = nil) ⇒ Object
This is a weather API endpoint which returns the current weather of a location by city name. code divided by comma, use ISO 3166 country codes. values are xml and html. If you don’t use the mode parameter format is JSON by default. standard, metric and imperial units are available. If you do not use the units parameter, standard units will be applied by default. get the output in your language.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/weather_api_assignment/controllers/weather_ap_is_controller.rb', line 32 def get_weather_by_city_name(q, mode = nil, units = nil, lang = nil) # Prepare query url. _path_url = '/weather' _query_builder = Configuration.base_uri.dup _query_builder << _path_url _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, { 'q' => q, 'mode' => mode, 'units' => units, 'lang' => lang }, 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) WeatherAPIResponse.from_hash(decoded) end |
#get_weather_by_latitude_and_longitude(lat, lon, mode = nil, units = nil, lang = nil) ⇒ Object
This is a weather API endpoint which returns the current weather of a location by latitude and longitude. latitude of city longitude of city values are xml and html. If you don’t use the mode parameter format is JSON by default. standard, metric and imperial units are available. If you do not use the units parameter, standard units will be applied by default. the output in your language.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/weather_api_assignment/controllers/weather_ap_is_controller.rb', line 83 def get_weather_by_latitude_and_longitude(lat, lon, mode = nil, units = nil, lang = nil) # Prepare query url. _path_url = '/weather' _query_builder = Configuration.base_uri.dup _query_builder << _path_url _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, { 'lat' => lat, 'lon' => lon, 'mode' => mode, 'units' => units, 'lang' => lang }, 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) WeatherAPIResponse.from_hash(decoded) end |
#instance ⇒ Object
15 16 17 |
# File 'lib/weather_api_assignment/controllers/weather_ap_is_controller.rb', line 15 def instance self.class.instance end |