class Youtube::APIController
Public Class Methods
new(config, http_call_back: nil)
click to toggle source
Calls superclass method
# File lib/youtube/controllers/api_controller.rb, line 9 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end
Public Instance Methods
get_forcast(param: 'String.Empty')
click to toggle source
get list of 5 random forcasts @param [String] param Optional parameter: default string parameter @return [Mixed] response from the API call
# File lib/youtube/controllers/api_controller.rb, line 16 def get_forcast(param: 'String.Empty') # Prepare query url. _query_builder = config.get_base_uri(Server::DEFAULT) _query_builder << '/WeatherForecast' _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'param' => param ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) _response = execute_request(_request) # Validate response against endpoint and global error codes. if _response.status_code == 400 raise ProblemDetailsException.new( 'Test error message', _response ) elsif _response.status_code == 404 raise APIException.new( 'not found', _response ) end validate_response(_response) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) unless _response.raw_body.nil? || _response.raw_body.to_s.strip.empty? decoded end