Class: RTM::API
- Inherits:
-
Object
- Object
- RTM::API
- Defined in:
- lib/rtmilk/api.rb,
lib/rtmilk/api.rb
Overview
–
subclasses ++
Defined Under Namespace
Classes: Auth, Contacts, Error, Groups, Lists, Reflection, Settings, Tasks, Test, Time, TimeLines, TimeZones, Transactions
Constant Summary collapse
- RTM_URI =
'www.rememberthemilk.com'- REST_PATH =
'/services/rest/'- AUTH_PATH =
'/services/auth/'- PERMS =
['read', 'write', 'delete']
Class Method Summary collapse
-
.auth_uri(params, h) ⇒ Object
construct auth uri from params.
-
.init(h) ⇒ Object
initialize the API context.
-
.key ⇒ Object
– —————————————————————– class methods ++.
- .params ⇒ Object
-
.request(uri) ⇒ Object
process http request, return response.
- .token ⇒ Object
-
.uri_auth(params, h) ⇒ Object
tailor parameters into auth uri.
-
.uri_req(params) ⇒ Object
tailor parameters into request uri.
Class Method Details
.auth_uri(params, h) ⇒ Object
construct auth uri from params.
69 70 71 |
# File 'lib/rtmilk/api.rb', line 69 def API.auth_uri(params, h) RTM_URI + uri_auth(params, h) end |
.init(h) ⇒ Object
initialize the API context. make sure to call this before using any API calls.
36 37 38 39 40 41 42 43 44 |
# File 'lib/rtmilk/api.rb', line 36 def API.init(h) @@key = h[:key] if h.has_key? :key @@sec = h[:secret] if h.has_key? :secret @@frob = h[:frob] if h.has_key? :frob @@token = h[:token] if h.has_key? :token @@params = { 'api_key' => @@key } @@http = Net::HTTP.new(RTM_URI) end |
.params ⇒ Object
31 |
# File 'lib/rtmilk/api.rb', line 31 def API.params ; @@params ; end |
.request(uri) ⇒ Object
process http request, return response.
74 75 76 77 78 79 |
# File 'lib/rtmilk/api.rb', line 74 def API.request(uri) head, body = @@http.get(uri) res = XmlSimple.new.xml_in(body) raise Error, res if 'fail' == res['stat'] res end |
.token ⇒ Object
32 |
# File 'lib/rtmilk/api.rb', line 32 def API.token ; @@token ; end |
.uri_auth(params, h) ⇒ Object
tailor parameters into auth uri.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rtmilk/api.rb', line 55 def API.uri_auth(params, h) p = params.dup p[:perms] = h[:perm] p[:frob] = h[:frob] if h[:frob] p[:callback] = h[:callback] if h[:callback] r = AUTH_PATH + '?' r += p.collect { |k, v| [k, v].join('=') }.sort.join('&') r += '&api_sig=' + sign(p) r end |