Class: ApimaticCalculator::SimpleCalculatorController
- Inherits:
-
BaseController
- Object
- BaseController
- ApimaticCalculator::SimpleCalculatorController
- Defined in:
- lib/apimatic_calculator/controllers/simple_calculator_controller.rb
Overview
SimpleCalculatorController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#get_calculate(options = {}) ⇒ Float
Calculates the expression using the specified operation.
-
#initialize(config, http_call_back: nil) ⇒ SimpleCalculatorController
constructor
A new instance of SimpleCalculatorController.
Methods inherited from BaseController
#execute_request, #validate_parameters, #validate_response
Constructor Details
#initialize(config, http_call_back: nil) ⇒ SimpleCalculatorController
Returns a new instance of SimpleCalculatorController.
9 10 11 |
# File 'lib/apimatic_calculator/controllers/simple_calculator_controller.rb', line 9 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#get_calculate(options = {}) ⇒ Float
Calculates the expression using the specified operation. apply on the variables
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 |
# File 'lib/apimatic_calculator/controllers/simple_calculator_controller.rb', line 19 def get_calculate( = {}) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/{operation}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'operation' => { 'value' => ['operation'], 'encode' => true } ) _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'x' => ['x'], 'y' => ['y'] ) _query_url = APIHelper.clean_url _query_builder # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url ) _response = execute_request(_request) validate_response(_response) # Return appropriate response type. _response.raw_body.to_f end |