flickr.rb 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/Changelog.txt +7 -2
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +24 -0
  5. data/LICENSE +16 -17
  6. data/Manifest.txt +2 -2
  7. data/README.txt +3 -1
  8. data/Rakefile +3 -24
  9. data/flickr.gemspec +22 -17
  10. data/lib/flickr.rb +104 -104
  11. data/rdoc/Flickr.html +1003 -0
  12. data/rdoc/Flickr/Config.html +267 -0
  13. data/rdoc/Flickr/Group.html +343 -0
  14. data/rdoc/Flickr/Photo.html +1396 -0
  15. data/rdoc/Flickr/PhotoCollection.html +229 -0
  16. data/rdoc/Flickr/Photoset.html +359 -0
  17. data/rdoc/Flickr/User.html +745 -0
  18. data/rdoc/README_txt.html +199 -0
  19. data/rdoc/created.rid +3 -1
  20. data/rdoc/fonts.css +167 -0
  21. data/rdoc/fonts/Lato-Light.ttf +0 -0
  22. data/rdoc/fonts/Lato-LightItalic.ttf +0 -0
  23. data/rdoc/fonts/Lato-Regular.ttf +0 -0
  24. data/rdoc/fonts/Lato-RegularItalic.ttf +0 -0
  25. data/rdoc/fonts/SourceCodePro-Bold.ttf +0 -0
  26. data/rdoc/fonts/SourceCodePro-Regular.ttf +0 -0
  27. data/rdoc/images/add.png +0 -0
  28. data/rdoc/images/arrow_up.png +0 -0
  29. data/rdoc/images/brick.png +0 -0
  30. data/rdoc/images/brick_link.png +0 -0
  31. data/rdoc/images/bug.png +0 -0
  32. data/rdoc/images/bullet_black.png +0 -0
  33. data/rdoc/images/bullet_toggle_minus.png +0 -0
  34. data/rdoc/images/bullet_toggle_plus.png +0 -0
  35. data/rdoc/images/date.png +0 -0
  36. data/rdoc/images/delete.png +0 -0
  37. data/rdoc/images/find.png +0 -0
  38. data/rdoc/images/loadingAnimation.gif +0 -0
  39. data/rdoc/images/macFFBgHack.png +0 -0
  40. data/rdoc/images/package.png +0 -0
  41. data/rdoc/images/page_green.png +0 -0
  42. data/rdoc/images/page_white_text.png +0 -0
  43. data/rdoc/images/page_white_width.png +0 -0
  44. data/rdoc/images/plugin.png +0 -0
  45. data/rdoc/images/ruby.png +0 -0
  46. data/rdoc/images/tag_blue.png +0 -0
  47. data/rdoc/images/tag_green.png +0 -0
  48. data/rdoc/images/transparent.png +0 -0
  49. data/rdoc/images/wrench.png +0 -0
  50. data/rdoc/images/wrench_orange.png +0 -0
  51. data/rdoc/images/zoom.png +0 -0
  52. data/rdoc/index.html +101 -21
  53. data/rdoc/js/darkfish.js +140 -0
  54. data/rdoc/js/jquery.js +18 -0
  55. data/rdoc/js/navigation.js +142 -0
  56. data/rdoc/js/search.js +109 -0
  57. data/rdoc/js/search_index.js +1 -0
  58. data/rdoc/js/searcher.js +228 -0
  59. data/rdoc/rdoc.css +580 -0
  60. data/rdoc/table_of_contents.html +473 -0
  61. data/test/flickr_test.rb +229 -227
  62. metadata +132 -68
  63. data/rdoc/classes/Flickr.html +0 -807
  64. data/rdoc/classes/Flickr/Config.html +0 -240
  65. data/rdoc/classes/Flickr/Group.html +0 -251
  66. data/rdoc/classes/Flickr/Photo.html +0 -1101
  67. data/rdoc/classes/Flickr/PhotoCollection.html +0 -194
  68. data/rdoc/classes/Flickr/Photoset.html +0 -266
  69. data/rdoc/classes/Flickr/User.html +0 -738
  70. data/rdoc/files/README_txt.html +0 -209
  71. data/rdoc/files/lib/flickr_rb.html +0 -162
  72. data/rdoc/fr_class_index.html +0 -33
  73. data/rdoc/fr_file_index.html +0 -28
  74. data/rdoc/fr_method_index.html +0 -112
  75. data/rdoc/rdoc-style.css +0 -208
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe1049d8dd0d71354cf7f221012392823c8896eb
4
+ data.tar.gz: c95508f5d5d08a400aa902ef1b174f0838431daf
5
+ SHA512:
6
+ metadata.gz: 70cabf927f292907dee0eb85efa4cf7a0e249e1d04950d89c48a82a0d864b14f2dd325eeaa83091582878814a366b7f6e74525412a449e43622abe0e32a10d13
7
+ data.tar.gz: 60b7e5c0a70268b8e9efb90d3af595e3cc2aed001f54ef8b53320b2058bca095fe2816b5c883d121fcd8fde2c505105b0d26bc21ba7fa025baffe0de0f98b434
@@ -1,3 +1,8 @@
1
+ 1.1.1 2014-04-17
2
+ * Migrated to usage of Bundler for dependency tracking
3
+ * Fixes retrieving list of photos no matter which sibling they are in XML structure
4
+ * Made tests compatible with latest version of mocha
5
+
1
6
  1.1.0 2010-05-16
