rmm5t-flickr_fu 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. data/.gitignore +13 -0
  2. data/LICENSE +22 -0
  3. data/README +147 -0
  4. data/Rakefile +73 -0
  5. data/VERSION.yml +4 -0
  6. data/flickr_fu.gemspec +120 -0
  7. data/lib/flickr/auth.rb +80 -0
  8. data/lib/flickr/base.rb +151 -0
  9. data/lib/flickr/comment.rb +16 -0
  10. data/lib/flickr/contact.rb +16 -0
  11. data/lib/flickr/contacts.rb +55 -0
  12. data/lib/flickr/errors.rb +20 -0
  13. data/lib/flickr/geo.rb +42 -0
  14. data/lib/flickr/license.rb +24 -0
  15. data/lib/flickr/location.rb +15 -0
  16. data/lib/flickr/note.rb +16 -0
  17. data/lib/flickr/people.rb +54 -0
  18. data/lib/flickr/person.rb +82 -0
  19. data/lib/flickr/photo.rb +321 -0
  20. data/lib/flickr/photo_response.rb +37 -0
  21. data/lib/flickr/photos.rb +246 -0
  22. data/lib/flickr/photoset.rb +37 -0
  23. data/lib/flickr/photosets.rb +39 -0
  24. data/lib/flickr/size.rb +16 -0
  25. data/lib/flickr/status.rb +19 -0
  26. data/lib/flickr/test.rb +31 -0
  27. data/lib/flickr/token.rb +22 -0
  28. data/lib/flickr/uploader.rb +162 -0
  29. data/lib/flickr/urls.rb +44 -0
  30. data/lib/flickr_fu.rb +48 -0
  31. data/spec/fixtures/flickr/contacts/get_list-fail-99.xml +4 -0
  32. data/spec/fixtures/flickr/contacts/get_public_list-0.xml +7 -0
  33. data/spec/fixtures/flickr/photos/geo/get_location-0.xml +11 -0
  34. data/spec/fixtures/flickr/photos/geo/get_location-fail-2.xml +4 -0
  35. data/spec/fixtures/flickr/photos/get_info-0.xml +41 -0
  36. data/spec/fixtures/flickr/photos/get_info-1.xml +19 -0
  37. data/spec/fixtures/flickr/photos/get_sizes-0.xml +10 -0
  38. data/spec/fixtures/flickr/photos/get_sizes-1.xml +8 -0
  39. data/spec/fixtures/flickr/photos/licenses/get_info.xml +12 -0
  40. data/spec/fixtures/flickr/photosets/get_list-0.xml +13 -0
  41. data/spec/fixtures/flickr/photosets/get_photos-0.xml +7 -0
  42. data/spec/fixtures/flickr/test/echo-0.xml +5 -0
  43. data/spec/fixtures/flickr/test/null-fail-99.xml +4 -0
  44. data/spec/fixtures/flickr/urls/get_group-0.xml +4 -0
  45. data/spec/fixtures/flickr/urls/get_group-fail-1.xml +4 -0
  46. data/spec/fixtures/flickr/urls/get_user_photos-0.xml +4 -0
  47. data/spec/fixtures/flickr/urls/get_user_photos-fail-1.xml +4 -0
  48. data/spec/fixtures/flickr/urls/get_user_photos-fail-2.xml +4 -0
  49. data/spec/fixtures/flickr/urls/get_user_profile-0.xml +4 -0
  50. data/spec/fixtures/flickr/urls/get_user_profile-fail-1.xml +4 -0
  51. data/spec/fixtures/flickr/urls/get_user_profile-fail-2.xml +4 -0
  52. data/spec/fixtures/flickr/urls/lookup_group-0.xml +6 -0
  53. data/spec/fixtures/flickr/urls/lookup_group-fail-1.xml +4 -0
  54. data/spec/fixtures/flickr/urls/lookup_user-0.xml +6 -0
  55. data/spec/fixtures/flickr/videos/get_info-0.xml +31 -0
  56. data/spec/fixtures/flickr/videos/get_sizes-0.xml +13 -0
  57. data/spec/flickr/base_spec.rb +97 -0
  58. data/spec/flickr/contacts_spec.rb +47 -0
  59. data/spec/flickr/errors_spec.rb +21 -0
  60. data/spec/flickr/geo_spec.rb +20 -0
  61. data/spec/flickr/photo_spec.rb +140 -0
  62. data/spec/flickr/photos_spec.rb +50 -0
  63. data/spec/flickr/photosets_spec.rb +49 -0
  64. data/spec/flickr/test_spec.rb +34 -0
  65. data/spec/flickr/urls_spec.rb +99 -0
  66. data/spec/spec.opts +4 -0
  67. data/spec/spec_helper.rb +20 -0
  68. metadata +150 -0
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ rdoc
2
+ .DS_Store
3
+ *.gem
4
+ demo*
5
+ *~
6
+ *.sw*
7
+ .specification
8
+ nbproject/
9
+ doc/rspec_report.html
10
+ doc/rspec_profile.txt
11
+ spec/spec.local.opts
12
+ coverage/
13
+ pkg/
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2008 CommonThread, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,147 @@
1
+ = flickr-fu
2
+
3
+ == Contact
4
+
5
+ Author: Ben Wyrosdick
6
+ Email: ben [at] commonthread.com
7
+ Lighthouse: http://commonthread.lighthouseapp.com/projects/12069-flickr_fu/overview
8
+ Main Repository: http://github.com/commonthread/flickr_fu/tree/master
9
+
10
+ == Getting Started
11
+
12
+ You need to first get an API key as detailed here:
13
+
14
+ http://www.flickr.com/services/api/misc.api_keys.html
15
+
16
+ == Installation
17
+
18
+ sudo gem install flickr-fu
19
+
20
+ == Documentation
21
+
22
+ RDoc Documentation can be found here:
23
+
24
+ http://www.commonthread.com/projects/flickr_fu/rdoc/
25
+
26
+ == Example flickr.yml
27
+ --- !map:HashWithIndifferentAccess
28
+ key: "YOUR KEY"
29
+ secret: "YOUR SECRET"
30
+ token_cache: "token_cache.yml"
31
+
32
+ == Authorization
33
+
34
+ To authorise your application to access Flickr using your API key you will
35
+ need to access a specific URL.
36
+
37
+ To generate this URL run the following and when presented with the URL
38
+ access it from your browser. Confirm the application has permission at
39
+ the level you have specified.
40
+
41
+ Note that flickr has different types of keys. If you use one for a webapplication,
42
+ which is most likely, you need to define a callback and somehow make sure that
43
+ you connect the parameter :frob that flickr send via the callback is assigned
44
+ to the right user account. The best way to do this is to loop over all the current
45
+ user's flickr accounts and try flickr.auth.token with the :frob.
46
+
47
+ Finally, cache the token (this will create the token cache file)
48
+
49
+ If you have an invalid API key you will see errors such as:
50
+
51
+ "100: Invalid API Key"
52
+
53
+ If you don't follow the process below to authorise your application
54
+ you will see errors such as:
55
+
56
+ "98: Login failed / Invalid auth token" or
57
+ "99: User not logged in / Insufficient permissions"
58
+
59
+ == Authorization Example for non-webapplication
60
+
61
+ require 'flickr_fu'
62
+
63
+ flickr = Flickr.new('flickr.yml')
64
+
65
+ puts "visit the following url, then click <enter> once you have authorized:"
66
+
67
+ # request write permissions
68
+ puts flickr.auth.url(:write)
69
+
70
+ gets
71
+
72
+ flickr.auth.cache_token
73
+
74
+ == Authorization Example for a webapplication
75
+
76
+ flickr.auth.token also contains the nsid and username, this
77
+ example only stores the token and no other userdata.
78
+
79
+ require 'flickr_fu'
80
+ class FlickrController < ActionController::Base
81
+ def create
82
+ flickr = Flickr.new('flickr.yml')
83
+ redirect_to flickr.auth.url(:write)
84
+ end
85
+ def flickr_callback
86
+ flickr = Flickr.new('flickr.yml')
87
+ flickr.auth.frob = params[:frob]
88
+ current_user.update_attribute :flickr_token, flickr.auth.token.token
89
+ end
90
+ def something_else_with_flickr
91
+ flickr = Flickr.new(YAML.load_file('flickr.yml').merge(:token => current_user.flickr_token))
92
+ # now you have full access on the user's data :)
93
+ end
94
+ end
95
+
96
+ == Search Example
97
+
98
+ require 'flickr_fu'
99
+
100
+ flickr = Flickr.new('flickr.yml')
101
+
102
+ photos = flickr.photos.search(:tags => 'ruby-flickr')
103
+
104
+ puts "found #{photos.size} photo(s)"
105
+
106
+ photos.each do |photo|
107
+ puts photo.title
108
+ puts photo.description unless [nil, ''].include?(photo.description)
109
+ [:square, :thumbnail, :small, :medium, :large, :original].each do |size|
110
+ puts "#{size}: #{photo.url(size)}"
111
+ end
112
+ puts "comments: #{photo.comments.size}"
113
+ photo.comments.each do |comment|
114
+ intro = "#{comment.author_name} says - "
115
+ puts "#{intro}\"#{comment.comment.gsub("\n", "\n"+(" "*intro.length))}\""
116
+ end
117
+ puts "notes: #{photo.notes.size}"
118
+ photo.notes.each do |note|
119
+ puts "[#{note.x},#{note.y} ~ #{note.width}x#{note.height}] - \"#{note.note}\""
120
+ end
121
+ puts
122
+ puts
123
+ end
124
+
125
+ == Another Search Example
126
+
127
+ If searching for photos by user id then you need to specify the 'alias' - without
128
+ intervention this is usually set by Flickr and is an alphanumeric string.
129
+
130
+ To find out the user id for a given user, you can use the tool at:
131
+
132
+ http://idgettr.com/
133
+
134
+ And replace the line in the above sample to query on user id:
135
+
136
+ photos = flickr.photos.search(:user_id => 'your_user_id_here')
137
+
138
+ == Patch Contributers
139
+
140
+ Chris Ledet
141
+ Maciej Biłas
142
+ Mike Perham
143
+ Chris Anderton
144
+ Luke Francl
145
+ Thomas R. Koll
146
+ P. Mark Anderson
147
+ Josh Nichols
data/Rakefile ADDED
@@ -0,0 +1,73 @@
1
+ require 'rake'
2
+ require 'rake/rdoctask'
3
+
4
+ # Gem building
5
+ begin
6
+ begin
7
+ require 'jeweler'
8
+ rescue LoadError
9
+ require 'rubygems'
10
+ require 'jeweler'
11
+ end
12
+ Jeweler::Tasks.new do |s|
13
+ s.name = "flickr_fu"
14
+ s.summary = "Provides a ruby interface to flickr via the REST api"
15
+ s.email = "ben@commonthread.com"
16
+ s.homepage = "http://github.com/commonthread/flickr_fu"
17
+ s.description = "Provides a ruby interface to flickr via the REST api"
18
+ s.authors = ["Ben Wyrosdick", "Maciej Bilas"]
19
+ s.rdoc_options = ["--main", "README"]
20
+ s.extra_rdoc_files = ["README"]
21
+ s.add_dependency("mime-types", ["> 0.0.0"])
22
+ s.add_dependency("xml-magic", ["> 0.0.0"])
23
+ s.files.exclude("spec/spec.local.opts")
24
+ end
25
+ rescue LoadError
26
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
27
+ end
28
+
29
+ desc 'Generate documentation for flickr_fu.'
30
+ Rake::RDocTask.new(:rdoc) do |rdoc|
31
+ rdoc.rdoc_dir = 'rdoc'
32
+ rdoc.title = 'flickr_fu'
33
+ rdoc.options << '--line-numbers' << '--inline-source'
34
+ rdoc.rdoc_files.include('README')
35
+ rdoc.rdoc_files.include('lib/**/*.rb')
36
+ end
37
+
38
+ # RSpec support
39
+ begin
40
+ require 'spec'
41
+ rescue LoadError
42
+ require 'rubygems'
43
+ require 'spec'
44
+ end
45
+ begin
46
+ require 'spec/rake/spectask'
47
+ rescue LoadError
48
+ puts <<-EOS
49
+ To use rspec for testing you must install rspec gem:
50
+ gem install rspec
51
+ EOS
52
+ exit(0)
53
+ end
54
+
55
+ task :default => :spec
56
+
57
+ spec_common = Proc.new do |t|
58
+ t.spec_opts = ['--options', "spec/spec.opts"]
59
+ t.spec_opts << ['--options', "spec/spec.local.opts" ] if File.exist?(File.dirname(__FILE__) + "/spec/spec.local.opts")
60
+ t.spec_files = FileList['spec/**/*_spec.rb']
61
+ end
62
+
63
+ desc "Run the specs under spec/models"
64
+ Spec::Rake::SpecTask.new do |t|
65
+ spec_common.call(t)
66
+ end
67
+
68
+ desc "Analyze code coverage with tests"
69
+ Spec::Rake::SpecTask.new("rcov") do |t|
70
+ spec_common.call(t)
71
+ t.rcov = true
72
+ t.rcov_opts = ["-x", "/var/lib", "-x", "spec/", "-T"]
73
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 3
4
+ :patch: 1
data/flickr_fu.gemspec ADDED
@@ -0,0 +1,120 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{flickr_fu}
8
+ s.version = "0.3.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ben Wyrosdick", "Maciej Bilas"]
12
+ s.date = %q{2009-09-18}
13
+ s.description = %q{Provides a ruby interface to flickr via the REST api}
14
+ s.email = %q{ben@commonthread.com}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README",
22
+ "Rakefile",
23
+ "VERSION.yml",
24
+ "flickr_fu.gemspec",
25
+ "lib/flickr/auth.rb",
26
+ "lib/flickr/base.rb",
27
+ "lib/flickr/comment.rb",
28
+ "lib/flickr/contact.rb",
29
+ "lib/flickr/contacts.rb",
30
+ "lib/flickr/errors.rb",
31
+ "lib/flickr/geo.rb",
32
+ "lib/flickr/license.rb",
33
+ "lib/flickr/location.rb",
34
+ "lib/flickr/note.rb",
35
+ "lib/flickr/people.rb",
36
+ "lib/flickr/person.rb",
37
+ "lib/flickr/photo.rb",
38
+ "lib/flickr/photo_response.rb",
39
+ "lib/flickr/photos.rb",
40
+ "lib/flickr/photoset.rb",
41
+ "lib/flickr/photosets.rb",
42
+ "lib/flickr/size.rb",
43
+ "lib/flickr/status.rb",
44
+ "lib/flickr/test.rb",
45
+ "lib/flickr/token.rb",
46
+ "lib/flickr/uploader.rb",
47
+ "lib/flickr/urls.rb",
48
+ "lib/flickr_fu.rb",
49
+ "spec/fixtures/flickr/contacts/get_list-fail-99.xml",
50
+ "spec/fixtures/flickr/contacts/get_public_list-0.xml",
51
+ "spec/fixtures/flickr/photos/geo/get_location-0.xml",
52
+ "spec/fixtures/flickr/photos/geo/get_location-fail-2.xml",
53
+ "spec/fixtures/flickr/photos/get_info-0.xml",
54
+ "spec/fixtures/flickr/photos/get_info-1.xml",
55
+ "spec/fixtures/flickr/photos/get_sizes-0.xml",
56
+ "spec/fixtures/flickr/photos/get_sizes-1.xml",
57
+ "spec/fixtures/flickr/photos/licenses/get_info.xml",
58
+ "spec/fixtures/flickr/photosets/get_list-0.xml",
59
+ "spec/fixtures/flickr/photosets/get_photos-0.xml",
60
+ "spec/fixtures/flickr/test/echo-0.xml",
61
+ "spec/fixtures/flickr/test/null-fail-99.xml",
62
+ "spec/fixtures/flickr/urls/get_group-0.xml",
63
+ "spec/fixtures/flickr/urls/get_group-fail-1.xml",
64
+ "spec/fixtures/flickr/urls/get_user_photos-0.xml",
65
+ "spec/fixtures/flickr/urls/get_user_photos-fail-1.xml",
66
+ "spec/fixtures/flickr/urls/get_user_photos-fail-2.xml",
67
+ "spec/fixtures/flickr/urls/get_user_profile-0.xml",
68
+ "spec/fixtures/flickr/urls/get_user_profile-fail-1.xml",
69
+ "spec/fixtures/flickr/urls/get_user_profile-fail-2.xml",
70
+ "spec/fixtures/flickr/urls/lookup_group-0.xml",
71
+ "spec/fixtures/flickr/urls/lookup_group-fail-1.xml",
72
+ "spec/fixtures/flickr/urls/lookup_user-0.xml",
73
+ "spec/fixtures/flickr/videos/get_info-0.xml",
74
+ "spec/fixtures/flickr/videos/get_sizes-0.xml",
75
+ "spec/flickr/base_spec.rb",
76
+ "spec/flickr/contacts_spec.rb",
77
+ "spec/flickr/errors_spec.rb",
78
+ "spec/flickr/geo_spec.rb",
79
+ "spec/flickr/photo_spec.rb",
80
+ "spec/flickr/photos_spec.rb",
81
+ "spec/flickr/photosets_spec.rb",
82
+ "spec/flickr/test_spec.rb",
83
+ "spec/flickr/urls_spec.rb",
84
+ "spec/spec.opts",
85
+ "spec/spec_helper.rb"
86
+ ]
87
+ s.homepage = %q{http://github.com/commonthread/flickr_fu}
88
+ s.rdoc_options = ["--main", "README"]
89
+ s.require_paths = ["lib"]
90
+ s.rubygems_version = %q{1.3.5}
91
+ s.summary = %q{Provides a ruby interface to flickr via the REST api}
92
+ s.test_files = [
93
+ "spec/flickr/base_spec.rb",
94
+ "spec/flickr/contacts_spec.rb",
95
+ "spec/flickr/errors_spec.rb",
96
+ "spec/flickr/geo_spec.rb",
97
+ "spec/flickr/photo_spec.rb",
98
+ "spec/flickr/photos_spec.rb",
99
+ "spec/flickr/photosets_spec.rb",
100
+ "spec/flickr/test_spec.rb",
101
+ "spec/flickr/urls_spec.rb",
102
+ "spec/spec_helper.rb"
103
+ ]
104
+
105
+ if s.respond_to? :specification_version then
106
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
107
+ s.specification_version = 3
108
+
109
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
110
+ s.add_runtime_dependency(%q<mime-types>, ["> 0.0.0"])
111
+ s.add_runtime_dependency(%q<xml-magic>, ["> 0.0.0"])
112
+ else
113
+ s.add_dependency(%q<mime-types>, ["> 0.0.0"])
114
+ s.add_dependency(%q<xml-magic>, ["> 0.0.0"])
115
+ end
116
+ else
117
+ s.add_dependency(%q<mime-types>, ["> 0.0.0"])
118
+ s.add_dependency(%q<xml-magic>, ["> 0.0.0"])
119
+ end
120
+ end
@@ -0,0 +1,80 @@
1
+ class Flickr::Auth < Flickr::Base
2
+ def initialize(flickr)
3
+ @flickr = flickr
4
+ end
5
+
6
+ # get or return a frob to use for authentication
7
+ def frob
8
+ @frob ||= get_frob
9
+ end
10
+
11
+ # set the frob
12
+ def frob= frob
13
+ @frob=frob
14
+ end
15
+
16
+ # generates the authorization url to allow access to a flickr account.
17
+ #
18
+ # Params
19
+ # * perms (Optional)
20
+ # sets the permision level to grant on the flickr account.
21
+ # :read - permission to read private information (DEFAULT)
22
+ # :write - permission to add, edit and delete photo metadata (includes 'read')
23
+ # :delete - permission to delete photos (includes 'write' and 'read')
24
+ # * options (Optional)
25
+ # additional parameters to pass to flickr. The most common use-case for
26
+ # this is to pass the (undocumented) :extra parameter that is returned
27
+ # back from flickr during the callback.
28
+ #
29
+ def url(perms = :read, options = {})
30
+ options.merge!(:api_key => @flickr.api_key, :perms => perms, :frob => self.frob)
31
+ @flickr.sign_request(options)
32
+ Flickr::Base::AUTH_ENDPOINT + "?" + options.collect{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
33
+ end
34
+
35
+ # gets the token object for the current frob
36
+ #
37
+ # Params
38
+ # * pass_through (Optional)
39
+ # Boolean value that determines if a call will be made to flickr to find a taken for the current frob if empty
40
+ #
41
+ def token(pass_through = true)
42
+ @token ||= get_token(pass_through) rescue nil
43
+ end
44
+
45
+ # saves the current token to the cache file if token exists
46
+ #
47
+ # Param
48
+ # * filename (Optional)
49
+ # filename of the cache file. defaults to the file passed into Flickr.new
50
+ #
51
+ def cache_token(filename = @flickr.token_cache)
52
+ if filename and self.token
53
+ cache_file = File.open(filename, 'w+')
54
+ cache_file.puts self.token.to_yaml
55
+ cache_file.close
56
+ true
57
+ else
58
+ false
59
+ end
60
+ end
61
+
62
+ private
63
+ def get_frob
64
+ rsp = @flickr.send_request('flickr.auth.getFrob')
65
+
66
+ rsp.frob.to_s
67
+ end
68
+
69
+ def get_token(pass_through)
70
+ if @flickr.token
71
+ @flickr.token
72
+ elsif @flickr.token_cache and File.exists?(@flickr.token_cache)
73
+ YAML.load_file(@flickr.token_cache)
74
+ elsif pass_through
75
+ rsp = @flickr.send_request('flickr.auth.getToken', {:frob => self.frob})
76
+
77
+ Token.new(:token => rsp.auth.token.to_s, :permisions => rsp.auth.perms.to_s, :user_id => rsp.auth.user[:nsid], :username => rsp.auth.user[:username], :user_real_name => rsp.auth.user[:fullname])
78
+ end
79
+ end
80
+ end