Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

todo #23665 : can now pass rtm key and secret via method params (Gior…

…gio's request)
  • Loading branch information...
commit ecea5321a388c495f80005074f6c37c10a3be3ad 1 parent a37d102
@jmettraux authored
View
6 CHANGELOG.txt
@@ -2,6 +2,12 @@
= rufus-rtm CHANGELOG.txt
+== rufus-rtm - 0.2 not yet released
+
+- todo #23665 : can now pass rtm key and secret via method params (Giorgio's
+ request)
+
+
== rufus-rtm - 0.1 released 2008/02/14
- initial release
View
2  README.txt
@@ -20,6 +20,8 @@ http://rubyforge.org/frs/?group_id=4812
* RTM_FROB
* RTM_AUTH_TOKEN
+(Note since version 0.2, it's OK to not set these environment variables and to pass their values for each method with :api_key, :shared_secret, :frob and :auth_token optional parameters (see test_2 of test/tasks_test.rb))
+
You have to apply for the first two ones at http://www.rememberthemilk.com/services/api/keys.rtm
Once you have the API key and the shared secret, you have to get the frob and the auth token. Fire your 'irb' and
View
33 lib/rufus/rtm/base.rb
@@ -50,9 +50,10 @@ module RTM
#
# Signs the RTM request (sets the 'api_sig' parameter).
#
- def self.sign (params) #:nodoc:
+ def self.sign (params, secret) #:nodoc:
+
+ sig = MD5.md5(secret + params.sort.flatten.join)
- sig = MD5.md5(SHARED_SECRET + params.sort.flatten.join)
params['api_sig'] = sig.to_s
params
@@ -65,26 +66,32 @@ def self.milk (params={}) #:nodoc:
sleep 1
- endpoint = params.delete :endpoint
+ endpoint = params.delete(:endpoint)
endpoint = AUTH_ENDPOINT if endpoint == :auth
endpoint = endpoint || REST_ENDPOINT
- ps = params.inject({}) do |r, (k, v)|
- r[k.to_s] = v
- r
- end
+ 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['api_key'] = API_KEY
ps['format'] = 'json'
- ps['frob'] = FROB if FROB
- ps['auth_token'] = AUTH_TOKEN if AUTH_TOKEN
+ secret = params[:shared_secret] || ENV['RTM_SHARED_SECRET']
- sign ps
+ sign(ps, secret)
- res = get endpoint, :query => ps
+ res = get(endpoint, :query => ps)
- JSON.parse(res.body)["rsp"]
+ JSON.parse(res.body)['rsp']
end
#
View
17 lib/rufus/rtm/credentials.rb
@@ -45,10 +45,10 @@ def self.auth_get_frob_and_url #:nodoc:
frob = auth_get_frob
p = {}
- p['api_key'] = API_KEY
- p['perms'] = "delete"
+ p['api_key'] = ENV['RTM_API_KEY']
+ p['perms'] = 'delete'
p['frob'] = frob
- sign p
+ sign(p, ENV['RTM_SHARED_SECRET'])
[
frob,
@@ -68,16 +68,7 @@ def self.auth_get_token (frob) #:nodoc:
#
# ensuring the credentials are present...
- API_KEY = ENV['RTM_API_KEY']
- SHARED_SECRET = ENV['RTM_SHARED_SECRET']
-
- raise "API_KEY missing from environment, cannot use Rufus::RTM" \
- unless API_KEY
-
- FROB = ENV['RTM_FROB']
- AUTH_TOKEN = ENV['RTM_AUTH_TOKEN']
-
- unless FROB
+ unless ENV['RTM_FROB']
frob, auth_url = auth_get_frob_and_url
View
14 lib/rufus/rtm/resources.rb
@@ -70,11 +70,11 @@ def save!
def self.milk_attr (*att_names) #:nodoc:
att_names.each do |att_name|
- class_eval """
+ class_eval %{
def #{att_name}
@hsh['#{att_name}']
end
- """
+ }
end
end
@@ -128,11 +128,11 @@ class Task < MilkResource
def self.task_attr (*att_names) #:nodoc:
att_names.each do |att_name|
- class_eval """
+ class_eval %{
def #{att_name}
@hsh['task']['#{att_name}']
end
- """
+ }
end
end
@@ -276,10 +276,10 @@ def initialize (h)
@list_id = h['id']
end
- def self.find
+ def self.find (params={})
- execute('getList')[resource_name]['list'].collect do |h|
- self.new h
+ execute('getList', params)[resource_name]['list'].collect do |h|
+ self.new(h)
end
end
end
View
19 test/tasks_test.rb
@@ -9,6 +9,8 @@
require 'test/unit'
+$: << File.dirname(__FILE__) + '/../lib'
+
require 'rufus/rtm'
include Rufus::RTM
@@ -57,7 +59,7 @@ def test_0
def test_1
lists = List.find
- assert_not_nil(lists.find { |e| e.name == "Inbox" })
+ assert_not_nil(lists.find { |e| e.name == 'Inbox' })
work = lists.find { |e| e.name == "Work" }
@@ -76,5 +78,20 @@ def test_1
t0.delete!
end
+
+ def test_2
+
+ key = ENV.delete('RTM_API_KEY')
+ secret = ENV.delete('RTM_SHARED_SECRET')
+
+ assert_raise RuntimeError do
+ lists = List.find
+ end
+
+ assert_not_nil List.find(:api_key => key, :shared_secret => secret)
+
+ ENV['RTM_API_KEY'] = key
+ ENV['RTM_SHARED_SECRET'] = secret
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.