Module: MilkCap::RTM
- Defined in:
- lib/milk_cap/rtm/base.rb,
lib/milk_cap/rtm/resources.rb,
lib/milk_cap/rtm/credentials.rb,
lib/milk_cap/rtm/data_normalization.rb
Defined Under Namespace
Modules: DataNormalization Classes: List, MilkResource, TagArray, Task
Constant Summary collapse
- VERSION =
'0.5.2'
- AUTH_ENDPOINT =
"http://www.rememberthemilk.com/services/auth/"
- REST_ENDPOINT =
"http://api.rememberthemilk.com/services/rest/"
Class Method Summary collapse
-
.auth_get_frob ⇒ Object
:nodoc:.
-
.auth_get_frob_and_url ⇒ Object
:nodoc:.
-
.auth_get_token(frob) ⇒ Object
:nodoc:.
- .get(endpoint, hash) ⇒ Object
-
.get_timeline ⇒ Object
Requests a timeline from RTM.
-
.milk(params = {}) ⇒ Object
Calls an API method (milk the cow).
-
.sign(params, secret) ⇒ Object
Signs the RTM request (sets the ‘api_sig’ parameter).
Class Method Details
.auth_get_frob ⇒ Object
:nodoc:
26 27 28 29 30 |
# File 'lib/milk_cap/rtm/credentials.rb', line 26 def self.auth_get_frob #:nodoc: r = milk(:method => 'rtm.auth.getFrob') r['frob'] end |
.auth_get_frob_and_url ⇒ Object
:nodoc:
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/milk_cap/rtm/credentials.rb', line 32 def self.auth_get_frob_and_url #:nodoc: frob = auth_get_frob p = {} p['api_key'] = ENV['RTM_API_KEY'] p['perms'] = 'delete' p['frob'] = frob sign(p, ENV['RTM_SHARED_SECRET']) [ frob, AUTH_ENDPOINT + '?' + p.collect { |k, v| "#{k}=#{v}" }.join("&") ] end |
.auth_get_token(frob) ⇒ Object
:nodoc:
48 49 50 51 52 53 54 55 |
# File 'lib/milk_cap/rtm/credentials.rb', line 48 def self.auth_get_token (frob) #:nodoc: begin milk(:method => 'rtm.auth.getToken', :frob => frob)['auth']['token'] rescue Exception => e nil end end |
.get(endpoint, hash) ⇒ Object
101 102 103 104 105 |
# File 'lib/milk_cap/rtm/base.rb', line 101 def self.get(endpoint, hash) query = hash.collect { |item| "#{item[0].to_s}=#{CGI.escape(item[1].to_s)}" }.join("&") url = endpoint + '?' + query Net::HTTP.get(URI.parse(url)) end |
.get_timeline ⇒ Object
Requests a timeline from RTM.
96 97 98 99 |
# File 'lib/milk_cap/rtm/base.rb', line 96 def self.get_timeline #:nodoc: milk(:method => 'rtm.timelines.create')['timeline'] end |
.milk(params = {}) ⇒ Object
Calls an API method (milk the cow).
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/milk_cap/rtm/base.rb', line 64 def self.milk (params={}) #:nodoc: endpoint = params.delete(:endpoint) endpoint = AUTH_ENDPOINT if endpoint == :auth endpoint = endpoint || REST_ENDPOINT ps = params.inject({}) { |r, (k, v)| r[k.to_s] = v; r } ps['api_key'] = params[:api_key] || ENV['RTM_API_KEY'] raise 'API_KEY missing from environment or parameters, cannot proceed' \ unless ps['api_key'] ps['frob'] = params[:frob] || ENV['RTM_FROB'] ps.delete('frob') if ps['frob'] == nil ps['auth_token'] = params[:auth_token] || ENV['RTM_AUTH_TOKEN'] ps.delete('auth_token') if ps['auth_token'] == nil ps['format'] = 'json' secret = params[:shared_secret] || ENV['RTM_SHARED_SECRET'] sign(ps, secret) res = get(endpoint, ps) JSON.parse(res)['rsp'] end |
.sign(params, secret) ⇒ Object
Signs the RTM request (sets the ‘api_sig’ parameter).
55 56 57 58 59 60 |
# File 'lib/milk_cap/rtm/base.rb', line 55 def self.sign (params, secret) #:nodoc: params['api_sig'] = md5(secret + params.sort.flatten.join) params end |