Class: Raas::ExchangeRatesController

Inherits:
BaseController show all
Defined in:
lib/raas/controllers/exchange_rates_controller.rb

Overview

ExchangeRatesController

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 Raas::BaseController

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



10
11
12
# File 'lib/raas/controllers/exchange_rates_controller.rb', line 10

def instance
  @instance
end

Instance Method Details

#get_exchange_ratesObject

Retrieve current exchange rates

Returns:

  • ExchangeRateResponseModel response from the API call



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
61
62
# File 'lib/raas/controllers/exchange_rates_controller.rb', line 19

def get_exchange_rates
  begin
    @logger.info("get_exchange_rates called.")
    # Prepare query url.
    @logger.info("Preparing query URL for get_exchange_rates.")
    _query_builder = Configuration.get_base_uri
    _query_builder << '/exchangerates'
    _query_url = APIHelper.clean_url _query_builder
  
    # Prepare headers.
    @logger.info("Preparing headers for get_exchange_rates.")
    _headers = {
      'accept' => 'application/json'
    }
  
    # Prepare and execute HttpRequest.
    @logger.info('Preparing and executing HttpRequest for get_exchange_rates.')
    _request = @http_client.get(
      _query_url,
      headers: _headers
    )
    BasicAuth.apply(_request)
    _context = execute_request(_request, name: 'get_exchange_rates')
  
    # Validate response against endpoint and global error codes.
    @logger.info("Validating response for get_exchange_rates.")
    unless _context.response.status_code.between?(200, 208)
      raise RaasGenericException.new(
        'API Error',
        _context
      )
    end
    validate_response(_context)
  
    # Return appropriate response type.
    @logger.info("Returning response for get_exchange_rates.")
    decoded = APIHelper.json_deserialize(_context.response.raw_body)
    ExchangeRateResponseModel.from_hash(decoded)

  rescue Exception => e
    @logger.error(e)
    raise e
  end
end

#instanceObject



13
14
15
# File 'lib/raas/controllers/exchange_rates_controller.rb', line 13

def instance
  self.class.instance
end