markoa-r2flickr 0.1.1.4 → 0.1.1.6
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.
- data/lib/flickr/photos.rb +39 -34
- metadata +1 -1
data/lib/flickr/photos.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
require 'flickr/base'
|
2
2
|
|
3
|
+
begin
|
4
|
+
# Did not exist in 1.8.6
|
5
|
+
StopIteration
|
6
|
+
rescue NameError
|
7
|
+
class StopIteration < Exception
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
class Flickr::Photos < Flickr::APIBase
|
4
12
|
def upload
|
5
13
|
require 'flickr/upload'
|
@@ -27,7 +35,7 @@ class Flickr::Photos < Flickr::APIBase
|
|
27
35
|
photo = photo.id if photo.class == Flickr::Photo
|
28
36
|
tstr = tags.join(',')
|
29
37
|
@flickr.call_method('flickr.photos.addTags',
|
30
|
-
'
|
38
|
+
'photo_id' => photo, 'tags' => tstr)
|
31
39
|
end
|
32
40
|
|
33
41
|
def removeTag(tag)
|
@@ -247,39 +255,36 @@ class Flickr::Photos < Flickr::APIBase
|
|
247
255
|
@flickr.call_method('flickr.photos.setMeta',args)
|
248
256
|
end
|
249
257
|
|
250
|
-
def search(
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
max_taken_date = @flickr.mysql_datetime(max_taken_date) if
|
263
|
-
max_taken_date.class == Time
|
264
|
-
license = license.id if license.class == Flickr::License
|
265
|
-
extras = extras.join(',') if extras.class == Array
|
266
|
-
|
267
|
-
args = {}
|
268
|
-
args['user_id'] = user if user
|
269
|
-
args['tags'] = tags if tags
|
270
|
-
args['tag_mode'] = tag_mode if tag_mode
|
271
|
-
args['text'] = text if text
|
272
|
-
args['min_upload_date'] = min_upload_date if min_upload_date
|
273
|
-
args['max_upload_date'] = max_upload_date if max_upload_date
|
274
|
-
args['min_taken_date'] = min_taken_date if min_taken_date
|
275
|
-
args['max_taken_date'] = max_taken_date if max_taken_date
|
276
|
-
args['license'] = license if license
|
277
|
-
args['extras'] = extras if extras
|
278
|
-
args['per_page'] = per_page if per_page
|
279
|
-
args['page'] = page if page
|
280
|
-
args['sort'] = sort if sort
|
258
|
+
def search(args)
|
259
|
+
args[:user_id] = args[:user_id].nsid if args[:user_id].respond_to?(:nsid)
|
260
|
+
args[:tags] = args[:tags].join(',') if args[:tags].class == Array
|
261
|
+
[:min_upload_date, :max_upload_date].each do |k|
|
262
|
+
args[k] = args[k].to_i if args[k].is_a? Time
|
263
|
+
end
|
264
|
+
[:min_taken_date, :max_taken_date].each do |k|
|
265
|
+
args[k] = @flickr.mysql_datetime(args[k]) if args[k].is_a? Time
|
266
|
+
end
|
267
|
+
args[:license] = args[:license].id if args[:license].is_a? Flickr::License
|
268
|
+
args[:extras] = args[:extras].join(',') if args[:extras].is_a? Array
|
269
|
+
args.each {|k,v| v = args.delete(k); args[k.to_s] = v}
|
281
270
|
|
282
|
-
|
283
|
-
|
271
|
+
if block_given?
|
272
|
+
thispage = 1
|
273
|
+
maxpages = 2
|
274
|
+
args['per_page'] ||= 500
|
275
|
+
until thispage > maxpages do
|
276
|
+
args['page'] = thispage
|
277
|
+
res = @flickr.call_method('flickr.photos.search',args)
|
278
|
+
list = Flickr::PhotoList.from_xml(res, @flickr)
|
279
|
+
maxpages = list.pages
|
280
|
+
list.each {|p| yield p}
|
281
|
+
thispage += 1
|
282
|
+
end
|
283
|
+
else
|
284
|
+
res = @flickr.call_method('flickr.photos.search',args)
|
285
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
286
|
+
end
|
287
|
+
rescue StopIteration
|
288
|
+
nil
|
284
289
|
end
|
285
290
|
end
|