Class: Kazoo::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/kazoo/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kazoo_config) ⇒ Auth

Returns a new instance of Auth.



5
6
7
8
9
10
11
12
# File 'lib/kazoo/auth.rb', line 5

def initialize(kazoo_config)
  @api_key = kazoo_config['api_key']
  @host = kazoo_config['host']
  @port = kazoo_config['port']
  @version = kazoo_config['version']
  @account_id = kazoo_config['account_id']
  get_token
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



3
4
5
# File 'lib/kazoo/auth.rb', line 3

def 
  @account_id
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



3
4
5
# File 'lib/kazoo/auth.rb', line 3

def api_key
  @api_key
end

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/kazoo/auth.rb', line 3

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/kazoo/auth.rb', line 3

def port
  @port
end

#tokenObject (readonly)

Returns the value of attribute token.



3
4
5
# File 'lib/kazoo/auth.rb', line 3

def token
  @token
end

#versionObject (readonly)

Returns the value of attribute version.



3
4
5
# File 'lib/kazoo/auth.rb', line 3

def version
  @version
end

Instance Method Details

#get_tokenObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kazoo/auth.rb', line 14

def get_token
  unless token
    base_uri = 'http://' + host + ":" + port + '/' + version + '/'
    auth_url = base_uri + 'api_auth'
    payload = {'data' => {'api_key' => api_key}}
    response = Nestful.json_put(auth_url, {:params => payload})
    @token = response['auth_token']
  end

  @token
end