lib/rufus/rtm/base.rb in rufus-rtm-0.1.2 vs lib/rufus/rtm/base.rb in rufus-rtm-0.1.3

- old
+ new

@@ -1,7 +1,7 @@ #-- -# Copyright (c) 2008-2009, John Mettraux, jmettraux@gmail.com +# Copyright (c) 2008-2010, John Mettraux, jmettraux@gmail.com # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -21,40 +21,49 @@ # # Made in Japan. #++ -require 'rubygems' require 'rufus/verbs' -require 'json' -require 'md5' +require 'json' # gem install 'json' or 'json_pure' -include Rufus::Verbs +begin + require 'md5' + def md5 (s) + MD5.md5(s).to_s + end + +rescue LoadError # ruby 1.9.x + + require 'digest/md5' + + def md5 (s) + Digest::MD5.hexdigest(s) + end +end + + module Rufus module RTM - VERSION = '0.1.2' + VERSION = '0.1.3' AUTH_ENDPOINT = "http://www.rememberthemilk.com/services/auth/" REST_ENDPOINT = "http://api.rememberthemilk.com/services/rest/" - # # Signs the RTM request (sets the 'api_sig' parameter). # def self.sign (params, secret) #:nodoc: - sig = MD5.md5(secret + params.sort.flatten.join) + params['api_sig'] = md5(secret + params.sort.flatten.join) - params['api_sig'] = sig.to_s - params end - # # Calls an API method (milk the cow). # def self.milk (params={}) #:nodoc: sleep 1 @@ -80,15 +89,14 @@ secret = params[:shared_secret] || ENV['RTM_SHARED_SECRET'] sign(ps, secret) - res = get(endpoint, :query => ps) + res = Rufus::Verbs.get(endpoint, :query => ps) JSON.parse(res.body)['rsp'] end - # # Requests a timeline from RTM. # def self.get_timeline #:nodoc: milk(:method => 'rtm.timelines.create')['timeline']