Class: Gonebusy::SearchController
- Inherits:
-
BaseController
- Object
- BaseController
- Gonebusy::SearchController
- Defined in:
- lib/gonebusy/controllers/search_controller.rb
Constant Summary collapse
- @@instance =
SearchController.new
Instance Attribute Summary
Attributes inherited from BaseController
Class Method Summary collapse
-
.instance ⇒ Object
Singleton instance of the controller class.
Instance Method Summary collapse
-
#search_query(options = Hash.new) ⇒ Object
Search for Providers and Provided Services.
Methods inherited from BaseController
#execute_request, #initialize, #validate_parameters, #validate_response
Constructor Details
This class inherits a constructor from Gonebusy::BaseController
Class Method Details
.instance ⇒ Object
Singleton instance of the controller class
7 8 9 |
# File 'lib/gonebusy/controllers/search_controller.rb', line 7 def self.instance @@instance end |
Instance Method Details
#search_query(options = Hash.new) ⇒ Object
Search for Providers and Provided Services.
15 16 17 18 19 20 21 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 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gonebusy/controllers/search_controller.rb', line 15 def search_query( = Hash.new) # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/search/{query}' # process optional query parameters _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'query' => ['query'] } # validate and preprocess url _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'accept' => 'application/json', 'Authorization' => Configuration., 'Authorization' => ['authorization'] } # create the HttpRequest object for the call _request = @http_client.get _query_url, headers: _headers # apply authentication CustomAuth.apply(_request) # execute the request _context = execute_request(_request) # endpoint error handling using HTTP status codes. if _context.response.status_code == 400 raise EntitiesErrorException.new '400 - Bad Request', _context elsif _context.response.status_code == 401 raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context elsif _context.response.status_code == 500 raise APIException.new '500 - Unexpected error', _context end # global error handling using HTTP status codes. validate_response(_context) # return appropriate response type decoded = APIHelper.json_deserialize(_context.response.raw_body) return SearchQueryResponse.from_hash(decoded) end |