Permalink
Browse files

Changed MD5 to Digest::MD5 and modified the sig a bit

  • Loading branch information...
1 parent cff17b2 commit adaaf4b0a9dcf0d64b10a03864b5843ea7a5dccc @jrichter jrichter committed Sep 5, 2010
Showing with 17 additions and 9 deletions.
  1. +1 −0 .gitignore
  2. +6 −3 README.markdown
  3. +10 −6 lib/flickr_party.rb
View
@@ -0,0 +1 @@
+*.swp
View
@@ -24,7 +24,7 @@ Usage
require 'flickr_party'
API_KEY = '...'
- SECRETE = '...'
+ SECRET = '...'
f = FlickrParty.new(API_KEY, SECRET)
@@ -38,9 +38,12 @@ Usage
require "highline/system_extensions"
HighLine::SystemExtensions.get_character
- f.complete_auth
+ # Get the frob from the previous url.
+ @frob = "my_super_awesome_frob"
+
+ @token = f.complete_auth('frob' => @frob)
# The wrapper uses method_missing to accept any method supported by the API (now or in the future).
# For instance, the method "flickr.activity.userPhotos" is called with the code below.
- f.flickr.activity.userPhotos('timeframe' => '10d')
+ f.flickr.activity.userPhotos('timeframe' => '10d', 'auth_token' => @token)
View
@@ -1,6 +1,6 @@
require 'rubygems'
require 'httparty'
-require 'md5'
+require 'digest/md5'
class FlickrParty
@@ -25,11 +25,14 @@ def initialize(api_key, secret, method=nil, token=nil)
def method_missing(method_name, args={}, test=nil)
if @method.to_s.count('.') == 2 or method_name.to_s =~ /[A-Z]/ or THIRD_LEVEL_METHODS.include?(method_name.to_s)
args = self.class.stringify_hash_keys(args)
- args.merge!('api_key' => @api_key, 'method' => @method + '.' + method_name.to_s, 'format' => 'rest')
+ args.merge!('api_key' => @api_key, 'method' => @method + '.' + method_name.to_s)
if @token
args.merge!('auth_token' => @token)
end
- args.merge!(:api_sig => MD5.hexdigest(@secret + args.to_a.sort.to_s))
+ args_to_s = ""
+ args.sort.each{|a| args_to_s += a[0].to_s + a[1].to_s }
+ sig = Digest::MD5.hexdigest(@secret.to_s + args_to_s)
+ args.merge!(:api_sig => sig)
self.class.post(ENDPOINT, :body => args)
else
if @method
@@ -43,15 +46,16 @@ def method_missing(method_name, args={}, test=nil)
def auth_url(perms='read')
@frob = self.flickr.auth.getFrob['rsp']['frob']
- sig = MD5.hexdigest("#{@secret}api_key#{@api_key}frob#{@frob}perms#{perms}")
+ sig = Digest::MD5.hexdigest("#{@secret}api_key#{@api_key}frob#{@frob}perms#{perms}")
"http://flickr.com/services/auth/?api_key=#{@api_key}&perms=#{perms}&frob=#{@frob}&api_sig=#{sig}"
end
- def complete_auth
+ def complete_auth(frob='put_your_frob_here')
+ @frob ||= frob
@auth = self.flickr.auth.getToken('frob' => @frob)['rsp']['auth']
@token = @auth['token']
end
-
+
def photo_url(photo_hash, size=nil)
if %w(m s t b).include?(size)
"http://farm#{photo_hash['farm']}.static.flickr.com/#{photo_hash['server']}/#{photo_hash['id']}_#{photo_hash['secret']}_#{size}.jpg"

0 comments on commit adaaf4b

Please sign in to comment.