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

.auth_hostObject



29
30
31
# File 'lib/rtmilk/api.rb', line 29

def API.auth_host
  'http://www.' + RTM_DOMAIN
end

.get_auth_url(perms, frob = nil) ⇒ Object

get Auth URL (both desktop/webapp)



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rtmilk/api.rb', line 67

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  = [auth_host, AUTH_PATH].join + '?'
   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.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rtmilk/api.rb', line 34

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



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

def API.key; @@key; end

.tokenObject



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

def API.token; @@token; end

.token=(token) ⇒ Object



48
49
50
# File 'lib/rtmilk/api.rb', line 48

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

Instance Method Details

#api_hostObject



25
26
27
# File 'lib/rtmilk/api.rb', line 25

def api_host
  'https://api.' + RTM_DOMAIN
end

#invokeObject

invoke a method



57
58
59
60
61
62
63
64
# File 'lib/rtmilk/api.rb', line 57

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

#signObject



81
82
83
# File 'lib/rtmilk/api.rb', line 81

def sign
   API.sign(@param)
end