Class: Gonebusy::PricingModelsController
- Inherits:
-
BaseController
- Object
- BaseController
- Gonebusy::PricingModelsController
- Defined in:
- lib/gonebusy/controllers/pricing_models_controller.rb
Constant Summary collapse
- @@instance =
PricingModelsController.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_pricing_model(authorization, create_pricing_model_body = nil) ⇒ Object
Create a PricingModel with params.
-
#get_pricing_model_by_id(authorization, id) ⇒ Object
Return a PricingModel by id.
-
#get_pricing_models(authorization, user_id = nil, page = 1, per_page = 10) ⇒ Object
Return list of PricingModels.
-
#update_pricing_model_by_id(authorization, id, update_pricing_model_by_id_body = nil) ⇒ Object
Update a PricingModel by id, with params.
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/pricing_models_controller.rb', line 7 def self.instance @@instance end |
Instance Method Details
#create_pricing_model(authorization, create_pricing_model_body = nil) ⇒ Object
Create a PricingModel with params
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/gonebusy/controllers/pricing_models_controller.rb', line 162 def create_pricing_model(, create_pricing_model_body = nil) # prepare query url _query_builder = Configuration.get_base_uri() _query_builder << '/pricing_models/new' _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8', 'Authorization' => Configuration., 'Authorization' => } # prepare and execute HttpRequest _request = @http_client.post _query_url, headers: _headers, parameters: create_pricing_model_body.to_json 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 == 403 raise EntitiesErrorErrorException.new 'Forbidden', _context elsif _context.response.status_code == 422 raise EntitiesErrorErrorException.new 'Unprocessable Entity', _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 CreatePricingModelResponse.from_hash(decoded) end |
#get_pricing_model_by_id(authorization, id) ⇒ Object
Return a PricingModel by id.
116 117 118 119 120 121 122 123 124 125 126 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 |
# File 'lib/gonebusy/controllers/pricing_models_controller.rb', line 116 def get_pricing_model_by_id(, id) # prepare query url _query_builder = Configuration.get_base_uri() _query_builder << '/pricing_models/{id}' _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'id' => id } _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 == 403 raise EntitiesErrorErrorException.new 'Forbidden', _context elsif _context.response.status_code == 404 raise EntitiesErrorErrorException.new 'Not Found', _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 GetPricingModelByIdResponse.from_hash(decoded) end |
#get_pricing_models(authorization, user_id = nil, page = 1, per_page = 10) ⇒ Object
Return list of PricingModels.
68 69 70 71 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 |
# File 'lib/gonebusy/controllers/pricing_models_controller.rb', line 68 def get_pricing_models(, user_id = nil, page = 1, per_page = 10) # prepare query url _query_builder = Configuration.get_base_uri() _query_builder << '/pricing_models' _query_builder = APIHelper.append_url_with_query_parameters _query_builder, { 'user_id' => user_id, 'page' => page, 'per_page' => per_page }, array_serialization: Configuration.array_serialization _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 == 401 raise EntitiesErrorErrorException.new 'Unauthorized/Missing Token', _context elsif _context.response.status_code == 403 raise EntitiesErrorErrorException.new 'Forbidden', _context elsif _context.response.status_code == 404 raise EntitiesErrorErrorException.new 'Not Found', _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 GetPricingModelsResponse.from_hash(decoded) end |
#update_pricing_model_by_id(authorization, id, update_pricing_model_by_id_body = nil) ⇒ Object
Update a PricingModel by id, with params
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 |
# File 'lib/gonebusy/controllers/pricing_models_controller.rb', line 16 def update_pricing_model_by_id(, id, update_pricing_model_by_id_body = nil) # prepare query url _query_builder = Configuration.get_base_uri() _query_builder << '/pricing_models/{id}' _query_builder = APIHelper.append_url_with_template_parameters _query_builder, { 'id' => id } _query_url = APIHelper.clean_url _query_builder # prepare headers _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8', 'Authorization' => Configuration., 'Authorization' => } # prepare and execute HttpRequest _request = @http_client.put _query_url, headers: _headers, parameters: update_pricing_model_by_id_body.to_json 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 == 403 raise EntitiesErrorErrorException.new 'Forbidden', _context elsif _context.response.status_code == 404 raise EntitiesErrorErrorException.new 'Not Found', _context elsif _context.response.status_code == 422 raise EntitiesErrorErrorException.new 'Unprocessable Entity', _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 UpdatePricingModelByIdResponse.from_hash(decoded) end |