Class: ApimaticTestingCalculator::SimpleCalculatorController

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

Overview

SimpleCalculatorController

Class Attribute Summary collapse

Attributes inherited from BaseController

#http_call_back, #http_client

Instance Method Summary collapse

Methods inherited from BaseController

#execute_request, #initialize, #validate_parameters, #validate_response

Constructor Details

This class inherits a constructor from ApimaticTestingCalculator::BaseController

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



12
13
14
# File 'lib/apimatic_testing_calculator/controllers/simple_calculator_controller.rb', line 12

def instance
  @instance
end

Instance Method Details

#get_calculate(operation, x, y) ⇒ Object

Calculates the result for the specified operation and variables. be applied on the provided 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



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
# File 'lib/apimatic_testing_calculator/controllers/simple_calculator_controller.rb', line 25

def get_calculate(operation,
                  x,
                  y)
  # Prepare query url.
  _path_url = '/{operation}'
  _path_url = APIHelper.append_url_with_template_parameters(
    _path_url,
    'operation' => operation
  )
  _query_builder = Configuration.base_uri.dup
  _query_builder << _path_url
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    {
      'x' => x,
      'y' => y
    },
    array_serialization: Configuration.array_serialization
  )
  _query_url = APIHelper.clean_url _query_builder
  # Prepare and execute HttpRequest.
  _request = @http_client.get(
    _query_url
  )
  _context = execute_request(_request)
  validate_response(_context)
  # Return appropriate response type.
  _context.response.raw_body.to_f
end

#instanceObject



15
16
17
# File 'lib/apimatic_testing_calculator/controllers/simple_calculator_controller.rb', line 15

def instance
  self.class.instance
end