flickrie 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/README.md +1 -1
  2. data/lib/flickrie.rb +18 -92
  3. data/lib/flickrie/api_methods.rb +759 -11
  4. data/lib/flickrie/base58.rb +15 -0
  5. data/lib/flickrie/callable.rb +78 -0
  6. data/lib/flickrie/client.rb +25 -17
  7. data/lib/flickrie/instance.rb +10 -15
  8. data/lib/flickrie/middleware.rb +4 -21
  9. data/lib/flickrie/middleware/fix_flickr_data.rb +215 -0
  10. data/lib/flickrie/middleware/retry.rb +23 -0
  11. data/lib/flickrie/{license.rb → objects/license.rb} +0 -0
  12. data/lib/flickrie/{location.rb → objects/location.rb} +13 -13
  13. data/lib/flickrie/{media.rb → objects/media.rb} +30 -25
  14. data/lib/flickrie/{media → objects/media}/exif.rb +0 -0
  15. data/lib/flickrie/{media → objects/media}/note.rb +11 -12
  16. data/lib/flickrie/{media → objects/media}/tag.rb +10 -9
  17. data/lib/flickrie/objects/media/visibility.rb +28 -0
  18. data/lib/flickrie/objects/media_context.rb +17 -0
  19. data/lib/flickrie/objects/media_count.rb +46 -0
  20. data/lib/flickrie/{photo.rb → objects/photo.rb} +2 -3
  21. data/lib/flickrie/{set.rb → objects/set.rb} +9 -30
  22. data/lib/flickrie/{ticket.rb → objects/ticket.rb} +0 -0
  23. data/lib/flickrie/{user.rb → objects/user.rb} +10 -50
  24. data/lib/flickrie/{user → objects/user}/upload_status.rb +0 -0
  25. data/lib/flickrie/{video.rb → objects/video.rb} +3 -4
  26. data/lib/flickrie/version.rb +1 -1
  27. metadata +38 -37
  28. data/lib/flickrie/api_methods/media.rb +0 -698
  29. data/lib/flickrie/api_methods/set.rb +0 -23
  30. data/lib/flickrie/api_methods/user.rb +0 -45
  31. data/lib/flickrie/media/class_methods.rb +0 -217
  32. data/lib/flickrie/media/visibility.rb +0 -29
  33. data/lib/flickrie/media_count.rb +0 -54
data/README.md CHANGED
@@ -6,7 +6,7 @@ This gem is a nice wrapper for the Flickr API with an object-oriented interface.
6
6
 
