dustin-r2flickr 0.1.1.6 → 0.1.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README +12 -4
- data/examples/album_test.rb +2 -2
- data/examples/loadr.rb +24 -24
- data/examples/relatedness.rb +52 -52
- data/examples/setdumpr.rb +18 -18
- data/lib/flickr/auth.rb +52 -53
- data/lib/flickr/base.rb +734 -736
- data/lib/flickr/blogs.rb +22 -22
- data/lib/flickr/favorites.rb +55 -55
- data/lib/flickr/groups.rb +67 -66
- data/lib/flickr/interestingness.rb +15 -15
- data/lib/flickr/licenses.rb +19 -19
- data/lib/flickr/notes.rb +18 -18
- data/lib/flickr/people.rb +64 -64
- data/lib/flickr/photos.rb +262 -259
- data/lib/flickr/photosets.rb +87 -89
- data/lib/flickr/pools.rb +62 -59
- data/lib/flickr/reflection.rb +76 -76
- data/lib/flickr/tags.rb +49 -49
- data/lib/flickr/test.rb +15 -14
- data/lib/flickr/token_cache.rb +20 -20
- data/lib/flickr/transform.rb +7 -5
- data/lib/flickr/upload.rb +186 -186
- data/lib/flickr/urls.rb +41 -40
- metadata +1 -1
data/lib/flickr/photos.rb
CHANGED
@@ -1,290 +1,293 @@
|
|
1
1
|
require 'flickr/base'
|
2
2
|
|
3
3
|
begin
|
4
|
-
|
5
|
-
|
4
|
+
# Did not exist in 1.8.6
|
5
|
+
StopIteration
|
6
6
|
rescue NameError
|
7
|
-
|
8
|
-
|
7
|
+
class StopIteration < Exception
|
8
|
+
end
|
9
9
|
end
|
10
10
|
|
11
11
|
class Flickr::Photos < Flickr::APIBase
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def upload
|
13
|
+
require 'flickr/upload'
|
14
|
+
@upload ||= Flickr::Upload.new(@flickr)
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def licenses
|
18
|
+
require 'flickr/licenses'
|
19
|
+
@licenses ||= Flickr::Licenses.new(@flickr)
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
def notes
|
23
|
+
require 'flickr/notes'
|
24
|
+
@notes ||= Flickr::Notes.new(@flickr)
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def transform
|
28
|
+
require 'flickr/transform'
|
29
|
+
@transform ||= Flickr::Transform.new(@flickr)
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
# photo can be a Photo or a photo id
|
33
|
+
# tags is an array of tags
|
34
|
+
def addTags(photo,tags)
|
35
|
+
photo = photo.id if photo.class == Flickr::Photo
|
36
|
+
tstr = tags.join(',')
|
37
|
+
@flickr.call_method('flickr.photos.addTags',
|
38
|
+
'photo_id' => photo, 'tags' => tstr)
|
39
|
+
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
def removeTag(tag)
|
42
|
+
tag = tag.id if tag.class == Flickr::Tag
|
43
|
+
@flickr.call_method('flickr.photos.removeTag', 'tag_id' => tag)
|
44
|
+
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
def setTags(tags)
|
47
|
+
tags=tags.map{|t| (t.class == Flickr::Tag) ? t.id : t}.join(' ')
|
48
|
+
photo = photo.id if photo.class == Flickr::Photo
|
49
|
+
@flickr.call_method('flickr.photos.setTags',
|
50
|
+
'photo_id' => photo, 'tags' => tags)
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
# photo can be a Photo or photo id string/number
|
54
|
+
def delete(photo)
|
55
|
+
photo = photo.id if photo.class == Flickr::Photo
|
56
|
+
res = @flickr.call_method('flickr.photos.delete',
|
57
|
+
'photo_id'=>photo)
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
60
|
+
# photo can be a Photo or photo id string/number
|
61
|
+
def getAllContexts(photo)
|
62
|
+
photo = photo.id if photo.class == Flickr::Photo
|
63
|
+
res @flickr.call_method('flickr.photos.getAllContexts',
|
64
|
+
'photo_id'=>photo)
|
65
|
+
list = []
|
66
|
+
res.each_element('set') do |set|
|
67
|
+
att = set.attributes
|
68
|
+
psid = att['id']
|
69
|
+
set = @flickr.photoset_cache_lookup(psid) ||
|
70
|
+
Flickr::PhotoSet.new(att['id'],@flickr)
|
71
|
+
set.title = att['title']
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
73
|
+
@flickr.photoset_cache_store(set)
|
74
|
+
list << set
|
75
|
+
end
|
76
|
+
res.each_element('pool') do |set|
|
77
|
+
att = set.attributes
|
78
|
+
ppid = att['id']
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
80
|
+
p = @flickr.photopool_cache_lookup(ppid) ||
|
81
|
+
Flickr::PhotoPool.new(ppid,@flickr)
|
82
|
+
p.title = att['title']
|
83
|
+
@flickr.photopool_cache_store(ppid)
|
84
|
+
list << p
|
85
|
+
end
|
86
|
+
return list
|
87
|
+
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
89
|
+
def getPerms(photo)
|
90
|
+
photo = photo.id if photo.class == Flickr::Photo
|
91
|
+
res = @flickr.call_method('flickr.photos.getPerms',
|
92
|
+
'photo_id' => photo)
|
93
|
+
perms = res.elements['/perms']
|
94
|
+
att = perms.attributes
|
95
|
+
phid = att['id']
|
96
|
+
photo = (photo.class == Flickr::Photo) ? photo :
|
97
|
+
(@flickr.photo_cache_lookup(phid) ||
|
98
|
+
Flickr::Photo.new(@flickr,phid))
|
99
|
+
photo.ispublic = (att['ispublic'].to_i == 1)
|
100
|
+
photo.isfriend = (att['isfriend'].to_i == 1)
|
101
|
+
photo.isfamily = (att['isfamily'].to_i == 1)
|
102
|
+
photo.permcomment = att['permcomment'].to_i
|
103
|
+
photo.permaddmeta = att['permaddmeta'].to_i
|
104
|
+
return photo
|
105
|
+
end
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
107
|
+
def setPerms(photo,is_public,is_friend,is_family,perm_comment,
|
108
|
+
perm_addmeta)
|
109
|
+
photo = photo.id if photo.class == Flickr::Photo
|
110
|
+
args = {
|
111
|
+
'photo_id' => photo,
|
112
|
+
'is_public' => (is_public == true || is_public == 1) ? 1 : 0,
|
113
|
+
'is_friend' => (is_friend == true || is_friend == 1) ? 1 : 0,
|
114
|
+
'is_family' => (is_family == true || is_family == 1) ? 1 : 0,
|
115
|
+
'perm_comment' => perm_comment,
|
116
|
+
'perm_addmeta' => perm_addmeta
|
117
|
+
}
|
118
|
+
res = @flickr.call_method('flickr.photos.setPerms',args)
|
119
|
+
end
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
121
|
+
def getContactsPhotos(count=nil,just_friends=nil,single_photo=nil,
|
122
|
+
include_self=nil)
|
123
|
+
args = {}
|
124
|
+
args['count'] = count if count
|
125
|
+
args['just_friends'] = just_friends ? '1' : '0' if
|
126
|
+
just_friends != nil
|
127
|
+
args['single_photo'] = single_photo ? '1' : '0' if
|
128
|
+
single_photo != nil
|
129
|
+
args['include_self'] = include_self ? '1' : '0' if
|
130
|
+
include_self != nil
|
131
|
+
res= @flickr.call_method('flickr.photos.getContactsPhotos',args)
|
132
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
133
|
+
end
|
134
134
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
135
|
+
# Person can be a string nsid or anything that responds to the
|
136
|
+
# nsid method.
|
137
|
+
def getContactsPublicPhotos(user, count=nil,just_friends=nil,
|
138
|
+
single_photo=nil, include_self=nil)
|
139
|
+
user = user.nsid if user.respond_to?(:nsid)
|
140
|
+
args = {}
|
141
|
+
args['count'] = count if count
|
142
|
+
args['user_id'] = user
|
143
|
+
args['just_friends'] = just_friends ? '1' : '0' if
|
144
|
+
just_friends != nil
|
145
|
+
args['single_photo'] = single_photo ? '1' : '0' if
|
146
|
+
single_photo != nil
|
147
|
+
args['include_self'] = include_self ? '1' : '0' if
|
148
|
+
include_self != nil
|
149
|
+
res=@flickr.call_method('flickr.photos.getContactsPublicPhotos',
|
150
|
+
args)
|
151
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
152
|
+
end
|
153
153
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
154
|
+
def getContext(photo)
|
155
|
+
photo = photo.id if photo.class == Flickr::Photo
|
156
|
+
res = @flickr.call_method('flickr.photos.getContext',
|
157
|
+
'photo_id' => photo)
|
158
|
+
return Flickr::Context.from_xml(res)
|
159
|
+
end
|
160
160
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
161
|
+
def getCounts(dates=nil,taken_dates=nil)
|
162
|
+
args = {}
|
163
|
+
args['dates'] = dates.map{|d| d.to_i}.join(',') if dates
|
164
|
+
args['taken_dates'] = taken_dates.map{|d| d.to_i}.join(',') if
|
165
|
+
taken_dates
|
166
|
+
res = @flickr.call_method('flickr.photos.getCounts',args)
|
167
|
+
list = []
|
168
|
+
res.elements['/photocounts'].each_element('photocount') do |el|
|
169
|
+
list << Flickr::Count.from_xml(el)
|
170
|
+
end
|
171
|
+
return list
|
172
|
+
end
|
173
173
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
174
|
+
def getExif(photo,secret = nil)
|
175
|
+
photo = photo.id if photo.class == Flickr::Photo
|
176
|
+
args = {'photo_id' => photo}
|
177
|
+
args['secret'] = secret if secret
|
178
|
+
res = @flickr.call_method('flickr.photos.getExif',args)
|
179
|
+
return Flickr::Photo.from_xml(res.elements['/photo'],@flickr)
|
180
|
+
end
|
181
181
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
def getNotInSet(extras=nil,per_page = nil, page = nil)
|
191
|
-
args = {}
|
192
|
-
extras = extras.join(',') if extras.class == Array
|
193
|
-
args['extras'] = extras if extras
|
194
|
-
args['per_page'] = per_page if per_page
|
195
|
-
args['page'] = page if page
|
196
|
-
res = @flickr.call_method('flickr.photos.getNotInSet',args)
|
197
|
-
return Flickr::PhotoList.from_xml(res,@flickr)
|
198
|
-
end
|
199
|
-
|
200
|
-
def getRecent(extras=nil,per_page = nil, page = nil)
|
201
|
-
args = {}
|
202
|
-
extras = extras.join(',') if extras.class == Array
|
203
|
-
args['extras'] = extras if extras
|
204
|
-
args['per_page'] = per_page if per_page
|
205
|
-
args['page'] = page if page
|
206
|
-
res = @flickr.call_method('flickr.photos.getRecent',args)
|
207
|
-
return Flickr::PhotoList.from_xml(res,@flickr)
|
208
|
-
end
|
209
|
-
|
210
|
-
def getUntagged(extras=nil,per_page = nil, page = nil)
|
211
|
-
args = {}
|
212
|
-
extras = extras.join(',') if extras.class == Array
|
213
|
-
args['extras'] = extras if extras
|
214
|
-
args['per_page'] = per_page if per_page
|
215
|
-
args['page'] = page if page
|
216
|
-
res = @flickr.call_method('flickr.photos.getUntagged',args)
|
217
|
-
return Flickr::PhotoList.from_xml(res,@flickr)
|
218
|
-
end
|
182
|
+
def getInfo(photo,secret = nil)
|
183
|
+
photo = (photo.class == Flickr::Photo) ? photo.id : photo
|
184
|
+
args= {'photo_id' => photo}
|
185
|
+
args['secret'] = secret if secret
|
186
|
+
res = @flickr.call_method('flickr.photos.getInfo',args)
|
187
|
+
return Flickr::Photo.from_xml(res.elements['photo'],@flickr)
|
188
|
+
end
|
219
189
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
size = Flickr::Size.from_xml(el)
|
230
|
-
photo.sizes[size.label.intern] = size
|
231
|
-
end
|
232
|
-
@flickr.photo_cache_store(photo)
|
233
|
-
return photo
|
234
|
-
end
|
190
|
+
def getNotInSet(extras=nil,per_page = nil, page = nil)
|
191
|
+
args = {}
|
192
|
+
extras = extras.join(',') if extras.class == Array
|
193
|
+
args['extras'] = extras if extras
|
194
|
+
args['per_page'] = per_page if per_page
|
195
|
+
args['page'] = page if page
|
196
|
+
res = @flickr.call_method('flickr.photos.getNotInSet',args)
|
197
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
198
|
+
end
|
235
199
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
args['date_taken_granularity'] = date_taken_granularity if
|
246
|
-
date_taken_granularity
|
247
|
-
@flickr.call_method('flickr.photos.setDates',args)
|
248
|
-
end
|
200
|
+
def getRecent(extras=nil,per_page = nil, page = nil)
|
201
|
+
args = {}
|
202
|
+
extras = extras.join(',') if extras.class == Array
|
203
|
+
args['extras'] = extras if extras
|
204
|
+
args['per_page'] = per_page if per_page
|
205
|
+
args['page'] = page if page
|
206
|
+
res = @flickr.call_method('flickr.photos.getRecent',args)
|
207
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
208
|
+
end
|
249
209
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
210
|
+
def getUntagged(extras=nil,per_page = nil, page = nil)
|
211
|
+
args = {}
|
212
|
+
extras = extras.join(',') if extras.class == Array
|
213
|
+
args['extras'] = extras if extras
|
214
|
+
args['per_page'] = per_page if per_page
|
215
|
+
args['page'] = page if page
|
216
|
+
res = @flickr.call_method('flickr.photos.getUntagged',args)
|
217
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
218
|
+
end
|
257
219
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
220
|
+
def getSizes(photo)
|
221
|
+
photo_id = (photo.class == Flickr::Photo) ? photo.id : photo
|
222
|
+
photo = (photo.class == Flickr::Photo) ? photo :
|
223
|
+
(@flickr.photo_cache_lookup(photo_id) ||
|
224
|
+
Flickr::Photo.new(@flickr,photo_id))
|
225
|
+
res = @flickr.call_method('flickr.photos.getSizes',
|
226
|
+
'photo_id' => photo_id )
|
227
|
+
photo.sizes = {}
|
228
|
+
res.elements['/sizes'].each_element do |el|
|
229
|
+
size = Flickr::Size.from_xml(el)
|
230
|
+
photo.sizes[size.label.intern] = size
|
231
|
+
end
|
232
|
+
@flickr.photo_cache_store(photo)
|
233
|
+
return photo
|
234
|
+
end
|
270
235
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
236
|
+
def setDates(photo,date_posted=nil,date_taken=nil,
|
237
|
+
date_taken_granularity=nil)
|
238
|
+
photo = photo.id if photo.class == Flickr::Photo
|
239
|
+
date_posted = date_posted.to_i if date_posted.class == Time
|
240
|
+
date_taken = @flickr.mysql_datetime(date_taken) if
|
241
|
+
date_taken.class == Time
|
242
|
+
args = {'photo_id' => photo}
|
243
|
+
args['date_posted'] = date_posted if date_posted
|
244
|
+
args['date_taken'] = date_taken if date_taken
|
245
|
+
args['date_taken_granularity'] = date_taken_granularity if
|
246
|
+
date_taken_granularity
|
247
|
+
@flickr.call_method('flickr.photos.setDates',args)
|
248
|
+
end
|
249
|
+
|
250
|
+
def setMeta(photo,title,description)
|
251
|
+
photo = photo.id if photo.class == Flickr::Photo
|
252
|
+
args = {'photo_id' => photo,
|
253
|
+
'title' => title,
|
254
|
+
'description' => description}
|
255
|
+
@flickr.call_method('flickr.photos.setMeta',args)
|
256
|
+
end
|
257
|
+
|
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
|
+
|
262
|
+
[:min_upload_date, :max_upload_date].each do |k|
|
263
|
+
args[k] = args[k].to_i if args[k].is_a? Time
|
264
|
+
end
|
265
|
+
|
266
|
+
[:min_taken_date, :max_taken_date].each do |k|
|
267
|
+
args[k] = @flickr.mysql_datetime(args[k]) if args[k].is_a? Time
|
268
|
+
end
|
269
|
+
|
270
|
+
args[:license] = args[:license].id if args[:license].is_a? Flickr::License
|
271
|
+
args[:extras] = args[:extras].join(',') if args[:extras].is_a? Array
|
272
|
+
args.each {|k,v| v = args.delete(k); args[k.to_s] = v}
|
273
|
+
|
274
|
+
if block_given?
|
275
|
+
thispage = 1
|
276
|
+
maxpages = 2
|
277
|
+
args['per_page'] ||= 500
|
278
|
+
until thispage > maxpages do
|
279
|
+
args['page'] = thispage
|
280
|
+
res = @flickr.call_method('flickr.photos.search',args)
|
281
|
+
list = Flickr::PhotoList.from_xml(res, @flickr)
|
282
|
+
maxpages = list.pages
|
283
|
+
list.each {|p| yield p}
|
284
|
+
thispage += 1
|
285
|
+
end
|
286
|
+
else
|
287
|
+
res = @flickr.call_method('flickr.photos.search',args)
|
288
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
289
|
+
end
|
290
|
+
rescue StopIteration
|
291
|
+
nil
|
292
|
+
end
|
290
293
|
end
|