Class: Gonebusy::CategoriesController
- Inherits:
-
BaseController
- Object
- BaseController
- Gonebusy::CategoriesController
- Defined in:
- lib/gonebusy/controllers/categories_controller.rb
Constant Summary collapse
- @@instance =
CategoriesController.new
Instance Attribute Summary
Attributes inherited from BaseController
Class Method Summary collapse
-
.instance ⇒ Object
Singleton instance of the controller class.
Instance Method Summary collapse
-
#create_category(options = Hash.new) ⇒ Object
Create a Category.
-
#get_categories(options = Hash.new) ⇒ Object
Return list of Categories.
-
#get_category_by_id(options = Hash.new) ⇒ Object
Return a Category by id.
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/categories_controller.rb', line 7 def self.instance @@instance end |
Instance Method Details
#create_category(options = Hash.new) ⇒ Object
Create a Category
72 73 74 75 76 77 78 79 80 81 82 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/gonebusy/controllers/categories_controller.rb', line 72 def create_category( = Hash.new) # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/categories/new' # validate and preprocess url _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8', 'Authorization' => Configuration., 'Authorization' => ['authorization'] } # create the HttpRequest object for the call _request = @http_client.post _query_url, headers: _headers, parameters: ['create_category_body'].to_json # 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 == 403 raise EntitiesErrorException.new '403 - Forbidden', _context elsif _context.response.status_code == 422 raise EntitiesErrorException.new '422 - Unprocessable Entity', _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 CreateCategoryResponse.from_hash(decoded) end |
#get_categories(options = Hash.new) ⇒ Object
Return list of Categories.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/gonebusy/controllers/categories_controller.rb', line 127 def get_categories( = Hash.new) # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/categories' # process optional query parameters _query_builder = APIHelper.append_url_with_query_parameters _query_builder, { 'page' => ['page'], 'per_page' => ['per_page'], 'user_id' => ['user_id'] } # 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 == 403 raise EntitiesErrorException.new '403 - Forbidden', _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 GetCategoriesResponse.from_hash(decoded) end |
#get_category_by_id(options = Hash.new) ⇒ Object
Return a Category by id.
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 63 64 65 66 |
# File 'lib/gonebusy/controllers/categories_controller.rb', line 15 def get_category_by_id( = Hash.new) # the base uri for api requests _query_builder = Configuration.base_uri.dup # prepare query string for API call _query_builder << '/categories/{id}' # process optional query parameters _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'id' => ['id'] } # 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 == 403 raise EntitiesErrorException.new '403 - Forbidden', _context elsif _context.response.status_code == 404 raise EntitiesErrorException.new '404 - Not Found', _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 GetCategoryByIdResponse.from_hash(decoded) end |