Class: RTM::API

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

Overview

API class

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_auth_url(perms, frob = nil) ⇒ Object

get Auth URL (both desktop/webapp)



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rtmilk/api.rb', line 59

def API.get_auth_url(perms, frob=nil)
   param = { :api_key => @@key, :perms => perms }
   if frob
      param['frob'] = frob
   end

   sig = API.sign(param)

   r  = 'http://' + RTM_URI + AUTH_PATH + '?'
   r += param.collect { |k, v| [k, v].join('=') }.sort.join('&')
   r += '&api_sig=' + sig
   r
end

.init(key, sec, option = nil) ⇒ Object

initialize the API context.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rtmilk/api.rb', line 26

def API.init(key, sec, option=nil)
   @@key = key
   @@sec = sec

   if (option)
      begin
         @@token = option[:token] if option.has_key? :token
      rescue => e
         puts e.message
      end
   end

end

.keyObject

getter methods



45
# File 'lib/rtmilk/api.rb', line 45

def API.key; @@key; end

.tokenObject



46
# File 'lib/rtmilk/api.rb', line 46

def API.token; @@token; end

.token=(token) ⇒ Object



40
41
42
# File 'lib/rtmilk/api.rb', line 40

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

Instance Method Details

#invokeObject

invoke a method



49
50
51
52
53
54
55
56
# File 'lib/rtmilk/api.rb', line 49

def invoke
   response = URI.join(RTM_URI, make_url).read
   # puts '--------------------------------------------------'
   # puts response
   # puts '--------------------------------------------------'
   result = XmlSimple.new.xml_in(response)
   ret = parse_result(result)
end

#signObject



73
74
75
# File 'lib/rtmilk/api.rb', line 73

def sign
   API.sign(@param)
end