Class: Trolley::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/trolley/Configuration.rb

Defined Under Namespace

Classes: InvalidProxyAddress

Constant Summary collapse

DEFAULT_API_BASE =
'https://api.trolley.com'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(publicKey, privateKey, **optionals) ⇒ Configuration

Returns a new instance of Configuration.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/trolley/Configuration.rb', line 8

def initialize(publicKey, privateKey, **optionals)
  raise ArgumentError, 'Both key/secret must be a nonempty string' if publicKey.to_s&.empty? || privateKey.to_s&.empty?

  @publicKey = publicKey
  @privateKey = privateKey
  @api_base = optionals[:api_base] || DEFAULT_API_BASE
  # failfast on a bad proxy
  proxy_uri = optionals[:proxy_uri]
  begin
    @proxy = proxy_uri.nil? ? nil : URI.parse(proxy_uri)
  rescue URI::InvalidURIError
    raise InvalidProxyAddress, "Invalid proxy provided to configuration: #{proxy_uri}"
  end
end

Instance Attribute Details

#api_baseObject (readonly)

Returns the value of attribute api_base.



4
5
6
# File 'lib/trolley/Configuration.rb', line 4

def api_base
  @api_base
end

#environmentObject (readonly)

Returns the value of attribute environment.



4
5
6
# File 'lib/trolley/Configuration.rb', line 4

def environment
  @environment
end

#privateKeyObject

Returns the value of attribute privateKey.



27
28
29
# File 'lib/trolley/Configuration.rb', line 27

def privateKey
  @privateKey
end

#proxyObject (readonly)

Returns the value of attribute proxy.



4
5
6
# File 'lib/trolley/Configuration.rb', line 4

def proxy
  @proxy
end

#publicKeyObject

Returns the value of attribute publicKey.



27
28
29
# File 'lib/trolley/Configuration.rb', line 27

def publicKey
  @publicKey
end

Instance Method Details

#useSsl?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/trolley/Configuration.rb', line 23

def useSsl?
  api_base.start_with? 'https'
end