2
7
  * Major improvement - now gem is very easy to use as a rails plugin with external configuration for api connection. - /config/flickr.api.yml
3
8
 
@@ -18,7 +23,7 @@
18
23
  * 1 major enhancement
19
24
  * When a collection of photos is fetched (e.g. by Flickr#search), a PhotoCollection object is now returned, a type of array, which allows easy access to the pagination information returned by Flickr (e.g. total items, pages, etc). Previously this info was lost
20
25
  * Minor enhancements:
21
- * Refactored parsing of response when getting info about photo (public API is not changed).
26
+ * Refactored parsing of response when getting info about photo (public API is not changed).
22
27
  * All returned info is now parsed and stored (previously only some attributes were)
23
28
  * A record is kept of whether info has been previously fetched from Flickr (avoids unnecessary extra calls)
24
29
  * Improved User#getInfo. No longer makes API call for pretty_url (which was in addition to main getInfo call) or photos_url
@@ -49,7 +54,7 @@
49
54
  * Minor enhancements:
50
55
  * Tweaked internals so new client instance isn't created each time new object (e.g. photo, user) is created
51
56
  * Improved test coverage
52
-
57
+
53
58
  == 1.0.4 2008-05-11
54
59
 
55
60
  * 1 major enhancement:
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ flickr (1.1.0)
5
+ xml-simple (>= 1.0.7)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ metaclass (0.0.4)
11
+ mocha (1.0.0)
12
+ metaclass (~> 0.0.1)
13
+ rake (10.1.1)
14
+ rdoc (4.0.0)
15
+ xml-simple (1.1.3)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ flickr!
22
+ mocha
23
+ rake
24
+ rdoc
data/LICENSE CHANGED
@@ -1,20 +1,19 @@
1
- Copyright (c) 2007 Scott Raymond, Patrick Plattes, Chris Taggart
1
+ Copyright (c) 2007 Scott Raymond, Patrick Plattes, Chris Taggart, Rafał Piekarski
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
10
9
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
13
12
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -1,10 +1,10 @@
1
- History.txt
1
+ Changelog.txt
2
2
  index.html
3
3
  init.rb
4
4
  lib/flickr.rb
5
5
  LICENSE
6
6
  Manifest.txt
7
7
  Rakefile
8
- README.txt
8
+ README.txt
9
9
  test/flickr_test.rb
10
10
  TODO
data/README.txt CHANGED
@@ -46,7 +46,9 @@ This has now been largely corrected, though not all current API calls are suppor
46
46
 
47
47
  == INSTALL:
48
48
 
49
- sudo gem install flickr
49
+ sudo gem install flickr.rb
50
+
51
+ * Gem homepage: http://rubygems.org/gems/flickr.rb
50
52
 
51
53
  == CONFIGURING:
52
54
 
data/Rakefile CHANGED
@@ -1,11 +1,10 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
- require 'rake/rdoctask'
4
- require 'rake/gempackagetask'
5
- require 'rubygems'
3
+ require 'rdoc/task'
4
+ require "bundler/gem_tasks"
6
5
 
7
6
  task :default => :test
8
-
7
+
9
8
  desc 'Test the flickr plugin.'
10
9
  Rake::TestTask.new(:test) do |t|
11
10
  t.libs << 'lib'
@@ -23,26 +22,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
23
22
  rdoc.rdoc_files.include('lib/**/*.rb')
24
23
  end
25
24
 
26
- spec = Gem::Specification.new do |s|
27
- s.add_dependency('xml-simple', '>= 1.0.7')
28
- s.name = 'flickr.rb'
29
- s.version = "1.1.0"
30
- s.platform = Gem::Platform::RUBY
31
- s.summary = "An insanely easy interface to the Flickr photo-sharing service. Also available as a Rails plugin! By Scott Raymond. Maintainer: Patrick Plattes, Rafal Piekarski"
32
- s.requirements << 'Flickr developers API key'
33
- s.files = Dir.glob("**/*").delete_if { |item| item.include?(".git") || item[/^pkg/] }
34
- s.require_path = 'lib'
35
- s.author = "Scott Raymond, Patrick Plattes, Rafal Piekarski"
36
- s.email = "ravbaker@gmail.com"
37
- s.rubyforge_project = "flickr"
38
- s.homepage = "http://github.com/RaVbaker/flickr/"
39
- end
40
-
41
- Rake::GemPackageTask.new(spec) do |pkg|
42
- pkg.need_zip = true
43
- pkg.need_tar = true
44
- end
45
-
46
25
  task "Dump Gemspec file"
47
26
  task :debug do
48
27
  puts spec.to_ruby
@@ -1,30 +1,35 @@
1
1
  Gem::Specification.new do |s|
2
- s.name = %q{flickr}
3
- s.version = "1.1.0"
2
+ s.name = 'flickr.rb'
3
+ s.version = '1.1.1'
4
+ s.authors = ['Scott Raymond, Patrick Plattes, Rafal Piekarski']
5
+ s.autorequire = 'flickr.rb'
6
+ s.date = '2010-05-15'
7
+ s.email = 'ravbaker@gmail.com'
8
+ s.files = Dir.glob("**/*").delete_if { |item| item.include?(".git") || item[/^pkg/] }
9
+ s.homepage = 'http://github.com/RaVbaker/flickr/'
10
+ s.require_paths = ['lib']
11
+ s.requirements = ['Flickr developers API key']
12
+ s.summary = 'An insanely easy interface to the Flickr photo-sharing service. Also available as a Rails plugin! By Scott Raymond. Maintainer: Rafal Piekarski'
13
+ s.description = 'Gem for using Flickr API in Ruby - https://www.flickr.com/services/api/'
14
+ s.licenses = ['MIT']
4
15
 
5
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
- s.authors = ["Scott Raymond, Patrick Plattes, Rafal Piekarski"]
7
- s.autorequire = %q{flickr}
8
- s.date = %q{2010-05-15}
9
- s.email = %q{ravbaker@gmail.com}
10
- s.files = ["History.txt", "LICENSE", "README.txt", "TODO", "lib/flickr.rb", "test/flickr_test.rb", "init.rb"]
11
- s.homepage = %q{http://github.com/RaVbaker/flickr/}
12
- s.require_paths = ["lib"]
13
- s.requirements = ["Flickr developers API key"]
14
- s.rubyforge_project = %q{flickr}
15
- s.rubygems_version = %q{1.2.0}
16
- s.summary = %q{An insanely easy interface to the Flickr photo-sharing service. Also available as a rails plugin! By Scott Raymond. Maintainer: Rafal Piekarski}
16
+ s.rubygems_version = '1.2.0'
17
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
17
18
 
18
19
  if s.respond_to? :specification_version then
19
20
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
20
21
  s.specification_version = 2
21
22
 
22
23
  if current_version >= 3 then
23
- s.add_runtime_dependency(%q<xml-simple>, [">= 1.0.7"])
24
+ s.add_runtime_dependency(%q<xml-simple>, ['>= 1.0.7'])
24
25
  else
25
- s.add_dependency(%q<xml-simple>, [">= 1.0.7"])
26
+ s.add_dependency(%q<xml-simple>, ['>= 1.0.7'])
26
27
  end
27
28
  else
28
- s.add_dependency(%q<xml-simple>, [">= 1.0.7"])
29
+ s.add_dependency(%q<xml-simple>, ['>= 1.0.7'])
29
30
  end
31
+
32
+ s.add_development_dependency 'rake'
33
+ s.add_development_dependency 'rdoc'
34
+ s.add_development_dependency 'mocha'
30
35
  end
@@ -1,6 +1,6 @@
1
1
  # = Flickr
2
2
  # An insanely easy interface to the Flickr photo-sharing service. By Scott Raymond.
3
- #
3
+ #
4
4
  # Author:: Scott Raymond <sco@redgreenblu.com>
5
5
  # Copyright:: Copyright (c) 2005 Scott Raymond <sco@redgreenblu.com>. Additional content by Patrick Plattes and Chris Taggart (http://pushrod.wordpress.com)
6
6
  # License:: MIT <http://www.opensource.org/licenses/mit-license.php>
@@ -42,21 +42,21 @@ require 'digest/md5'
42
42
  class Flickr
43
43
  attr_reader :api_key, :auth_token
44
44
  attr_accessor :user
45
-
45
+
46
46
  HOST_URL = 'http://api.flickr.com'
47
47
  API_PATH = '/services/rest'
48
48
 
49
- # Flickr, annoyingly, uses a number of representations to specify the size
49
+ # Flickr, annoyingly, uses a number of representations to specify the size
50
50
  # of a photo, depending on the context. It gives a label such a "Small" or
51
- # "Medium" to a size of photo, when returning all possible sizes. However,
51
+ # "Medium" to a size of photo, when returning all possible sizes. However,
52
52
  # when generating the uri for the page that features that size of photo, or
53
- # the source url for the image itself it uses a single letter. Bizarrely,
53
+ # the source url for the image itself it uses a single letter. Bizarrely,
54
54
  # these letters are different depending on whether you want the Flickr page
55
55
  # for the photo or the source uri -- e.g. a "Small" photo (240 pixels on its
56
- # longest side) may be viewed at
56
+ # longest side) may be viewed at
57
57
  # "http://www.flickr.com/photos/sco/2397458775/sizes/s/"
58
- # but its source is at
59
- # "http://farm4.static.flickr.com/3118/2397458775_2ec2ddc324_m.jpg".
58
+ # but its source is at
59
+ # "http://farm4.static.flickr.com/3118/2397458775_2ec2ddc324_m.jpg".
60
60
  # The VALID_SIZES hash associates the correct letter with a label
61
61
  VALID_SIZES = { "Square" => ["s", "sq"],
62
62
  "Thumbnail" => ["t", "t"],
@@ -65,15 +65,15 @@ class Flickr
65
65
  "Large" => ["b", "l"]
66
66
  }
67
67
 
68
- # To use the Flickr API you need an api key
69
- # (see http://www.flickr.com/services/api/misc.api_keys.html), and the flickr
68
+ # To use the Flickr API you need an api key
69
+ # (see http://www.flickr.com/services/api/misc.api_keys.html), and the flickr
70
70
  # client object shuld be initialized with this. You'll also need a shared
71
71
  # secret code if you want to use authentication (e.g. to get a user's
72
72
  # private photos)
73
73
  # There are two ways to initialize the Flickr client. The preferred way is with
74
- # a hash of params, e.g. 'api_key' => 'your_api_key', 'shared_secret' =>
75
- # 'shared_secret_code'. Other way is to use in Rails an config file
76
- # RAILS_ROOT/config/flickr.api.yml and there use params as key/values even
74
+ # a hash of params, e.g. 'api_key' => 'your_api_key', 'shared_secret' =>
75
+ # 'shared_secret_code'. Other way is to use in Rails an config file
76
+ # RAILS_ROOT/config/flickr.api.yml and there use params as key/values even
77
77
  # specified for every environment.
78
78
  def initialize(api_key_or_params={})
79
79
  @host = HOST_URL
@@ -82,8 +82,8 @@ class Flickr
82
82
  api_key_or_params = {:api_key => api_key_or_params} if api_key_or_params.is_a?(String)
83
83
  api_key_or_params = Config.get if Config.parsed? and api_key_or_params.empty?
84
84
  set_up_configuration api_key_or_params if api_key_or_params.is_a? Hash
85
- end
86
-
85
+ end
86
+
87
87
  def set_up_configuration api_key_or_params = {}
88
88
  @api_key = api_key_or_params[:api_key]
89
89
  @shared_secret = api_key_or_params[:shared_secret]
@@ -96,13 +96,13 @@ class Flickr
96
96
  def get_token_from(frob)
97
97
  auth_response = request("auth.getToken", :frob => frob)['auth']
98
98
  @auth_token = auth_response['token']
99
- @user = User.new( 'id' => auth_response['user']['nsid'],
99
+ @user = User.new( 'id' => auth_response['user']['nsid'],
100
100
  'username' => auth_response['user']['username'],
101
101
  'name' => auth_response['user']['fullname'],
102
102
  'client' => self)
103
103
  @auth_token
104
- end
105
-
104
+ end
105
+
106
106
  # Implements flickr.urls.lookupGroup and flickr.urls.lookupUser
107
107
  def find_by_url(url)
108
108
  response = urls_lookupUser('url'=>url) rescue urls_lookupGroup('url'=>url) rescue nil
@@ -119,18 +119,18 @@ class Flickr
119
119
  def recent
120
120
  photos_request('photos.getRecent')
121
121
  end
122
-
122
+
123
123
  def photos_search(params={})
124
124
  photos_request('photos.search', params)
125
125
  end
126
126
  alias_method :search, :photos_search
127
-
127
+
128
128
  # Gets public photos with a given tag
129
129
  def tag(tag)
130
130
  photos('tags'=>tag)
131
131
  end
132
-
133
- # Implements flickr.people.findByEmail and flickr.people.findByUsername.
132
+
133
+ # Implements flickr.people.findByEmail and flickr.people.findByUsername.
134
134
  def users(lookup=nil)
135
135
  user = people_findByEmail('find_email'=>lookup)['user'] rescue people_findByUsername('username'=>lookup)['user']
136
136
  return User.new("id" => user["nsid"], "username" => user["username"], "client" => self)
@@ -140,35 +140,35 @@ class Flickr
140
140
  def groups(group_name, options={})
141
141
  collection = groups_search({"text" => group_name}.merge(options))['groups']['group']
142
142
  collection = [collection] if collection.is_a? Hash
143
-
144
- collection.collect { |group| Group.new( "id" => group['nsid'],
145
- "name" => group['name'],
143
+
144
+ collection.collect { |group| Group.new( "id" => group['nsid'],
145
+ "name" => group['name'],
146
146
  "eighteenplus" => group['eighteenplus'],
147
147
  "client" => self) }
148
148
  end
149
-
149
+
150
150
  def photoset(photoset_id)
151
151
  Photoset.new(photoset_id, @api_key)
152
152
  end
153
-
153
+
154
154
  # Implements flickr.tags.getRelated
155
155
  def related_tags(tag)
156
156
  tags_getRelated('tag'=>tag)['tags']['tag']
157
157
  end
158
-
158
+
159
159
  # Implements flickr.photos.licenses.getInfo
160
160
  def licenses
161
161
  photos_licenses_getInfo['licenses']['license']
162
162
  end
163
-
163
+
164
164
  # Returns url for user to login in to Flickr to authenticate app for a user
165
165
  def login_url(perms)
166
166
  "http://flickr.com/services/auth/?api_key=#{@api_key}&perms=#{perms}&api_sig=#{signature_from('api_key'=>@api_key, 'perms' => perms)}"
167
167
  end
168
-
168
+
169
169
  # Implements everything else.
170
170
  # Any method not defined explicitly will be passed on to the Flickr API,
171
- # and return an XmlSimple document. For example, Flickr#test_echo is not
171
+ # and return an XmlSimple document. For example, Flickr#test_echo is not
172
172
  # defined, so it will pass the call to the flickr.test.echo method.
173
173
  def method_missing(method_id, params={})
174
174
  request(method_id.id2name.gsub(/_/, '.'), params)
@@ -188,82 +188,82 @@ class Flickr
188
188
  end
189
189
 
190
190
  # acts like request but returns a PhotoCollection (a list of Photo objects)
191
- def photos_request(method, params={})
191
+ def photos_request(method, params={}, list_node="photos")
192
192
  photos = request(method, params)
193
- PhotoCollection.new(photos, @api_key)
193
+ PhotoCollection.new(photos, @api_key, list_node)
194
194
  end
195
-
196
- # Builds url for Flickr API REST request from given the flickr method name
195
+
196
+ # Builds url for Flickr API REST request from given the flickr method name
197
197
  # (exclusing the 'flickr.' that begins each method call) and params (where
198
198
  # applicable) which should be supplied as a Hash (e.g 'user_id' => "foo123")
199
199
  def request_url(method, params={})
200
200
  method = 'flickr.' + method
201
201
  url = "#{@host}#{@api}/?api_key=#{@api_key}&method=#{method}"
202
202
  params.merge!('api_key' => @api_key, 'method' => method, 'auth_token' => @auth_token)
203
- signature = signature_from(params)
204
-
203
+ signature = signature_from(params)
204
+
205
205
  url = "#{@host}#{@api}/?" + params.merge('api_sig' => signature).collect { |k,v| "#{k}=" + CGI::escape(v.to_s) unless v.nil? }.compact.join("&")
206
206
  end
207
-
207
+
208
208
  def signature_from(params={})
209
209
  return unless @shared_secret # don't both getting signature if no shared_secret
210
210
  request_str = params.reject {|k,v| v.nil?}.collect {|p| "#{p[0].to_s}#{p[1]}"}.sort.join # build key value pairs, sort in alpha order then join them, ignoring those with nil value
211
211
  return Digest::MD5.hexdigest("#{@shared_secret}#{request_str}")
212
212
  end
213
-
213
+
214
214
  # A collection of photos is returned as a PhotoCollection, a subclass of Array.
215
215
  # This allows us to retain the pagination info returned by Flickr and make it
216
216
  # accessible in a friendly way
217
217
  class PhotoCollection < Array
218
218
  attr_reader :page, :pages, :perpage, :total
219
-
220
- # builds a PhotoCollection from given params, such as those returned from
221
- # photos.search API call. Note all the info is contained in the value of
222
- # the first (and only) key-value pair of the response. The key will vary
219
+
220
+ # builds a PhotoCollection from given params, such as those returned from
221
+ # photos.search API call. Note all the info is contained in the value of
222
+ # the first (and only) key-value pair of the response. The key will vary
223
223
  # depending on the original object the photos are related to (e.g 'photos',
224
224
  # 'photoset', etc)
225
- def initialize(photos_api_response={}, api_key={})
226
- photos = photos_api_response.values.first
227
- [ "page", "pages", "perpage", "total" ].each { |i| instance_variable_set("@#{i}", photos[i])}
225
+ def initialize(photos_api_response={}, api_key={}, list_node="photos")
226
+ photos = photos_api_response[list_node]
227
+ [ "page", "pages", "perpage", "total" ].each { |i| instance_variable_set("@#{i}", photos[i])}
228
228
  collection = photos['photo'] || []
229
229
  collection = [collection] if collection.is_a? Hash
230
230
  collection.each { |photo| self << Photo.new(photo.delete('id'), api_key, photo) }
231
231
  end
232
- end
233
-
232
+ end
233
+
234
234
  # This class supports external configuration
235
- class Config
236
-
235
+ class Config
236
+
237
237
  # Contains whole configuration for flickr API
238
- @@configuration = {}
239
-
238
+ @@configuration = {}
239
+
240
240
  # Is true if configuration has been parsed
241
241
  @@parsed = false
242
-
242
+
243
243
  # parses file and prepare @@configuration for access from outside to fetch configuration hash
244
244
  def self.load_from_file file
245
245
  return false unless File.exist?(file)
246
246
  @@configuration = YAML.load(ERB.new(File.read(file)).result)
247
247
  @@parsed = true
248
248
  parse_in_rails_env!
249
- end
250
-
249
+ end
250
+
251
251
  # Excludes specific configuration for choosed environment in Rails
252
252
  def self.parse_in_rails_env!
253
- @@configuration = @@configuration[RAILS_ENV].symbolize_keys if defined? RAILS_ENV
254
- end
255
-
253
+ @@configuration = @@configuration[RAILS_ENV].symbolize_keys if defined? RAILS_ENV and @@configuration.has_key? RAILS_ENV
254
+ end
255
+
256
256
  # Returns configuration Hash
257
257
  def self.get
258
258
  @@configuration
259
259
  end
260
-
260
+
261
261
  # Returns true if configuration has been parsed
262
262
  def self.parsed?
263
263
  @@parsed
264
264
  end
265
265
  end
266
-
266
+
267
267
  # Todo:
268
268
  # logged_in?
269
269
  # if logged in:
@@ -279,20 +279,20 @@ class Flickr
279
279
  # flickr.test.login
280
280
  # uploading
281
281
  class User
282
-
282
+
283
283
  attr_reader :client, :id, :name, :location, :photos_url, :url, :count, :firstdate, :firstdatetaken
284
284
 
285
- # A Flickr::User can be instantiated in two ways. The old (deprecated)
286
- # method is with an ordered series of values. The new method is with a
287
- # params Hash, which is easier when a variable number of params are
285
+ # A Flickr::User can be instantiated in two ways. The old (deprecated)
286
+ # method is with an ordered series of values. The new method is with a
287
+ # params Hash, which is easier when a variable number of params are
288
288
  # supplied, which is the case here, and also avoids having to constantly
289
289
  # supply nil values for the email and password, which are now irrelevant
290
- # as authentication is no longer done this way.
291
- # An associated flickr client will also be generated if an api key is
290
+ # as authentication is no longer done this way.
291
+ # An associated flickr client will also be generated if an api key is
292
292
  # passed among the arguments or in the params hash. Alternatively, and
293
- # most likely, an existing client object may be passed in the params hash
293
+ # most likely, an existing client object may be passed in the params hash
294
294
  # (e.g. 'client' => some_existing_flickr_client_object), and this is
295
- # what happends when users are initlialized as the result of a method
295
+ # what happends when users are initlialized as the result of a method
296
296
  # called on the flickr client (e.g. flickr.users)
297
297
  def initialize(id_or_params_hash=nil, username=nil, email=nil, password=nil, api_key={})
298
298
  if id_or_params_hash.is_a?(Hash)
@@ -325,35 +325,35 @@ class Flickr
325
325
  def firstdatetaken
326
326
  @firstdatetaken.nil? ? getInfo.firstdatetaken : @firstdatetaken
327
327
  end
328
-
329
- # Builds url for user's photos page as per
328
+
329
+ # Builds url for user's photos page as per
330
330
  # http://www.flickr.com/services/api/misc.urls.html
331
331
  def photos_url
332
332
  "http://www.flickr.com/photos/#{id}/"
333
333
  end
334
-
335
- # Builds url for user's profile page as per
334
+
335
+ # Builds url for user's profile page as per
336
336
  # http://www.flickr.com/services/api/misc.urls.html
337
337
  def url
338
338
  "http://www.flickr.com/people/#{id}/"
339
339
  end
340
-
340
+
341
341
  def pretty_url
342
342
  @pretty_url ||= @client.urls_getUserProfile('user_id'=>@id)['user']['url']
343
343
  end
344
-
344
+
345
345
  # Implements flickr.people.getPublicGroups
346
346
  def groups
347
347
  collection = @client.people_getPublicGroups('user_id'=>@id)['groups']['group']
348
348
  collection = [collection] if collection.is_a? Hash
349
- collection.collect { |group| Group.new( "id" => group['nsid'],
349
+ collection.collect { |group| Group.new( "id" => group['nsid'],
350
350
  "name" => group['name'],
351
351
  "eighteenplus" => group['eighteenplus'],
352
352
  "client" => @client) }
353
353
  end
354
-
354
+
355
355
  # Implements flickr.people.getPublicPhotos. Options hash allows you to add
356
- # extra restrictions as per flickr.people.getPublicPhotos docs, e.g.
356
+ # extra restrictions as per flickr.people.getPublicPhotos docs, e.g.
357
357
  # user.photos('per_page' => '25', 'extras' => 'date_taken')
358
358
  def photos(options={})
359
359
  @client.photos_request('people.getPublicPhotos', {'user_id' => @id}.merge(options))
@@ -370,12 +370,12 @@ class Flickr
370
370
  @client.contacts_getPublicList('user_id'=>@id)['contacts']['contact'].collect { |contact| User.new(contact['nsid'], contact['username'], nil, nil, @api_key) }
371
371
  #or
372
372
  end
373
-
373
+
374
374
  # Implements flickr.favorites.getPublicList
375
375
  def favorites
376
376
  @client.photos_request('favorites.getPublicList', 'user_id' => @id)
377
377
  end
378
-
378
+
379
379
  # Implements flickr.photosets.getList
380
380
  def photosets
381
381
  @client.photosets_getList('user_id'=>@id)['photosets']['photoset'].collect { |photoset| Photoset.new(photoset['id'], @api_key) }
@@ -395,7 +395,7 @@ class Flickr
395
395
  def contactsPhotos
396
396
  @client.photos_request('photos.getContactsPublicPhotos', 'user_id' => @id)
397
397
  end
398
-
398
+
399
399
  def to_s
400
400
  @name
401
401
  end
@@ -426,22 +426,22 @@ class Flickr
426
426
  extra_params.each { |k,v| self.instance_variable_set("@#{k}", v) } # convert extra_params into instance variables
427
427
  @client = Flickr.new @api_key
428
428
  end
429
-
430
- # Allows access to all photos instance variables through hash like
431
- # interface, e.g. photo["datetaken"] returns @datetaken instance
429
+
430
+ # Allows access to all photos instance variables through hash like
431
+ # interface, e.g. photo["datetaken"] returns @datetaken instance
432
432
  # variable. Useful for accessing any weird and wonderful parameter
433
433
  # that may have been returned by Flickr when finding the photo,
434
- # e.g. those returned by the extras argument in
434
+ # e.g. those returned by the extras argument in
435
435
  # flickr.people.getPublicPhotos
436
436
  def [](param_name)
437
437
  instance_variable_get("@#{param_name}")
438
438
  end
439
-
439
+
440
440
  def title
441
441
  @title.nil? ? getInfo("title") : @title
442
442
  end
443
-
444
- # Returns the owner of the photo as a Flickr::User. If we have no info
443
+
444
+ # Returns the owner of the photo as a Flickr::User. If we have no info
445
445
  # about the owner, we make an API call to get it. If we already have
446
446
  # the owner's id, create a user based on that. Either way, we cache the
447
447
  # result so we don't need to check again
@@ -563,7 +563,7 @@ class Flickr
563
563
  # Implements flickr.photos.notes.add
564
564
  def add_note(note)
565
565
  end
566
-
566
+
567
567
  # Implements flickr.photos.setDates
568
568
  def dates=(dates)
569
569
  end
@@ -571,11 +571,11 @@ class Flickr
571
571
  # Implements flickr.photos.setPerms
572
572
  def perms=(perms)
573
573
  end
574
-
574
+
575
575
  # Implements flickr.photos.setTags
576
576
  def tags=(tags)
577
577
  end
578
-
578
+
579
579
  # Implements flickr.photos.setMeta
580
580
  def title=(title)
581
581
  end
@@ -585,7 +585,7 @@ class Flickr
585
585
  # Implements flickr.photos.addTags
586
586
  def add_tag(tag)
587
587
  end
588
-
588
+
589
589
  # Implements flickr.photos.removeTag
590
590
  def remove_tag(tag)
591
591
  end
@@ -606,12 +606,12 @@ class Flickr
606
606
  # Implements flickr.photos.notes.edit
607
607
  def editNote(note_id)
608
608
  end
609
-
609
+
610
610
  # Converts the Photo to a string by returning its title
611
611
  def to_s
612
612
  title
613
613
  end
614
-
614
+
615
615
  private
616
616
 
617
617
  # Implements flickr.photos.getInfo
@@ -626,10 +626,10 @@ class Flickr
626
626
  @url = info['urls']['url']['content'] # assumes only one url
627
627
  instance_variable_get("@#{attrib}")
628
628
  end
629
-
630
- # Builds source uri of image from params (often returned from other
631
- # methods, e.g. User#photos). As specified at:
632
- # http://www.flickr.com/services/api/misc.urls.html. If size is given
629
+
630
+ # Builds source uri of image from params (often returned from other
631
+ # methods, e.g. User#photos). As specified at:
632
+ # http://www.flickr.com/services/api/misc.urls.html. If size is given
633
633
  # should be one the keys in the VALID_SIZES hash, i.e.
634
634
  # "Square", "Thumbnail", "Medium", "Large", "Original", "Small" (These
635
635
  # are the values returned by flickr.photos.getSizes).
@@ -646,8 +646,8 @@ class Flickr
646
646
  "http://farm#{@farm}.static.flickr.com/#{@server}/#{@id}_#{@secret}_#{s_size}.jpg"
647
647
  end
648
648
  end
649
-
650
- # Builds uri of Flickr page for photo. By default returns the main
649
+
650
+ # Builds uri of Flickr page for photo. By default returns the main
651
651
  # page for the photo, but if passed a size will return the simplified
652
652
  # flickr page featuring the given size of the photo
653
653
  # TODO: Handle "Original" size
@@ -668,13 +668,13 @@ class Flickr
668
668
  # flickr.groups.pools.remove
669
669
  class Group
670
670
  attr_reader :id, :client, :description, :name, :eighteenplus, :members, :online, :privacy, :url#, :chatid, :chatcount
671
-
671
+
672
672
  def initialize(id_or_params_hash=nil, api_key={})
673
673
  if id_or_params_hash.is_a?(Hash)
674
674
  id_or_params_hash.each { |k,v| self.instance_variable_set("@#{k}", v) } # convert extra_params into instance variables
675
675
  else
676
676
  @id = id_or_params_hash
677
- @api_key = api_key
677
+ @api_key = api_key
678
678
  @client = Flickr.new @api_key
679
679
  end
680
680
  end
@@ -724,11 +724,11 @@ class Flickr
724
724
  @url = "http://www.flickr.com/photos/#{@owner.getInfo.username}/sets/#{@id}/"
725
725
  self
726
726
  end
727
-
727
+
728
728
  def getPhotos
729
- photosetPhotos = @client.photos_request('photosets.getPhotos', {'photoset_id' => @id})
729
+ photosetPhotos = @client.photos_request('photosets.getPhotos', {'photoset_id' => @id}, "photoset")
730
730
  end
731
731
 
732
732
  end
733
-
733
+
734
734
  end