Class: Upcoming::Auth

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

Constant Summary collapse

API_KEY =
'6c43a45521'
FROB =
'36a7cf3804aed4226f5d228e81b498913160e67c'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAuth

Returns a new instance of Auth.



11
12
13
14
15
16
# File 'lib/upcoming/auth.rb', line 11

def initialize
  @token = nil
  @user_id = nil
  @user_name = nil
  @name = nil
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/upcoming/auth.rb', line 9

def name
  @name
end

#tokenObject (readonly)

Returns the value of attribute token.



9
10
11
# File 'lib/upcoming/auth.rb', line 9

def token
  @token
end

#user_idObject (readonly)

Returns the value of attribute user_id.



9
10
11
# File 'lib/upcoming/auth.rb', line 9

def user_id
  @user_id
end

#user_nameObject (readonly)

Returns the value of attribute user_name.



9
10
11
# File 'lib/upcoming/auth.rb', line 9

def user_name
  @user_name
end

Instance Method Details

#get_tokenObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/upcoming/auth.rb', line 18

def get_token
  req = Upcoming::Request.new
  resp = req.send({:method => 'auth.getToken', :frob => Upcoming::Auth::FROB})
  
  doc = Document.new(resp.body)
  el = XPath.first(doc, '//token')
  
  @token = el.attribute('token').value
  @user_id = el.attribute('user_id').value
  @user_name = el.attribute('user_username').value
  @name = el.attribute('user_name').value
  
  return true
end

#valid_token?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/upcoming/auth.rb', line 33

def valid_token?
  req = Upcoming::Request.new
  resp = req.send({:method => 'auth.checkToken', :token => @token})
  
  doc = Document.new(resp.body)
  el = XPath.first(doc, '//token')
  
  if el.nil?
    return false
  end
  
  return true
end