Class: ApimaticCalculator::SimpleCalculatorController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/apimatic_calculator/controllers/simple_calculator_controller.rb

Overview

SimpleCalculatorController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent

Constructor Details

This class inherits a constructor from ApimaticCalculator::BaseController

Instance Method Details

#get_calculate(options = {}) ⇒ Float

Calculates the expression using the specified operation. apply on the variables

Parameters:

  • operation (OperationTypeEnum)

    Required parameter: The operator to

  • x (Float)

    Required parameter: The LHS value

  • y (Float)

    Required parameter: The RHS value

Returns:

  • (Float)

    response from the API call



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/apimatic_calculator/controllers/simple_calculator_controller.rb', line 15

def get_calculate(options = {})
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/{operation}',
                                 Server::CALCULATOR)
               .template_param(new_parameter(options['operation'], key: 'operation')
                                .should_encode(true))
               .query_param(new_parameter(options['x'], key: 'x'))
               .query_param(new_parameter(options['y'], key: 'y')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:deserialize_primitive_types))
               .deserialize_into(proc do |response| response.to_f end)
               .is_primitive_response(true))
    .execute
end