Class: Revolut::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/revolut/configuration.rb

Overview

A class responsible for all configurations.

Constant Summary collapse

PRODUCTION_API_ENDPOINT =
'https://b2b.revolut.com/api/1.0'
SANDBOX_API_ENDPOINT =
'https://sandbox-b2b.revolut.com/api/1.0'
AVAILABLE_ENVIRONMENTS =
%i[production sandbox].freeze
DEFAULT_ENVIRONMENT =
:production
USER_AGENT =
"Revolut Ruby v#{Revolut::VERSION}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



12
13
14
# File 'lib/revolut/configuration.rb', line 12

def api_key
  @api_key
end

#urlString

Takes url provided from configuration or uses default one.

Returns:

  • (String)

    An API Endpoint url which will be used for connection.



18
19
20
21
22
23
24
25
26
27
# File 'lib/revolut/configuration.rb', line 18

def url
  return @url if @url

  case environment
  when :production
    PRODUCTION_API_ENDPOINT
  when :sandbox
    SANDBOX_API_ENDPOINT
  end
end

#user_agentString

Takes user agent from configuration or uses default one.

Returns:

  • (String)

    User agent which will be used for connection headers.



32
33
34
# File 'lib/revolut/configuration.rb', line 32

def user_agent
  @user_agent || USER_AGENT
end

Instance Method Details

#environmentSymbol

Takes environment from configuration or uses default one. It will be used to set url automatically.

Returns:

  • (Symbol)

    Environment which will be used to set url.



40
41
42
# File 'lib/revolut/configuration.rb', line 40

def environment
  @environment || DEFAULT_ENVIRONMENT
end

#environment=(environment) ⇒ Symbol

Sets environment which will be used for url.

Returns:

  • (Symbol)

    Environment which will be used to set url.

Raises:



47
48
49
50
51
52
53
# File 'lib/revolut/configuration.rb', line 47

def environment=(environment)
  env_sym = environment.is_a?(String) ? environment.to_sym : environment

  raise Revolut::Error, 'Invalid environment provided.' unless AVAILABLE_ENVIRONMENTS.include?(env_sym)

  @environment = env_sym
end