flickr_party 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.markdown +29 -34
  2. data/lib/flickr_party.rb +12 -8
  3. metadata +37 -40
data/README.markdown CHANGED
@@ -1,46 +1,41 @@
1
1
  Flickr Party
2
2
  ============
3
3
 
4
- Wrapper for the Flickr API, with real application authentication, using HTTParty.
4
+ Flickr Party is the simplest possible thing that might work for you. We build on HTTParty, and do a bit of `method_missing` magic to accept any method that the official Flickr API supports.
5
5
 
6
- About
7
- -----
8
-
9
- This piece of code uses HTTParty for its magic. All Flickr methods should
10
- be supported, but you'll still need to reference the Flickr API docs heavily
11
- and understand how they work.
12
-
13
- All method calls are automatically signed and include the authentication token.
6
+ You can also (optionally) do authenticated API calls using the `auth_url` and `complete_auth` methods (see below).
14
7
 
15
8
  Installation
16
9
  ------------
17
10
 
18
- sudo gem install flickr_party -s http://gemcutter.org
11
+ ```sh
12
+ gem install flickr_party
13
+ ```
19
14
 
20
15
  Usage
21
16
  -----
22
17
 
23
- require 'rubygems'
24
- require 'flickr_party'
25
-
26
- API_KEY = '...'
27
- SECRETE = '...'
28
-
29
- f = FlickrParty.new(API_KEY, SECRET)
30
-
31
- # The code supports real application authentication.
32
- url = f.auth_url # returns the url you should send the user to
33
- `open #{url}` # open in browser
34
-
35
- # This is just a way to pause until the user says go.
36
- # If you're building a gui app or web-based app, you will obviously do something different.
37
- print 'Press any key once you have authorized the app...'
38
- require "highline/system_extensions"
39
- HighLine::SystemExtensions.get_character
40
-
41
- f.complete_auth
42
-
43
- # The wrapper uses method_missing to accept any method supported by the API (now or in the future).
44
- # For instance, the method "flickr.activity.userPhotos" is called with the code below.
45
-
46
- f.flickr.activity.userPhotos('timeframe' => '10d')
18
+ ```ruby
19
+ require 'rubygems'
20
+ require 'flickr_party'
21
+
22
+ # get your key and secret from:
23
+ # http://www.flickr.com/services/apps
24
+ API_KEY = '...'
25
+ SECRET = '...'
26
+
27
+ f = FlickrParty.new(API_KEY, SECRET)
28
+
29
+ # if you want to do authenticated calls, authenticate the user like so:
30
+ f.auth_url # open this in a browser for the user to confirm
31
+ # wait until confirmed, and then save the auth token...
32
+ token = f.complete_auth
33
+
34
+ # call any API method by calling it on the FlickrParty object directly
35
+ # pass in any needed parameters as a hash
36
+ # pass in the auth_token if authentication is required for this call
37
+ data = f.flickr.activity.userPhotos('timeframe' => '10d', 'auth_token' => token)
38
+
39
+ # data is presented vary raw, in the "rsp" key...
40
+ data['rsp'] # => data
41
+ ```
data/lib/flickr_party.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'httparty'
3
- require 'md5'
3
+ require 'digest/md5'
4
4
 
5
5
  class FlickrParty
6
6
 
@@ -25,11 +25,14 @@ class FlickrParty
25
25
  def method_missing(method_name, args={}, test=nil)
26
26
  if @method.to_s.count('.') == 2 or method_name.to_s =~ /[A-Z]/ or THIRD_LEVEL_METHODS.include?(method_name.to_s)
27
27
  args = self.class.stringify_hash_keys(args)
28
- args.merge!('api_key' => @api_key, 'method' => @method + '.' + method_name.to_s, 'format' => 'rest')
28
+ args.merge!('api_key' => @api_key, 'method' => @method + '.' + method_name.to_s)
29
29
  if @token
30
30
  args.merge!('auth_token' => @token)
31
31
  end
32
- args.merge!(:api_sig => MD5.hexdigest(@secret + args.to_a.sort.to_s))
32
+ args_to_s = ""
33
+ args.sort.each{|a| args_to_s += a[0].to_s + a[1].to_s }
34
+ sig = Digest::MD5.hexdigest(@secret.to_s + args_to_s)
35
+ args.merge!(:api_sig => sig)
33
36
  self.class.post(ENDPOINT, :body => args)
34
37
  else
35
38
  if @method
@@ -41,17 +44,18 @@ class FlickrParty
41
44
  end
42
45
  end
43
46
 
44
- def auth_url(perms='read')
47
+ def auth_url(perms='read', extra = nil)
45
48
  @frob = self.flickr.auth.getFrob['rsp']['frob']
46
- sig = MD5.hexdigest("#{@secret}api_key#{@api_key}frob#{@frob}perms#{perms}")
47
- "http://flickr.com/services/auth/?api_key=#{@api_key}&perms=#{perms}&frob=#{@frob}&api_sig=#{sig}"
49
+ sig = Digest::MD5.hexdigest("#{@secret}api_key#{@api_key}extra#{extra}frob#{@frob}perms#{perms}")
50
+ "http://flickr.com/services/auth/?api_key=#{@api_key}&perms=#{perms}&frob=#{@frob}&api_sig=#{sig}&extra=#{extra}"
48
51
  end
49
52
 
50
- def complete_auth
53
+ def complete_auth(frob='put_your_frob_here')
54
+ @frob ||= frob
51
55
  @auth = self.flickr.auth.getToken('frob' => @frob)['rsp']['auth']
52
56
  @token = @auth['token']
53
57
  end
54
-
58
+
55
59
  def photo_url(photo_hash, size=nil)
56
60
  if %w(m s t b).include?(size)
57
61
  "http://farm#{photo_hash['farm']}.static.flickr.com/#{photo_hash['server']}/#{photo_hash['id']}_#{photo_hash['secret']}_#{size}.jpg"
metadata CHANGED
@@ -1,65 +1,62 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: flickr_party
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.1
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.3.0
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Tim Morgan
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2009-10-21 00:00:00 -05:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: httparty
12
+ date: 2013-03-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ name: httparty
25
30
  description:
26
31
  email: tim@timmorgan.org
27
32
  executables: []
28
-
29
33
  extensions: []
30
-
31
34
  extra_rdoc_files: []
32
-
33
- files:
35
+ files:
34
36
  - README.markdown
35
37
  - lib/flickr_party.rb
36
- has_rdoc: true
37
38
  homepage: http://github.com/seven1m/flickr_party
38
39
  licenses: []
39
-
40
40
  post_install_message:
41
41
  rdoc_options: []
42
-
43
- require_paths:
42
+ require_paths:
44
43
  - lib
45
- required_ruby_version: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: "0"
50
- version:
51
- required_rubygems_version: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
56
- version:
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
57
56
  requirements: []
58
-
59
57
  rubyforge_project:
60
- rubygems_version: 1.3.5
58
+ rubygems_version: 1.8.24
61
59
  signing_key:
62
60
  specification_version: 3
63
61
  summary: Lightweight wrapper for Flickr API using HTTParty
64
62
  test_files: []
65
-