Class: RTM::RTMAuth

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

Overview

Implements authorization related tasks. These are to be used one-time only when the user first uses your application.

auth = RTMAuth.new(api_key,secret)
url = auth.get_auth_url
# send user to url
# When they have done so
token = auth.get_token
# object auth no longer needed; use token with RTM

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ RTMAuth

Returns a new instance of RTMAuth.



14
15
16
# File 'lib/moocow/auth.rb', line 14

def initialize(endpoint)
  @endpoint = endpoint
end

Instance Method Details

#check_tokenObject Also known as: checkToken



37
38
39
# File 'lib/moocow/auth.rb', line 37

def check_token
  raise "checkToken should be called on the RTM object directly";
end

#frobObject

After a call to get_frob, this returns the frob that was gotten.



50
51
52
# File 'lib/moocow/auth.rb', line 50

def frob
  @frob
end

#frob=(frob) ⇒ Object



54
55
56
# File 'lib/moocow/auth.rb', line 54

def frob=(frob)
  @frob=frob
end

#get_frobObject Also known as: getFrob



42
43
44
45
46
# File 'lib/moocow/auth.rb', line 42

def get_frob
  response = @endpoint.call_method('rtm.auth.getFrob',nil,false)
  @frob = response['frob']
  @frob
end

#get_tokenObject Also known as: getToken

After the user has authorized, gets the token



31
32
33
34
# File 'lib/moocow/auth.rb', line 31

def get_token
  response = @endpoint.call_method('rtm.auth.getToken', { 'frob' => @frob }, false)
  response['auth']['token']
end

#url(perms = :delete, application_type = :desktop, callback_url = nil) ⇒ Object

Get the URL to allow the user to authorize the application

perms

the permissions you wish to get, either :read, :write, or :delete

application_type

if :desktop, a frob is gotten and the URL is suitable for a desktop application. if :web, a url suitable for the web is returned.

callback_url

the callback URL you want the user sent to after they authorize. This will have the frob and you must call frob= before get_token with the frob that was given to you.



22
23
24
25
26
27
28
# File 'lib/moocow/auth.rb', line 22

def url(perms = :delete, application_type=:desktop, callback_url=nil)
  @frob = get_frob if application_type == :desktop
  params = {'perms' => perms.to_s}
  params['frob'] = @frob if @frob
  params['callbackURL'] = callback_url if callback_url
  @endpoint.url_for(nil,params,'auth')
end