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(authorization, query) ⇒ 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(authorization, query) ⇒ 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 |
# File 'lib/gonebusy/controllers/search_controller.rb', line 15 def search_query(, query) # prepare query url _query_builder = Configuration.get_base_uri() _query_builder << '/search/{query}' _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'query' => query } _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'accept' => 'application/json', 'Authorization' => Configuration., 'Authorization' => } # prepare and execute HttpRequest _request = @http_client.get _query_url, headers: _headers CustomAuth.apply(_request) _context = execute_request(_request) # validate response against endpoint and global error codes if _context.response.status_code == 400 raise EntitiesErrorErrorException.new 'Bad Request', _context elsif _context.response.status_code == 401 raise EntitiesErrorErrorException.new 'Unauthorized/Missing Token', _context elsif !_context.response.status_code.between?(200, 208) raise APIException.new 'Unexpected error', _context end validate_response(_context) # return appropriate response type decoded = APIHelper.json_deserialize(_context.response.raw_body) return SearchQueryResponse.from_hash(decoded) end |