class ApimaticCalculator::SimpleCalculatorController

SimpleCalculatorController

Public Class Methods

new(config, http_call_back: nil) click to toggle source
Calls superclass method ApimaticCalculator::BaseController::new
# 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

Public Instance Methods

get_calculate(options = {}) click to toggle source

Calculates the expression using the specified operation. @param [OperationTypeEnum] operation Required parameter: The operator to apply on the variables @param [Float] x Required parameter: The LHS value @param [Float] y Required parameter: The RHS value @return [Float] response from the API call

# File lib/apimatic_calculator/controllers/simple_calculator_controller.rb, line 19
def get_calculate(options = {})
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/{operation}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'operation' => { 'value' => options['operation'], 'encode' => true }
  )
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'x' => options['x'],
    'y' => options['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