Method: Pebbles::API#initialize

Defined in:
lib/pebbles/api.rb

#initialize(options = {}) ⇒ API

Returns a new instance of API.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pebbles/api.rb', line 35

def initialize(options={})
  options = OPTIONS.merge(options)
  options[:headers] = HEADERS.merge(options[:headers])

  @api_key = options.delete(:api_key) || ENV['PEBBLES_API_KEY']
  if !@api_key && options.has_key?(:username) && options.has_key?(:password)
    username = options.delete(:username)
    password = options.delete(:password)
    @connection = Excon.new("#{options[:scheme]}://#{options[:host]}", options)
    @api_key = self.(username, password).body["api_key"]
  end

  @connection = Excon.new("#{options[:scheme]}://#{options[:host]}", options)
end