Class: StocksExchangeApiClient::Configuration

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

Constant Summary collapse

URL_V3 =
'https://api3.stex.com'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url: URL_V3, option: {}, use_version: 3, s2s: false) ⇒ Configuration

Returns a new instance of Configuration.



8
9
10
11
12
13
# File 'lib/stocks_exchange_api_client/configuration.rb', line 8

def initialize(url: URL_V3, option: {}, use_version: 3, s2s: false)
  @url||= url
  @option||= option
  @use_version||= use_version
  @s2s||= s2s
end

Instance Attribute Details

#optionObject

Returns the value of attribute option.



6
7
8
# File 'lib/stocks_exchange_api_client/configuration.rb', line 6

def option
  @option
end

#s2sObject

Returns the value of attribute s2s.



6
7
8
# File 'lib/stocks_exchange_api_client/configuration.rb', line 6

def s2s
  @s2s
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/stocks_exchange_api_client/configuration.rb', line 6

def url
  @url
end

#use_versionObject

Returns the value of attribute use_version.



6
7
8
# File 'lib/stocks_exchange_api_client/configuration.rb', line 6

def use_version
  @use_version
end

Instance Method Details

#validate!Object



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

def validate!
  if use_version == 2
    raise 'Disabled supporting version 2 API'
  end
  if use_version == 3 && !s2s
    unless option[:client_id] && option[:client_secret] && option[:token_object][:access_token] && option[:token_object][:refresh_token]
      raise Errors::ConfigurationError
    end
  end
  if use_version == 3 && s2s
      unless option[:token_object][:access_token]
        raise Errors::ConfigurationError
      end
  end
end