7
7
  - GitHub page: [https://github.com/janko-m/flickrie](https://github.com/janko-m/flickrie)
8
8
 
9
- - Documentation: [http://rubydoc.info/github/janko-m/flickrie](http://rubydoc.info/github/janko-m/flickrie/)
9
+ - Documentation: [http://rubydoc.info/github/janko-m/flickrie/master](http://rubydoc.info/github/janko-m/flickrie/master)
10
10
 
11
11
  - Wiki: [https://github.com/janko-m/flickrie/wiki](https://github.com/janko-m/flickrie/wiki)
12
12
 
@@ -1,7 +1,4 @@
1
- require 'flickrie/client'
2
- require 'flickrie/upload_client'
3
- require 'flickrie/middleware'
4
- require 'faraday_middleware'
1
+ require 'flickrie/callable'
5
2
 
6
3
  module Flickrie
7
4
  DEFAULTS = {
@@ -85,6 +82,8 @@ module Flickrie
85
82
  # @see Flickrie::Collection
86
83
  attr_accessor :pagination
87
84
 
85
+ # This is basically `attr_writer` with resetting the client. This is because client is cached,
86
+ # so it wouldn't pick up the attribute being set. This is mainly for the console.
88
87
  [
89
88
  :api_key, :shared_secret, :timeout,
90
89
  :open_timeout, :access_token, :access_secret
@@ -96,83 +95,7 @@ module Flickrie
96
95
  end
97
96
  end
98
97
 
99
- # This is for manual use (for example, if I haven't covered something yet, and you really need it).
100
- # Here's an example:
101
- #
102
- # response = Flickrie.client.get "flickr.photos.getInfo", :photo_id => 8423943
103
- # response.body['photo']['id'] # => 8423943
104
- # response.body['photo']['description'] # => "..."
105
- #
106
- # Flickrie.client.post "flickr.photos.licenses.setLicense", :photo_id => 1241497, :license_id => 2
107
- #
108
- # For the full list of available API methods, see [this page](http://www.flickr.com/services/api/).
109
- #
110
- # @return [HTTP response] A Faraday HTTP response
111
- def client
112
- @client ||= new_client
113
- end
114
-
115
- # @private
116
- def new_client(access_token = {})
117
- params = {
118
- :url => 'http://api.flickr.com/services/rest',
119
- :params => {
120
- :format => 'json',
121
- :nojsoncallback => '1',
122
- :api_key => api_key
123
- },
124
- :request => {
125
- :open_timeout => open_timeout || DEFAULTS[:open_timeout],
126
- :timeout => timeout || DEFAULTS[:timeout]
127
- }
128
- }
129
-
130
- Client.new(params) do |b|
131
- b.use Middleware::Retry
132
- b.use FaradayMiddleware::OAuth,
133
- :consumer_key => api_key,
134
- :consumer_secret => shared_secret,
135
- :token => access_token[:token] || self.access_token,
136
- :token_secret => access_token[:secret] || self.access_secret
137
-
138
- b.use Middleware::StatusCheck
139
- b.use FaradayMiddleware::ParseJson
140
- b.use Middleware::OAuthCheck
141
-
142
- b.adapter :net_http
143
- end
144
- end
145
-
146
- # @private
147
- def upload_client
148
- @upload_client ||= new_upload_client
149
- end
150
-
151
- # @private
152
- def new_upload_client(access_token = {})
153
- params = {
154
- :url => 'http://api.flickr.com/services',
155
- :request => {
156
- :open_timeout => open_timeout || DEFAULTS[:open_timeout]
157
- }
158
- }
159
-
160
- UploadClient.new(params) do |b|
161
- b.use Middleware::Retry
162
- b.use FaradayMiddleware::OAuth,
163
- :consumer_key => api_key,
164
- :consumer_secret => shared_secret,
165
- :token => access_token[:token] || self.access_token,
166
- :token_secret => access_token[:secret] || self.access_secret
167
- b.request :multipart
168
-
169
- b.use Middleware::UploadStatusCheck
170
- b.use FaradayMiddleware::ParseXml
171
- b.use Middleware::OAuthCheck
172
-
173
- b.adapter :net_http
174
- end
175
- end
98
+ include Callable
176
99
  end
177
100
  end
178
101
 
@@ -180,17 +103,20 @@ require 'flickrie/api_methods'
180
103
  require 'flickrie/core_ext'
181
104
 
182
105
  module Flickrie
183
- autoload :Collection, 'flickrie/collection'
184
- autoload :License, 'flickrie/license'
185
- autoload :User, 'flickrie/user'
186
- autoload :Media, 'flickrie/media'
187
- autoload :Photo, 'flickrie/photo'
188
- autoload :Video, 'flickrie/video'
189
- autoload :Set, 'flickrie/set'
190
- autoload :MediaCount, 'flickrie/media_count'
191
- autoload :Ticket, 'flickrie/ticket'
192
- autoload :Instance, 'flickrie/instance'
193
- autoload :OAuth, 'flickrie/oauth'
106
+ autoload :License, 'flickrie/objects/license'
107
+ autoload :User, 'flickrie/objects/user'
108
+ autoload :Media, 'flickrie/objects/media'
109
+ autoload :Photo, 'flickrie/objects/photo'
110
+ autoload :Video, 'flickrie/objects/video'
111
+ autoload :Set, 'flickrie/objects/set'
112
+ autoload :MediaCount, 'flickrie/objects/media_count'
113
+ autoload :MediaContext, 'flickrie/objects/media_context'
114
+ autoload :Ticket, 'flickrie/objects/ticket'
115
+
116
+ autoload :Collection, 'flickrie/collection'
117
+ autoload :Instance, 'flickrie/instance'
118
+ autoload :OAuth, 'flickrie/oauth'
119
+ autoload :Base58, 'flickrie/base58'
194
120
 
195
121
  extend ApiMethods
196
122
  end
@@ -1,7 +1,3 @@
1
- require 'flickrie/api_methods/media'
2
- require 'flickrie/api_methods/user'
3
- require 'flickrie/api_methods/set'
4
-
5
1
  module Flickrie
6
2
  module ApiMethods
7
3
  # For uploading photos and videos to Flickr. Example:
@@ -50,6 +46,718 @@ module Flickrie
50
46
  end
51
47
  end
52
48
 
49
+ # Fetches the Flickr user with the given email.
50
+ #
51
+ # @param email [String]
52
+ # @return [Flickrie::User]
53
+ # @api_method [flickr.people.findByEmail](http://www.flickr.com/services/api/flickr.people.findByEmail.html)
54
+ def find_user_by_email(email, params = {})
55
+ response = client.find_user_by_email(email, params)
56
+ User.new(response.body['user'], self)
57
+ end
58
+
59
+ # Fetches the Flickr user with the given username.
60
+ #
61
+ # @param username [String]
62
+ # @return [Flickrie::User]
63
+ # @api_method [flickr.people.findByUsername](http://www.flickr.com/services/api/flickr.people.findByUsername.html)
64
+ def find_user_by_username(username, params = {})
65
+ response = client.find_user_by_username(username, params)
66
+ User.new(response.body['user'], self)
67
+ end
68
+
69
+ # Fetches photos and videos from the Flickr user with the given NSID.
70
+ #
71
+ # @param nsid [String]
72
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
73
+ # @api_method [flickr.people.getPhotos](http://www.flickr.com/services/api/flickr.people.getPhotos.html)
74
+ #
75
+ # @note This method requires authentication with "read" permissions.
76
+ def media_from_user(nsid, params = {})
77
+ response = client.media_from_user(nsid, params)
78
+ Media.new_collection(response.body['photos'], self)
79
+ end
80
+ # Fetches photos from the Flickr user with the given NSID.
81
+ #
82
+ # @param nsid [String]
83
+ # @return [Flickrie::Collection<Flickrie::Photo>]
84
+ # @api_method [flickr.people.getPhotos](http://www.flickr.com/services/api/flickr.people.getPhotos.html)
85
+ #
86
+ # @note This method requires authentication with "read" permissions.
87
+ def photos_from_user(nsid, params = {})
88
+ media_from_user(nsid, params).select { |media| media.is_a?(Photo) }
89
+ end
90
+ # Fetches videos from the Flickr user with the given NSID.
91
+ #
92
+ # @param nsid [String]
93
+ # @return [Flickrie::Collection<Flickrie::Video>]
94
+ # @api_method [flickr.people.getPhotos](http://www.flickr.com/services/api/flickr.people.getPhotos.html)
95
+ #
96
+ # @note This method requires authentication with "read" permissions.
97
+ def videos_from_user(nsid, params = {})
98
+ media_from_user(nsid, params).select { |media| media.is_a?(Video) }
99
+ end
100
+
101
+ # Fetches photos and videos containing a Flickr user with the given NSID.
102
+ #
103
+ # @param nsid [String]
104
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
105
+ # @api_method [flickr.people.getPhotosOf](http://www.flickr.com/services/api/flickr.people.getPhotosOf.html)
106
+ def media_of_user(nsid, params = {})
107
+ response = client.media_of_user(nsid, params)
108
+ Media.new_collection(response.body['photos'], self)
109
+ end
110
+ # Fetches photos containing a Flickr user with the given NSID.
111
+ #
112
+ # @param nsid [String]
113
+ # @return [Flickrie::Collection<Flickrie::Photo>]
114
+ # @api_method [flickr.people.getPhotosOf](http://www.flickr.com/services/api/flickr.people.getPhotosOf.html)
115
+ def photos_of_user(nsid, params = {})
116
+ media_of_user(nsid, params).select { |media| media.is_a?(Photo) }
117
+ end
118
+ # Fetches videos containing a Flickr user with the given NSID.
119
+ #
120
+ # @param nsid [String]
121
+ # @return [Flickrie::Collection<Flickrie::Video>]
122
+ # @api_method [flickr.people.getPhotosOf](http://www.flickr.com/services/api/flickr.people.getPhotosOf.html)
123
+ def videos_of_user(nsid, params = {})
124
+ media_of_user(nsid, params).select { |media| media.is_a?(Video) }
125
+ end
126
+
127
+ # Fetches public photos and videos from the Flickr user with the given
128
+ # NSID.
129
+ #
130
+ # @param nsid [String]
131
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
132
+ # @api_method [flickr.people.getPublicPhotos](http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html)
133
+ def public_media_from_user(nsid, params = {})
134
+ response = client.public_media_from_user(nsid, params)
135
+ Media.new_collection(response.body['photos'], self)
136
+ end
137
+ # Fetches public photos from the Flickr user with the given NSID.
138
+ #
139
+ # @param nsid [String]
140
+ # @return [Flickrie::Collection<Flickrie::Photo>]
141
+ # @api_method [flickr.people.getPublicPhotos](http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html)
142
+ def public_photos_from_user(nsid, params = {})
143
+ public_media_from_user(nsid, params).select { |media| media.is_a?(Photo) }
144
+ end
145
+ # Fetches public videos from the Flickr user with the given NSID.
146
+ #
147
+ # @param nsid [String]
148
+ # @return [Flickrie::Collection<Flickrie::Video>]
149
+ # @api_method [flickr.people.getPublicPhotos](http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html)
150
+ def public_videos_from_user(nsid, params = {})
151
+ public_media_from_user(nsid, params).select { |media| media.is_a?(Video) }
152
+ end
153
+
154
+ # Fetches the Flickr user with the given NSID.
155
+ #
156
+ # @param nsid [String]
157
+ # @return [Flickrie::User]
158
+ # @api_method [flickr.people.getInfo](http://www.flickr.com/services/api/flickr.people.getInfo.html)
159
+ def get_user_info(nsid, params = {})
160
+ response = client.get_user_info(nsid, params)
161
+ User.new(response.body['person'], self)
162
+ end
163
+
164
+ # Returns the upload status of the user who is currently authenticated.
165
+ #
166
+ # @return [Flickrie::User]
167
+ # @api_method [flickr.people.getUploadStatus](http://www.flickr.com/services/api/flickr.people.getUploadStatus.html)
168
+ # @see Flickrie::User#upload_status
169
+ #
170
+ # @note This method requires authentication with "read" permissions.
171
+ def get_upload_status(params = {})
172
+ response = client.get_upload_status(params)
173
+ User.new(response.body['user'], self)
174
+ end
175
+
176
+ # Add tags to the photo/video with the given ID.
177
+ #
178
+ # @param media_id [String, Fixnum]
179
+ # @param tags [String] A space delimited string with tags
180
+ # @return [nil]
181
+ # @api_method [flickr.photos.addTags](http://www.flickr.com/services/api/flickr.photos.addTags.html)
182
+ #
183
+ # @note This method requires authentication with "write" permissions.
184
+ def add_media_tags(media_id, tags, params = {})
185
+ client.add_media_tags(media_id, tags, params)
186
+ nil
187
+ end
188
+ alias add_photo_tags add_media_tags
189
+ alias add_video_tags add_media_tags
190
+
191
+ # Deletes the photo/video with the given ID.
192
+ #
193
+ # @param media_id [String, Fixnum]
194
+ # @return [nil]
195
+ # @api_method [flickr.photos.delete](http://www.flickr.com/services/api/flickr.photos.delete.html)
196
+ #
197
+ # @note This method requires authentication with "delete" permissions.
198
+ def delete_media(media_id, params = {})
199
+ client.delete_media(media_id, params)
200
+ nil
201
+ end
202
+ alias delete_photo delete_media
203
+ alias delete_video delete_media
204
+
205
+ # Fetches photos and videos from contacts of the user who authenticated.
206
+ #
207
+ # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
208
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
209
+ # @api_method [flickr.photos.getContactsPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html)
210
+ #
211
+ # @note This method requires authentication with "read" permissions.
212
+ def media_from_contacts(params = {})
213
+ response = client.media_from_contacts(params)
214
+ Media.new_collection(response.body['photos'], self)
215
+ end
216
+ # Fetches photos from contacts of the user who authenticated.
217
+ #
218
+ # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
219
+ # @return [Flickrie::Collection<Flickrie::Photo>]
220
+ # @api_method [flickr.photos.getContactsPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html)
221
+ #
222
+ # @note This method requires authentication with "read" permissions.
223
+ def photos_from_contacts(params = {})
224
+ media_from_contacts(params).select { |media| media.is_a?(Photo) }
225
+ end
226
+ # Fetches videos from contacts of the user who authenticated.
227
+ #
228
+ # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
229
+ # @return [Flickrie::Collection<Flickrie::Video>]
230
+ # @api_method [flickr.photos.getContactsPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html)
231
+ #
232
+ # @note This method requires authentication with "read" permissions.
233
+ def videos_from_contacts(params = {})
234
+ media_from_contacts(params).select { |media| media.is_a?(Video) }
235
+ end
236
+
237
+ # Fetches public photos and videos from contacts of the user with the
238
+ # given NSID.
239
+ #
240
+ # @param nsid [String]
241
+ # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
242
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
243
+ # @api_method [flickr.photos.getContactsPublicPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html)
244
+ def public_media_from_user_contacts(nsid, params = {})
245
+ response = client.public_media_from_user_contacts(nsid, params)
246
+ Media.new_collection(response.body['photos'], self)
247
+ end
248
+ # Fetches public photos from contacts of the user with the
249
+ # given NSID.
250
+ #
251
+ # @param nsid [String]
252
+ # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
253
+ # @return [Flickrie::Collection<Flickrie::Photo>]
254
+ # @api_method [flickr.photos.getContactsPublicPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html)
255
+ def public_photos_from_user_contacts(nsid, params = {})
256
+ public_media_from_user_contacts(nsid, params).
257
+ select { |media| media.is_a?(Photo) }
258
+ end
259
+ # Fetches public videos from contacts of the user with the
260
+ # given NSID.
261
+ #
262
+ # @param nsid [String]
263
+ # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
264
+ # @return [Flickrie::Collection<Flickrie::Video>]
265
+ # @api_method [flickr.photos.getContactsPublicPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html)
266
+ def public_videos_from_user_contacts(nsid, params = {})
267
+ public_media_from_user_contacts(nsid, params).
268
+ select { |media| media.is_a?(Video) }
269
+ end
270
+
271
+ # Fetches context of the photo/video with the given ID. Example:
272
+ #
273
+ # context = Flickrie.get_photo_context(37124234)
274
+ # context.count # => 23
275
+ # context.previous # => #<Photo: id=2433240, ...>
276
+ # context.next # => #<Video: id=1282404, ...>
277
+ #
278
+ # @param media_id [String, Fixnum]
279
+ # @return [Struct]
280
+ # @api_method [flickr.photos.getContext](http://www.flickr.com/services/api/flickr.photos.getContext.html)
281
+ def get_media_context(media_id, params = {})
282
+ response = client.get_media_context(media_id, params)
283
+ MediaContext.new(response.body, self)
284
+ end
285
+ alias get_photo_context get_media_context
286
+ alias get_video_context get_media_context
287
+
288
+ # Fetches numbers of photos and videos for given date ranges. Example:
289
+ #
290
+ # require 'date'
291
+ # dates = [DateTime.parse("3rd Jan 2011").to_time, DateTime.parse("11th Aug 2011").to_time]
292
+ # counts = Flickrie.get_media_counts(:taken_dates => dates.map(&:to_i).join(','))
293
+ #
294
+ # count = counts.first
295
+ # count.value # => 24
296
+ # count.date_range # => 2011-01-03 01:00:00 +0100..2011-08-11 02:00:00 +0200
297
+ # count.date_range.begin # => 2011-01-03 01:00:00 +0100
298
+ # count.from # => 2011-01-03 01:00:00 +0100
299
+ #
300
+ # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
301
+ # @return [Flickrie::MediaCount]
302
+ # @api_method [flickr.photos.getCounts](http://www.flickr.com/services/api/flickr.photos.getCounts.html)
303
+ def get_media_counts(params = {})
304
+ response = client.get_media_counts(params)
305
+ MediaCount.new_collection(response.body['photocounts'])
306
+ end
307
+ alias get_photos_counts get_media_counts
308
+ alias get_videos_counts get_media_counts
309
+
310
+ # Fetches the exif for the photo with the given ID. Example:
311
+ #
312
+ # photo = Flickrie.get_photo_exif(27234987)
313
+ # photo.exif.get('Model') # => 'Canon PowerShot G12'
314
+ #
315
+ # photo.exif.get('X-Resolution', :data => 'raw') # => '180'
316
+ # photo.exif.get('X-Resolution', :data => 'clean') # => '180 dpi'
317
+ # photo.exif.get('X-Resolution') # => '180 dpi'
318
+ #
319
+ # @param photo_id [String, Fixnum]
320
+ # @return [Flickrie::Photo]
321
+ # @api_method [flickr.photos.getExif](http://www.flickr.com/services/api/flickr.photos.getExif.html)
322
+ def get_photo_exif(photo_id, params = {})
323
+ response = client.get_media_exif(photo_id, params)
324
+ Photo.new(response.body['photo'], self)
325
+ end
326
+ # Fetches the exif for the video with the given ID. Example:
327
+ #
328
+ # video = Flickrie.get_video_exif(27234987)
329
+ # video.exif.get('Model') # => 'Canon PowerShot G12'
330
+ #
331
+ # video.exif.get('X-Resolution', :data => 'raw') # => '180'
332
+ # video.exif.get('X-Resolution', :data => 'clean') # => '180 dpi'
333
+ # video.exif.get('X-Resolution') # => '180 dpi'
334
+ #
335
+ # @param video_id [String, Fixnum]
336
+ # @return [Flickrie::Video]
337
+ # @api_method [flickr.photos.getExif](http://www.flickr.com/services/api/flickr.photos.getExif.html)
338
+ def get_video_exif(video_id, params = {})
339
+ response = client.get_media_exif(video_id, params)
340
+ Video.new(response.body['photo'], self)
341
+ end
342
+
343
+ # Fetches the list of users who favorited the photo with the given ID.
344
+ # Example:
345
+ #
346
+ # photo = Flickrie.get_photo_favorites(24810948)
347
+ # photo.favorites.first.username # => "John Smith"
348
+ #
349
+ # @param photo_id [String, Fixnum]
350
+ # @return [Flickrie::Photo]
351
+ # @api_method [flickr.photos.getFavorites](http://www.flickr.com/services/api/flickr.photos.getFavorites.html)
352
+ def get_photo_favorites(photo_id, params = {})
353
+ response = client.get_media_favorites(photo_id, params)
354
+ Photo.new(response.body['photo'], self)
355
+ end
356
+ # Fetches the list of users who favorited the video with the given ID.
357
+ # Example:
358
+ #
359
+ # video = Flickrie.get_video_favorites(24810948)
360
+ # video.favorites.first.username # => "John Smith"
361
+ #
362
+ # @param video_id [String, Fixnum]
363
+ # @return [Flickrie::Video]
364
+ # @api_method [flickr.photos.getFavorites](http://www.flickr.com/services/api/flickr.photos.getFavorites.html)
365
+ def get_video_favorites(video_id, params = {})
366
+ response = client.get_media_favorites(video_id, params)
367
+ Video.new(response.body['photo'], self)
368
+ end
369
+
370
+ # Fetches info of the photo/video with the given ID.
371
+ #
372
+ # @param media_id [String, Fixnum]
373
+ # @return [Flickrie::Photo, Flickrie::Video]
374
+ # @api_method [flickr.photos.getInfo](http://www.flickr.com/services/api/flickr.photos.getInfo.html)
375
+ def get_media_info(media_id, params = {})
376
+ response = client.get_media_info(media_id, params)
377
+ Media.new(response.body['photo'], self)
378
+ end
379
+ alias get_photo_info get_media_info
380
+ alias get_video_info get_media_info
381
+
382
+ # Fetches photos and videos from the authenticated user
383
+ # that are not in any set.
384
+ #
385
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
386
+ # @api_method [flickr.photos.getNotInSet](http://www.flickr.com/services/api/flickr.photos.getNotInSet.html)
387
+ #
388
+ # @note This method requires authentication with "read" permissions.
389
+ def media_not_in_set(params = {})
390
+ response = client.media_not_in_set({:media => 'all'}.merge(params))
391
+ Media.new_collection(response.body['photos'], self)
392
+ end
393
+ # Fetches photos from the authenticated user
394
+ # that are not in any set.
395
+ #
396
+ # @return [Flickrie::Collection<Flickrie::Photo>]
397
+ # @api_method [flickr.photos.getNotInSet](http://www.flickr.com/services/api/flickr.photos.getNotInSet.html)
398
+ #
399
+ # @note This method requires authentication with "read" permissions.
400
+ def photos_not_in_set(params = {})
401
+ media_not_in_set({:media => "photos"}.merge(params))
402
+ end
403
+ # Fetches videos from the authenticated user
404
+ # that are not in any set.
405
+ #
406
+ # @return [Flickrie::Collection<Flickrie::Video>]
407
+ # @api_method [flickr.photos.getNotInSet](http://www.flickr.com/services/api/flickr.photos.getNotInSet.html)
408
+ #
409
+ # @note This method requires authentication with "read" permissions.
410
+ def videos_not_in_set(params = {})
411
+ media_not_in_set({:media => "videos"}.merge(params))
412
+ end
413
+
414
+ # Gets permissions of a photo with the given ID.
415
+ #
416
+ # @return [Flickrie::Photo]
417
+ # @api_method [flickr.photos.getPerms](http://www.flickr.com/services/api/flickr.photos.getPerms.html)
418
+ #
419
+ # @note This method requires authentication with "read" permissions.
420
+ def get_photo_permissions(photo_id, params = {})
421
+ response = client.get_media_permissions(photo_id, params)
422
+ Photo.new(response.body['perms'], self)
423
+ end
424
+ # Gets permissions of a video with the given ID.
425
+ #
426
+ # @return [Flickrie::Video]
427
+ # @api_method [flickr.photos.getPerms](http://www.flickr.com/services/api/flickr.photos.getPerms.html)
428
+ #
429
+ # @note This method requires authentication with "read" permissions.
430
+ def get_video_permissions(video_id, params = {})
431
+ response = client.get_media_permissions(video_id, params)
432
+ Video.new(response.body['perms'], self)
433
+ end
434
+
435
+ # Fetches the latest photos and videos uploaded to Flickr.
436
+ #
437
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
438
+ # @api_method [flickr.photos.getRecent](http://www.flickr.com/services/api/flickr.photos.getRecent.html)
439
+ def get_recent_media(params = {})
440
+ response = client.get_recent_media(params)
441
+ Media.new_collection(response.body['photos'], self)
442
+ end
443
+ # Fetches the latest photos uploaded to Flickr.
444
+ #
445
+ # @return [Flickrie::Collection<Flickrie::Photo>]
446
+ # @api_method [flickr.photos.getRecent](http://www.flickr.com/services/api/flickr.photos.getRecent.html)
447
+ def get_recent_photos(params = {})
448
+ get_recent_media(params).select { |media| media.is_a?(Photo) }
449
+ end
450
+ # Fetches the latest videos uploaded to Flickr.
451
+ #
452
+ # @return [Flickrie::Collection<Flickrie::Video>]
453
+ # @api_method [flickr.photos.getRecent](http://www.flickr.com/services/api/flickr.photos.getRecent.html)
454
+ def get_recent_videos(params = {})
455
+ get_recent_media(params).select { |media| media.is_a?(Video) }
456
+ end
457
+
458
+ # Fetches the sizes of the photo with the given ID. Example:
459
+ #
460
+ # photo = Flickrie.get_photo_sizes(242348)
461
+ # photo.medium!(500)
462
+ # photo.size # => "Medium 500"
463
+ # photo.source_url # => "http://farm8.staticflickr.com/7090/7093101501_9337f28800.jpg"
464
+ #
465
+ # @param photo_id [String, Fixnum]
466
+ # @return [Flickrie::Photo]
467
+ # @api_method [flickr.photos.getSizes](http://www.flickr.com/services/api/flickr.photos.getSizes.html)
468
+ def get_photo_sizes(photo_id, params = {})
469
+ response = client.get_media_sizes(photo_id, params)
470
+ Photo.new(response.body['sizes'], self)
471
+ end
472
+ # Fetches the sizes of the video with the given ID. Example:
473
+ #
474
+ # video = Flickrie.get_video_sizes(438492)
475
+ # video.download_url # => "..."
476
+ #
477
+ # @param video_id [String, Fixnum]
478
+ # @return [Flickrie::Video]
479
+ # @api_method [flickr.photos.getSizes](http://www.flickr.com/services/api/flickr.photos.getSizes.html)
480
+ def get_video_sizes(video_id, params = {})
481
+ response = client.get_media_sizes(video_id, params)
482
+ Video.new(response.body['sizes'], self)
483
+ end
484
+
485
+ # Fetches photos and videos from the authenticated user that have no
486
+ # tags.
487
+ #
488
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
489
+ # @api_method [flickr.photos.getUntagged](http://www.flickr.com/services/api/flickr.photos.getUntagged.html)
490
+ #
491
+ # @note This method requires authentication with "read" permissions.
492
+ def get_untagged_media(params = {})
493
+ response = client.get_untagged_media({:media => 'all'}.merge(params))
494
+ Media.new_collection(response.body['photos'], self)
495
+ end
496
+ # Fetches photos from the authenticated user that have no tags.
497
+ #
498
+ # @return [Flickrie::Collection<Flickrie::Photo>]
499
+ # @api_method [flickr.photos.getUntagged](http://www.flickr.com/services/api/flickr.photos.getUntagged.html)
500
+ #
501
+ # @note This method requires authentication with "read" permissions.
502
+ def get_untagged_photos(params = {})
503
+ get_untagged_media({:media => 'photos'}.merge(params))
504
+ end
505
+ # Fetches videos from the authenticated user that have no tags.
506
+ #
507
+ # @return [Flickrie::Collection<Flickrie::Video>]
508
+ # @api_method [flickr.photos.getUntagged](http://www.flickr.com/services/api/flickr.photos.getUntagged.html)
509
+ #
510
+ # @note This method requires authentication with "read" permissions.
511
+ def get_untagged_videos(params = {})
512
+ get_untagged_media({:media => 'videos'}.merge(params))
513
+ end
514
+
515
+ # Fetches geo-tagged photos and videos from the authenticated user.
516
+ #
517
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
518
+ # @api_method [flickr.photos.getWithGeoData](http://www.flickr.com/services/api/flickr.photos.getWithGeoData.html)
519
+ #
520
+ # @note This method requires authentication with "read" permissions.
521
+ def get_media_with_geo_data(params = {})
522
+ response = client.get_media_with_geo_data({:media => 'all'}.merge(params))
523
+ Media.new_collection(response.body['photos'], self)
524
+ end
525
+ # Fetches geo-tagged photos from the authenticated user.
526
+ #
527
+ # @return [Flickrie::Collection<Flickrie::Photo>]
528
+ # @api_method [flickr.photos.getWithGeoData](http://www.flickr.com/services/api/flickr.photos.getWithGeoData.html)
529
+ #
530
+ # @note This method requires authentication with "read" permissions.
531
+ def get_photos_with_geo_data(params = {})
532
+ get_media_with_geo_data({:media => 'photos'}.merge(params))
533
+ end
534
+ # Fetches geo-tagged videos from the authenticated user.
535
+ #
536
+ # @return [Flickrie::Collection<Flickrie::Video>]
537
+ # @api_method [flickr.photos.getWithGeoData](http://www.flickr.com/services/api/flickr.photos.getWithGeoData.html)
538
+ #
539
+ # @note This method requires authentication with "read" permissions.
540
+ def get_videos_with_geo_data(params = {})
541
+ get_media_with_geo_data({:media => 'videos'}.merge(params))
542
+ end
543
+
544
+ # Fetches photos and videos from the authenticated user that are not
545
+ # geo-tagged.
546
+ #
547
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
548
+ # @api_method [flickr.photos.getWithoutGeoData](http://www.flickr.com/services/api/flickr.photos.getWithoutGeoData.html)
549
+ #
550
+ # @note This method requires authentication with "read" permissions.
551
+ def get_media_without_geo_data(params = {})
552
+ response = client.get_media_with_geo_data({:media => 'all'}.merge(params))
553
+ Media.new_collection(response.body['photos'], self)
554
+ end
555
+ # Fetches photos from the authenticated user that are not geo-tagged.
556
+ #
557
+ # @return [Flickrie::Collection<Flickrie::Photo>]
558
+ # @api_method [flickr.photos.getWithoutGeoData](http://www.flickr.com/services/api/flickr.photos.getWithoutGeoData.html)
559
+ #
560
+ # @note This method requires authentication with "read" permissions.
561
+ def get_photos_without_geo_data(params = {})
562
+ get_media_with_geo_data({:media => 'photos'}.merge(params))
563
+ end
564
+ # Fetches videos from the authenticated user that are not geo-tagged.
565
+ #
566
+ # @return [Flickrie::Collection<Flickrie::Video>]
567
+ # @api_method [flickr.photos.getWithoutGeoData](http://www.flickr.com/services/api/flickr.photos.getWithoutGeoData.html)
568
+ #
569
+ # @note This method requires authentication with "read" permissions.
570
+ def get_videos_without_geo_data(params = {})
571
+ get_media_with_geo_data({:media => 'videos'}.merge(params))
572
+ end
573
+
574
+ # Fetches photos and videos from the authenticated user that have
575
+ # recently been updated.
576
+ #
577
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
578
+ # @api_method [flickr.photos.recentlyUpdated](http://www.flickr.com/services/api/flickr.photos.recentlyUpdated.html)
579
+ #
580
+ # @note This method requires authentication with "read" permissions.
581
+ def recently_updated_media(params = {})
582
+ response = client.recently_updated_media(params)
583
+ Media.new_collection(response.body['photos'], self)
584
+ end
585
+ # Fetches photos from the authenticated user that have recently been updated.
586
+ #
587
+ # @return [Flickrie::Collection<Flickrie::Photo>]
588
+ # @api_method [flickr.photos.recentlyUpdated](http://www.flickr.com/services/api/flickr.photos.recentlyUpdated.html)
589
+ #
590
+ # @note This method requires authentication with "read" permissions.
591
+ def recently_updated_photos(params = {})
592
+ recently_updated_media(params).select { |media| media.is_a?(Photo) }
593
+ end
594
+ # Fetches videos from the authenticated user that have recently been updated.
595
+ #
596
+ # @return [Flickrie::Collection<Flickrie::Video>]
597
+ # @api_method [flickr.photos.recentlyUpdated](http://www.flickr.com/services/api/flickr.photos.recentlyUpdated.html)
598
+ #
599
+ # @note This method requires authentication with "read" permissions.
600
+ def recently_updated_videos(params = {})
601
+ recently_updated_media(params).select { |media| media.is_a?(Video) }
602
+ end
603
+
604
+ # Remove the tag with the given ID
605
+ #
606
+ # @param tag_id [String]
607
+ # @return [nil]
608
+ # @api_method [flickr.photos.removeTag](http://www.flickr.com/services/api/flickr.photos.removeTag.html)
609
+ #
610
+ # @note This method requires authentication with "write" permissions.
611
+ def remove_media_tag(tag_id, params = {})
612
+ client.remove_media_tag(tag_id, params)
613
+ nil
614
+ end
615
+ alias remove_photo_tag remove_media_tag
616
+ alias remove_video_tag remove_media_tag
617
+
618
+ # Fetches photos and videos matching a certain criteria.
619
+ #
620
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
621
+ # @api_method [flickr.photos.search](http://www.flickr.com/services/api/flickr.photos.search.html)
622
+ def search_media(params = {})
623
+ response = client.search_media({:media => 'all'}.merge(params))
624
+ Media.new_collection(response.body['photos'], self)
625
+ end
626
+ # Fetches photos matching a certain criteria.
627
+ #
628
+ # @return [Flickrie::Collection<Flickrie::Photo>]
629
+ # @api_method [flickr.photos.search](http://www.flickr.com/services/api/flickr.photos.search.html)
630
+ def search_photos(params = {})
631
+ search_media({:media => 'photos'}.merge(params))
632
+ end
633
+ # Fetches videos matching a certain criteria.
634
+ #
635
+ # @return [Flickrie::Collection<Flickrie::Video>]
636
+ # @api_method [flickr.photos.search](http://www.flickr.com/services/api/flickr.photos.search.html)
637
+ def search_videos(params = {})
638
+ search_media({:media => 'videos'}.merge(params))
639
+ end
640
+
641
+ # Sets the content type of a photo/video.
642
+ #
643
+ # @param media_id [String, Fixnum]
644
+ # @param content_type [String, Fixnum]
645
+ # @return [nil]
646
+ # @api_method [flickr.photos.setContentType](http://www.flickr.com/services/api/flickr.photos.setContentType.html)
647
+ #
648
+ # @note This method requires authentication with "write" permissions.
649
+ def set_media_content_type(media_id, content_type, params = {})
650
+ client.set_media_content_type(media_id, content_type, params)
651
+ nil
652
+ end
653
+ alias set_photo_content_type set_media_content_type
654
+ alias set_video_content_type set_media_content_type
655
+
656
+ # Sets dates for a photo/video.
657
+ #
658
+ # @param media_id [String, Fixnum]
659
+ # @return [nil]
660
+ # @api_method [flickr.photos.setDates](http://www.flickr.com/services/api/flickr.photos.setDates.html)
661
+ #
662
+ # @note This method requires authentication with "write" permissions.
663
+ def set_media_dates(media_id, params = {})
664
+ client.set_media_dates(media_id, params)
665
+ nil
666
+ end
667
+ alias set_photo_dates set_media_dates
668
+ alias set_video_dates set_media_dates
669
+
670
+ # Sets meta information for a photo/video.
671
+ #
672
+ # @param media_id [String, Fixnum]
673
+ # @return [nil]
674
+ # @api_method [flickr.photos.setMeta](http://www.flickr.com/services/api/flickr.photos.setMeta.html)
675
+ #
676
+ # @note This method requires authentication with "write" permissions.
677
+ def set_media_meta(media_id, params = {})
678
+ client.set_media_meta(media_id, params)
679
+ nil
680
+ end
681
+ alias set_photo_meta set_media_meta
682
+ alias set_video_meta set_media_meta
683
+
684
+ # Sets permissions for a photo/video.
685
+ #
686
+ # @param media_id [String, Fixnum]
687
+ # @return [nil]
688
+ # @api_method [flickr.photos.setPerms](http://www.flickr.com/services/api/flickr.photos.setPerms.html)
689
+ #
690
+ # @note This method requires authentication with "write" permissions.
691
+ def set_media_permissions(media_id, params = {})
692
+ client.set_media_permissions(media_id, params)
693
+ nil
694
+ end
695
+ alias set_photo_permissions set_media_permissions
696
+ alias set_video_permissions set_media_permissions
697
+
698
+ # Sets the safety level of a photo/video.
699
+ #
700
+ # @param media_id [String, Fixnum]
701
+ # @return [nil]
702
+ # @api_method [flickr.photos.setSafetyLevel](http://www.flickr.com/services/api/flickr.photos.setSafetyLevel.html)
703
+ #
704
+ # @note This method requires authentication with "write" permissions.
705
+ def set_media_safety_level(media_id, params = {})
706
+ client.set_media_safety_level(media_id, params)
707
+ nil
708
+ end
709
+ alias set_photo_safety_level set_media_safety_level
710
+ alias set_video_safety_level set_media_safety_level
711
+
712
+ # Sets tags for a photo/video.
713
+ #
714
+ # @param media_id [String, Fixnum]
715
+ # @return [nil]
716
+ # @api_method [flickr.photos.setTags](http://www.flickr.com/services/api/flickr.photos.setTags.html)
717
+ #
718
+ # @note This method requires authentication with "write" permissions.
719
+ def set_media_tags(media_id, tags, params = {})
720
+ client.set_media_tags(media_id, tags, params)
721
+ nil
722
+ end
723
+ alias set_photo_tags set_media_tags
724
+ alias set_video_tags set_media_tags
725
+
726
+ # Fetches all available types of licenses.
727
+ #
728
+ # @return [Array<Flickrie::License>]
729
+ # @api_method [flickr.photos.licenses.getInfo](http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html)
730
+ def get_licenses(params = {})
731
+ response = client.get_licenses(params)
732
+ License.from_hash(response.body['licenses']['license'])
733
+ end
734
+
735
+ # Sets the license of a photo/video.
736
+ #
737
+ # @return [nil]
738
+ # @api_method [flickr.photos.licenses.setLicense](http://www.flickr.com/services/api/flickr.photos.licenses.setLicense.html)
739
+ #
740
+ # @note This method requires authentication with "write" permissions.
741
+ def set_media_license(media_id, license_id, params = {})
742
+ client.set_media_license(media_id, license_id, params)
743
+ nil
744
+ end
745
+ alias set_photo_license set_media_license
746
+ alias set_video_license set_media_license
747
+
748
+ # Rotates a photo/video.
749
+ #
750
+ # @return [nil]
751
+ # @api_method [flickr.photos.transform.rotate](http://www.flickr.com/services/api/flickr.photos.transform.rotate.html)
752
+ #
753
+ # @note This method requires authentication with "write" permissions.
754
+ def rotate_media(media_id, degrees, params = {})
755
+ client.rotate_media(media_id, degrees, params)
756
+ nil
757
+ end
758
+ alias rotate_photo rotate_media
759
+ alias rotate_video rotate_media
760
+
53
761
  # Fetches upload tickets with given IDs. Example:
54
762
  #
55
763
  # photo = File.open("...")
@@ -71,13 +779,53 @@ module Flickrie
71
779
  map { |info| Ticket.new(info) }
72
780
  end
73
781
 
74
- # Fetches all available types of licenses.
782
+ # Fetches information about the set with the given ID.
75
783
  #
76
- # @return [Array<Flickrie::License>]
77
- # @api_method [flickr.photos.licenses.getInfo](http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html)
78
- def get_licenses(params = {})
79
- response = client.get_licenses(params)
80
- License.from_hash(response.body['licenses']['license'])
784
+ # @param set_id [String, Fixnum]
785
+ # @return [Flickrie::Set]
786
+ # @api_method [flickr.photosets.getInfo](http://www.flickr.com/services/api/flickr.photosets.getInfo.html)
787
+ def get_set_info(set_id, params = {})
788
+ response = client.get_set_info(set_id, params)
789
+ Set.new(response.body['photoset'], self)
790
+ end
791
+
792
+ # Fetches sets from a user with the given NSID.
793
+ #
794
+ # @param nsid [String]
795
+ # @return [Flickrie::Collection<Flickrie::Set>]
796
+ # @api_method [flickr.photosets.getList](http://www.flickr.com/services/api/flickr.photosets.getList.html)
797
+ def sets_from_user(nsid, params = {})
798
+ response = client.sets_from_user(nsid, params)
799
+ Set.new_collection(response.body['photosets'], self)
800
+ end
801
+
802
+ # Fetches photos and videos from a set with the given ID.
803
+ #
804
+ # @param set_id [String]
805
+ # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
806
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
807
+ # @api_method [flickr.photosets.getPhotos](http://www.flickr.com/services/api/flickr.photosets.getPhotos.html)
808
+ def media_from_set(set_id, params = {})
809
+ response = client.media_from_set(set_id, {:media => 'all'}.merge(params))
810
+ Media.new_collection(response.body['photoset'], self)
811
+ end
812
+ # Fetches photos from a set with the given ID.
813
+ #
814
+ # @param set_id [String]
815
+ # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
816
+ # @return [Flickrie::Collection<Flickrie::Photo>]
817
+ # @api_method [flickr.photosets.getPhotos](http://www.flickr.com/services/api/flickr.photosets.getPhotos.html)
818
+ def photos_from_set(set_id, params = {})
819
+ media_from_set(set_id, {:media => 'photos'}.merge(params))
820
+ end
821
+ # Fetches videos from a set with the given ID.
822
+ #
823
+ # @param set_id [String]
824
+ # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
825
+ # @return [Flickrie::Collection<Flickrie::Video>]
826
+ # @api_method [flickr.photosets.getPhotos](http://www.flickr.com/services/api/flickr.photosets.getPhotos.html)
827
+ def videos_from_set(set_id, params = {})
828
+ media_from_set(set_id, {:media => 'videos'}.merge(params))
81
829
  end
82
830
 
83
831
  # Tests if the authentication was successful. If it was, it
@@ -89,7 +837,7 @@ module Flickrie
89
837
  # @note This method requires authentication with "read" permissions.
90
838
  def test_login(params = {})
91
839
  response = client.test_login(params)
92
- User.from_test(response.body['user'])
840
+ User.new(response.body['user'], self)
93
841
  end
94
842
  end
95
843
  end