Method: TestingBot::Api#initialize

Defined in:
lib/testingbot/api.rb

#initialize(key = nil, secret = nil, options = {}) ⇒ Api

Returns a new instance of Api.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/testingbot/api.rb', line 13

def initialize(key = nil, secret = nil, options = {})
  @key = key
  @secret = secret
  @options = {
    :debug => false
  }.merge(options)
  if @key.nil? || @secret.nil?
    cached_credentials = load_config_file
    @key, @secret = cached_credentials unless cached_credentials.nil?
  end

  if @key.nil? || @secret.nil?
    @key = ENV["TESTINGBOT_KEY"] if ENV["TESTINGBOT_KEY"]
    @secret = ENV["TESTINGBOT_SECRET"] if ENV["TESTINGBOT_SECRET"]
  end

  if @key.nil? || @secret.nil?
    @key = ENV["TB_KEY"] if ENV["TB_KEY"]
    @secret = ENV["TB_SECRET"] if ENV["TB_SECRET"]
  end

  raise "Please supply a TestingBot Key" if @key.nil?
  raise "Please supply a TestingBot Secret" if @secret.nil?
end