Class: RTM::RTM

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

Overview

Root access to RTM api. Most methods work just like the api demonstrates, however auth is a bit different:

rtm = RTM.new(Endpoint.new(api_key,secret))
auth_url = rtm.auth.url
# Send user to url
# When they click authorize and return to your app do:
rtm.token=rtm.auth.get_token

This is a one time thing, so cache the token somewhere and you are good to go:

response = rtm.tasks.getList(:filter => 'location:Work and status:completed')
response = rtm.groups.add(:group => 'My New Group')

If you don’t supply timelines, they will be created for you each time as needed. Also note that you can use Ruby-style method calls instead of filthy camel-case, e.g.

response = rtm.tasks.get_list(:filter => 'location:Work and status:completed')
# Same as
response = rtm.tasks.getList(:filter => 'location:Work and status:completed')

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ RTM

Create access to RTM

endpoint

an Endpoint to RTM



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

def initialize(endpoint)
  @endpoint = endpoint
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object

Gateway to all other method-spaces. Assumes you are making a valid call on RTM. Essentially, any method will give you an RTMMethodSpace object keyed to the method name, e.g. rtm.foobar will assume that RTM has a “foobar” methodspace. method names are converted to camelcase.



78
79
80
81
82
83
84
85
# File 'lib/moocow/moocow.rb', line 78

def method_missing(symbol,*args)
  if !args || args.empty?
    rtm_object = symbol.to_s.rtmize
    return RTMMethodSpace.new(rtm_object,@endpoint)
  else
    return super(symbol,*args)
  end
end

Instance Method Details

#authObject

Get the auth method-space



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

def auth
  RTMAuth.new(@endpoint)
end

#auto_timeline=(a) ⇒ Object



45
46
47
# File 'lib/moocow/moocow.rb', line 45

def auto_timeline=(a)
  @endpoint.auto_timeline=a
end

#check_tokenObject Also known as: checkToken

Raises an InvalidTokenException if the token is not valid



60
61
62
63
64
65
66
# File 'lib/moocow/moocow.rb', line 60

def check_token
  begin
    response = @endpoint.call_method('rtm.auth.checkToken')
  rescue VerificationException
    raise InvalidTokenException
  end
end

#last_timelineObject

Gets the last timeline that was used if in auto-timeline mode



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

def last_timeline
  @endpoint.last_timeline
end

#testObject

Get the test method-space (Kernel defines a test method, making method_missing problematic)



70
71
72
# File 'lib/moocow/moocow.rb', line 70

def test
  return RTMMethodSpace.new('test',@endpoint)
end

#token=(token) ⇒ Object

Set the token



41
42
43
# File 'lib/moocow/moocow.rb', line 41

def token=(token)
  @endpoint.token=token
end