digitalpardoe-rflickr 1.0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +22 -0
- data/lib/flickr.rb +39 -0
- data/lib/flickr/auth.rb +96 -0
- data/lib/flickr/base.rb +813 -0
- data/lib/flickr/blogs.rb +50 -0
- data/lib/flickr/contacts.rb +68 -0
- data/lib/flickr/favorites.rb +79 -0
- data/lib/flickr/groups.rb +102 -0
- data/lib/flickr/interestingness.rb +39 -0
- data/lib/flickr/licenses.rb +43 -0
- data/lib/flickr/notes.rb +44 -0
- data/lib/flickr/people.rb +99 -0
- data/lib/flickr/photos.rb +305 -0
- data/lib/flickr/photosets.rb +124 -0
- data/lib/flickr/pools.rb +90 -0
- data/lib/flickr/reflection.rb +109 -0
- data/lib/flickr/tags.rb +79 -0
- data/lib/flickr/transform.rb +29 -0
- data/lib/flickr/upload.rb +225 -0
- data/lib/flickr/urls.rb +69 -0
- metadata +73 -0
@@ -0,0 +1,305 @@
|
|
1
|
+
# rFlickr: A Ruby based Flickr API implementation.
|
2
|
+
# Copyright (C) 2009, Alex Pardoe (digital:pardoe)
|
3
|
+
#
|
4
|
+
# Derrived from work by Trevor Schroeder, see here:
|
5
|
+
# http://rubyforge.org/projects/rflickr/.
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU General Public License
|
9
|
+
# as published by the Free Software Foundation; either version 2
|
10
|
+
# of the License, or (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with this program; if not, write to the Free Software
|
19
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
20
|
+
|
21
|
+
require 'flickr/base'
|
22
|
+
|
23
|
+
class Flickr::Photos < Flickr::APIBase
|
24
|
+
def upload
|
25
|
+
require 'flickr/upload'
|
26
|
+
@upload ||= Flickr::Upload.new(@flickr)
|
27
|
+
end
|
28
|
+
|
29
|
+
def licenses
|
30
|
+
require 'flickr/licenses'
|
31
|
+
@licenses ||= Flickr::Licenses.new(@flickr)
|
32
|
+
end
|
33
|
+
|
34
|
+
def notes
|
35
|
+
require 'flickr/notes'
|
36
|
+
@notes ||= Flickr::Notes.new(@flickr)
|
37
|
+
end
|
38
|
+
|
39
|
+
def transform
|
40
|
+
require 'flickr/transform'
|
41
|
+
@transform ||= Flickr::Transform.new(@flickr)
|
42
|
+
end
|
43
|
+
|
44
|
+
# photo can be a Photo or a photo id
|
45
|
+
# tags is an array of tags
|
46
|
+
def addTags(photo,tags)
|
47
|
+
photo = photo.id if photo.class == Flickr::Photo
|
48
|
+
tstr = tags.join(',')
|
49
|
+
@flickr.call_method('flickr.photos.addTags',
|
50
|
+
'photo' => photo, 'tags' => tstr)
|
51
|
+
end
|
52
|
+
|
53
|
+
def removeTag(tag)
|
54
|
+
tag = tag.id if tag.class == Flickr::Tag
|
55
|
+
@flickr.call_method('flickr.photos.removeTag', 'tag_id' => tag)
|
56
|
+
end
|
57
|
+
|
58
|
+
def setTags(tags)
|
59
|
+
tags=tags.map{|t| (t.class == Flickr::Tag) ? t.id : t}.join(' ')
|
60
|
+
photo = photo.id if photo.class == Flickr::Photo
|
61
|
+
@flickr.call_method('flickr.photos.setTags',
|
62
|
+
'photo_id' => photo, 'tags' => tags)
|
63
|
+
end
|
64
|
+
|
65
|
+
# photo can be a Photo or photo id string/number
|
66
|
+
def delete(photo)
|
67
|
+
photo = photo.id if photo.class == Flickr::Photo
|
68
|
+
res = @flickr.call_method('flickr.photos.delete',
|
69
|
+
'photo_id'=>photo)
|
70
|
+
end
|
71
|
+
|
72
|
+
# photo can be a Photo or photo id string/number
|
73
|
+
def getAllContexts(photo)
|
74
|
+
photo = photo.id if photo.class == Flickr::Photo
|
75
|
+
res @flickr.call_method('flickr.photos.getAllContexts',
|
76
|
+
'photo_id'=>photo)
|
77
|
+
list = []
|
78
|
+
res.each_element('set') do |set|
|
79
|
+
att = set.attributes
|
80
|
+
psid = att['id']
|
81
|
+
set = @flickr.photoset_cache_lookup(psid) ||
|
82
|
+
Flickr::PhotoSet.new(att['id'],@flickr)
|
83
|
+
set.title = att['title']
|
84
|
+
|
85
|
+
@flickr.photoset_cache_store(set)
|
86
|
+
list << set
|
87
|
+
end
|
88
|
+
res.each_element('pool') do |set|
|
89
|
+
att = set.attributes
|
90
|
+
ppid = att['id']
|
91
|
+
|
92
|
+
p = @flickr.photopool_cache_lookup(ppid) ||
|
93
|
+
Flickr::PhotoPool.new(ppid,@flickr)
|
94
|
+
p.title = att['title']
|
95
|
+
@flickr.photopool_cache_store(ppid)
|
96
|
+
list << p
|
97
|
+
end
|
98
|
+
return list
|
99
|
+
end
|
100
|
+
|
101
|
+
def getPerms(photo)
|
102
|
+
photo = photo.id if photo.class == Flickr::Photo
|
103
|
+
res = @flickr.call_method('flickr.photos.getPerms',
|
104
|
+
'photo_id' => photo)
|
105
|
+
perms = res.elements['/perms']
|
106
|
+
att = perms.attributes
|
107
|
+
phid = att['id']
|
108
|
+
photo = (photo.class == Flickr::Photo) ? photo :
|
109
|
+
(@flickr.photo_cache_lookup(phid) ||
|
110
|
+
Flickr::Photo.new(@flickr,phid))
|
111
|
+
photo.ispublic = (att['ispublic'].to_i == 1)
|
112
|
+
photo.isfriend = (att['isfriend'].to_i == 1)
|
113
|
+
photo.isfamily = (att['isfamily'].to_i == 1)
|
114
|
+
photo.permcomment = att['permcomment'].to_i
|
115
|
+
photo.permaddmeta = att['permaddmeta'].to_i
|
116
|
+
return photo
|
117
|
+
end
|
118
|
+
|
119
|
+
def setPerms(photo,is_public,is_friend,is_family,perm_comment,
|
120
|
+
perm_addmeta)
|
121
|
+
photo = photo.id if photo.class == Flickr::Photo
|
122
|
+
args = {
|
123
|
+
'photo_id' => photo,
|
124
|
+
'is_public' => (is_public == true || is_public == 1) ? 1 : 0,
|
125
|
+
'is_friend' => (is_friend == true || is_friend == 1) ? 1 : 0,
|
126
|
+
'is_family' => (is_family == true || is_family == 1) ? 1 : 0,
|
127
|
+
'perm_comment' => perm_comment,
|
128
|
+
'perm_addmeta' => perm_addmeta
|
129
|
+
}
|
130
|
+
res = @flickr.call_method('flickr.photos.setPerms',args)
|
131
|
+
end
|
132
|
+
|
133
|
+
def getContactsPhotos(count=nil,just_friends=nil,single_photo=nil,
|
134
|
+
include_self=nil)
|
135
|
+
args = {}
|
136
|
+
args['count'] = count if count
|
137
|
+
args['just_friends'] = just_friends ? '1' : '0' if
|
138
|
+
just_friends != nil
|
139
|
+
args['single_photo'] = single_photo ? '1' : '0' if
|
140
|
+
single_photo != nil
|
141
|
+
args['include_self'] = include_self ? '1' : '0' if
|
142
|
+
include_self != nil
|
143
|
+
res= @flickr.call_method('flickr.photos.getContactsPhotos',args)
|
144
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Person can be a string nsid or anything that responds to the
|
148
|
+
# nsid method.
|
149
|
+
def getContactsPublicPhotos(user, count=nil,just_friends=nil,
|
150
|
+
single_photo=nil, include_self=nil)
|
151
|
+
user = user.nsid if user.respond_to?(:nsid)
|
152
|
+
args = {}
|
153
|
+
args['count'] = count if count
|
154
|
+
args['user_id'] = user
|
155
|
+
args['just_friends'] = just_friends ? '1' : '0' if
|
156
|
+
just_friends != nil
|
157
|
+
args['single_photo'] = single_photo ? '1' : '0' if
|
158
|
+
single_photo != nil
|
159
|
+
args['include_self'] = include_self ? '1' : '0' if
|
160
|
+
include_self != nil
|
161
|
+
res=@flickr.call_method('flickr.photos.getContactsPublicPhotos',
|
162
|
+
args)
|
163
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
164
|
+
end
|
165
|
+
|
166
|
+
def getContext(photo)
|
167
|
+
photo = photo.id if photo.class == Flickr::Photo
|
168
|
+
res = @flickr.call_method('flickr.photos.getContext',
|
169
|
+
'photo_id' => photo)
|
170
|
+
return Flickr::Context.from_xml(res)
|
171
|
+
end
|
172
|
+
|
173
|
+
def getCounts(dates=nil,taken_dates=nil)
|
174
|
+
args = {}
|
175
|
+
args['dates'] = dates.map{|d| d.to_i}.join(',') if dates
|
176
|
+
args['taken_dates'] = taken_dates.map{|d| d.to_i}.join(',') if
|
177
|
+
taken_dates
|
178
|
+
res = @flickr.call_method('flickr.photos.getCounts',args)
|
179
|
+
list = []
|
180
|
+
res.elements['/photocounts'].each_element('photocount') do |el|
|
181
|
+
list << Flickr::Count.from_xml(el)
|
182
|
+
end
|
183
|
+
return list
|
184
|
+
end
|
185
|
+
|
186
|
+
def getExif(photo,secret = nil)
|
187
|
+
photo = photo.id if photo.class == Flickr::Photo
|
188
|
+
args = {'photo_id' => photo}
|
189
|
+
args['secret'] = secret if secret
|
190
|
+
res = @flickr.call_method('flickr.photos.getExif',args)
|
191
|
+
return Flickr::Photo.from_xml(res.elements['/photo'],@flickr)
|
192
|
+
end
|
193
|
+
|
194
|
+
def getInfo(photo,secret = nil)
|
195
|
+
photo = (photo.class == Flickr::Photo) ? photo.id : photo
|
196
|
+
args= {'photo_id' => photo}
|
197
|
+
args['secret'] = secret if secret
|
198
|
+
res = @flickr.call_method('flickr.photos.getInfo',args)
|
199
|
+
return Flickr::Photo.from_xml(res.elements['photo'],@flickr)
|
200
|
+
end
|
201
|
+
|
202
|
+
def getNotInSet(extras=nil,per_page = nil, page = nil)
|
203
|
+
args = {}
|
204
|
+
extras = extras.join(',') if extras.class == Array
|
205
|
+
args['extras'] = extras if extras
|
206
|
+
args['per_page'] = per_page if per_page
|
207
|
+
args['page'] = page if page
|
208
|
+
res = @flickr.call_method('flickr.photos.getNotInSet',args)
|
209
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
210
|
+
end
|
211
|
+
|
212
|
+
def getRecent(extras=nil,per_page = nil, page = nil)
|
213
|
+
args = {}
|
214
|
+
extras = extras.join(',') if extras.class == Array
|
215
|
+
args['extras'] = extras if extras
|
216
|
+
args['per_page'] = per_page if per_page
|
217
|
+
args['page'] = page if page
|
218
|
+
res = @flickr.call_method('flickr.photos.getRecent',args)
|
219
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
220
|
+
end
|
221
|
+
|
222
|
+
def getUntagged(extras=nil,per_page = nil, page = nil)
|
223
|
+
args = {}
|
224
|
+
extras = extras.join(',') if extras.class == Array
|
225
|
+
args['extras'] = extras if extras
|
226
|
+
args['per_page'] = per_page if per_page
|
227
|
+
args['page'] = page if page
|
228
|
+
res = @flickr.call_method('flickr.photos.getUntagged',args)
|
229
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
230
|
+
end
|
231
|
+
|
232
|
+
def getSizes(photo)
|
233
|
+
photo_id = (photo.class == Flickr::Photo) ? photo.id : photo
|
234
|
+
photo = (photo.class == Flickr::Photo) ? photo :
|
235
|
+
(@flickr.photo_cache_lookup(photo_id) ||
|
236
|
+
Flickr::Photo.new(@flickr,photo_id))
|
237
|
+
res = @flickr.call_method('flickr.photos.getSizes',
|
238
|
+
'photo_id' => photo_id )
|
239
|
+
photo.sizes = {}
|
240
|
+
res.elements['/sizes'].each_element do |el|
|
241
|
+
size = Flickr::Size.from_xml(el)
|
242
|
+
photo.sizes[size.label.intern] = size
|
243
|
+
end
|
244
|
+
@flickr.photo_cache_store(photo)
|
245
|
+
return photo
|
246
|
+
end
|
247
|
+
|
248
|
+
def setDates(photo,date_posted=nil,date_taken=nil,
|
249
|
+
date_taken_granularity=nil)
|
250
|
+
photo = photo.id if photo.class == Flickr::Photo
|
251
|
+
date_posted = date_posted.to_i if date_posted.class == Time
|
252
|
+
date_taken = @flickr.mysql_datetime(date_taken) if
|
253
|
+
date_taken.class == Time
|
254
|
+
args = {'photo_id' => photo}
|
255
|
+
args['date_posted'] = date_posted if date_posted
|
256
|
+
args['date_taken'] = date_taken if date_taken
|
257
|
+
args['date_taken_granularity'] = date_taken_granularity if
|
258
|
+
date_taken_granularity
|
259
|
+
@flickr.call_method('flickr.photos.setDates',args)
|
260
|
+
end
|
261
|
+
|
262
|
+
def setMeta(photo,title,description)
|
263
|
+
photo = photo.id if photo.class == Flickr::Photo
|
264
|
+
args = {'photo_id' => photo,
|
265
|
+
'title' => title,
|
266
|
+
'description' => description}
|
267
|
+
@flickr.call_method('flickr.photos.setMeta',args)
|
268
|
+
end
|
269
|
+
|
270
|
+
def search(user=nil,tags=nil,tag_mode=nil,text=nil,min_upload_date=nil,
|
271
|
+
max_upload_date=nil,min_taken_date=nil,max_taken_date=nil,
|
272
|
+
license=nil,extras=nil,per_page=nil,page=nil,sort=nil)
|
273
|
+
|
274
|
+
user = user.nsid if user.respond_to?(:nsid)
|
275
|
+
tags = tags.join(',') if tags.class == Array
|
276
|
+
min_upload_date = min_upload_date.to_i if
|
277
|
+
min_upload_date.class == Time
|
278
|
+
max_upload_date = max_upload_date.to_i if
|
279
|
+
max_upload_date.class == Time
|
280
|
+
min_taken_date = @flickr.mysql_datetime(min_taken_date) if
|
281
|
+
min_taken_date.class == Time
|
282
|
+
max_taken_date = @flickr.mysql_datetime(max_taken_date) if
|
283
|
+
max_taken_date.class == Time
|
284
|
+
license = license.id if license.class == Flickr::License
|
285
|
+
extras = extras.join(',') if extras.class == Array
|
286
|
+
|
287
|
+
args = {}
|
288
|
+
args['user_id'] = user if user
|
289
|
+
args['tags'] = tags if tags
|
290
|
+
args['tag_mode'] = tag_mode if tag_mode
|
291
|
+
args['text'] = text if text
|
292
|
+
args['min_upload_date'] = min_upload_date if min_upload_date
|
293
|
+
args['max_upload_date'] = max_upload_date if max_upload_date
|
294
|
+
args['min_taken_date'] = min_taken_date if min_taken_date
|
295
|
+
args['max_taken_date'] = max_taken_date if max_taken_date
|
296
|
+
args['license'] = license if license
|
297
|
+
args['extras'] = extras if extras
|
298
|
+
args['per_page'] = per_page if per_page
|
299
|
+
args['page'] = page if page
|
300
|
+
args['sort'] = sort if sort
|
301
|
+
|
302
|
+
res = @flickr.call_method('flickr.photos.search',args)
|
303
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
304
|
+
end
|
305
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# rFlickr: A Ruby based Flickr API implementation.
|
2
|
+
# Copyright (C) 2009, Alex Pardoe (digital:pardoe)
|
3
|
+
#
|
4
|
+
# Derrived from work by Trevor Schroeder, see here:
|
5
|
+
# http://rubyforge.org/projects/rflickr/.
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU General Public License
|
9
|
+
# as published by the Free Software Foundation; either version 2
|
10
|
+
# of the License, or (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with this program; if not, write to the Free Software
|
19
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
20
|
+
|
21
|
+
require 'flickr/base'
|
22
|
+
|
23
|
+
class Flickr::PhotoSets < Flickr::APIBase
|
24
|
+
# photoset can be a PhotoSet or a a photoset id
|
25
|
+
# photo can be a Photo or a photo id
|
26
|
+
def addPhoto(photoset,photo)
|
27
|
+
photo = photo.id if photo.class == Flickr::Photo
|
28
|
+
photoset = photoset.id if photoset.class == Flickr::PhotoSet
|
29
|
+
|
30
|
+
@flickr.call_method('flickr.photosets.addPhoto',
|
31
|
+
'photoset_id' => photoset, 'photo_id' => photo)
|
32
|
+
end
|
33
|
+
|
34
|
+
def create(title,primary_photo, description = nil)
|
35
|
+
primary_photo = primary_photo.id if
|
36
|
+
primary_photo.class == Flickr::Photo
|
37
|
+
args = { 'title' => title, 'primary_photo_id' =>
|
38
|
+
primary_photo}
|
39
|
+
args['description'] = description if description
|
40
|
+
res = @flickr.call_method('flickr.photosets.create',args)
|
41
|
+
id = res.elements['/photoset'].attributes['id']
|
42
|
+
url = res.elements['/photoset'].attributes['url']
|
43
|
+
set = Flickr::PhotoSet.new(id,@flickr)
|
44
|
+
set.title = title
|
45
|
+
set.url = url
|
46
|
+
@flickr.photoset_cache_store(set)
|
47
|
+
return set
|
48
|
+
end
|
49
|
+
|
50
|
+
def delete(photoset)
|
51
|
+
photoset = photoset.id if photoset.class == Flickr::PhotoSet
|
52
|
+
@flickr.call_method('flickr.photosets.delete',
|
53
|
+
'photoset_id' => photoset)
|
54
|
+
end
|
55
|
+
|
56
|
+
def editMeta(photoset,title,description=nil)
|
57
|
+
photoset = photoset.id if photoset.class == Flickr::PhotoSet
|
58
|
+
args = {'photoset_id' => photoset,
|
59
|
+
'title' => title}
|
60
|
+
args['description' ] = description if description
|
61
|
+
@flickr.call_method('flickr.photosets.editMeta',args)
|
62
|
+
end
|
63
|
+
|
64
|
+
def editPhotos(photoset,primary_photo,photos)
|
65
|
+
photoset = photoset.id if photoset.class == Flickr::PhotoSet
|
66
|
+
primary_photo = primary_photo.id if
|
67
|
+
primary_photo.class == Flickr::Photo
|
68
|
+
photos=photos.map{|p| p.id if p.class==Flickr::Photo}.join(',')
|
69
|
+
args = {'photoset_id' => photoset,
|
70
|
+
'primary_photo_id' => primary_photo,
|
71
|
+
'photo_ids' => photos }
|
72
|
+
@flickr.call_method('flickr.photosets.editPhotos',args)
|
73
|
+
end
|
74
|
+
|
75
|
+
def getContext(photo,photoset)
|
76
|
+
photoset = photoset.id if photoset.class == Flickr::PhotoSet
|
77
|
+
photo = photo.id if photo.class == Flickr::Photo
|
78
|
+
res = @flickr.call_method('flickr.photosets.getContext',
|
79
|
+
'photo_id' => photo, 'photoset_id' => photoset)
|
80
|
+
return Flickr::Context.from_xml(res,@flickr)
|
81
|
+
end
|
82
|
+
|
83
|
+
def getList(user=nil)
|
84
|
+
user = user.nsid if user.respond_to?(:nsid)
|
85
|
+
args = {}
|
86
|
+
args['user_id'] = user if user
|
87
|
+
res = @flickr.call_method('flickr.photosets.getList',args)
|
88
|
+
list = []
|
89
|
+
res.elements['/photosets'].each_element do |el|
|
90
|
+
list << Flickr::PhotoSet.from_xml(el,@flickr)
|
91
|
+
end
|
92
|
+
return list
|
93
|
+
end
|
94
|
+
|
95
|
+
def removePhoto(photoset,photo)
|
96
|
+
photoset = photoset.id if photoset.class == Flickr::PhotoSet
|
97
|
+
photo = photo.id if photo.class == Flickr::Photo
|
98
|
+
@flickr.call_method('flickr.photosets.removePhoto',
|
99
|
+
'photo_id' => photo, 'photoset_id' => photoset)
|
100
|
+
end
|
101
|
+
|
102
|
+
def getPhotos(photoset,extras=nil)
|
103
|
+
photoset = photoset.id if photoset.class == Flickr::PhotoSet
|
104
|
+
extras = extras.join(',') if extras.class == Array
|
105
|
+
args = { 'photoset_id' => photoset }
|
106
|
+
args['extras'] = extras if extras
|
107
|
+
res = @flickr.call_method('flickr.photosets.getPhotos',args)
|
108
|
+
return Flickr::PhotoSet.from_xml(res.root,@flickr)
|
109
|
+
end
|
110
|
+
|
111
|
+
def getInfo(photoset)
|
112
|
+
photoset = photoset.id if photoset.class == Flickr::PhotoSet
|
113
|
+
res = @flickr.call_method('flickr.photosets.getInfo',
|
114
|
+
'photoset_id' => photoset)
|
115
|
+
return Flickr::PhotoSet.from_xml(res.root,@flickr)
|
116
|
+
end
|
117
|
+
|
118
|
+
def orderSets(photosets)
|
119
|
+
photosets=photosets.map { |ps|
|
120
|
+
(ps.class==Flickr::PhotoSet) ? ps.id : ps}.join(',')
|
121
|
+
@flickr.call_method('flickr.photosets.orderSets',
|
122
|
+
'photoset_ids' => photosets)
|
123
|
+
end
|
124
|
+
end
|
data/lib/flickr/pools.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# rFlickr: A Ruby based Flickr API implementation.
|
2
|
+
# Copyright (C) 2009, Alex Pardoe (digital:pardoe)
|
3
|
+
#
|
4
|
+
# Derrived from work by Trevor Schroeder, see here:
|
5
|
+
# http://rubyforge.org/projects/rflickr/.
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU General Public License
|
9
|
+
# as published by the Free Software Foundation; either version 2
|
10
|
+
# of the License, or (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with this program; if not, write to the Free Software
|
19
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
20
|
+
|
21
|
+
require 'flickr/groups'
|
22
|
+
|
23
|
+
class Flickr::Pools < Flickr::APIBase
|
24
|
+
def initialize(flickr,groups)
|
25
|
+
super(flickr)
|
26
|
+
@groups = groups
|
27
|
+
end
|
28
|
+
|
29
|
+
# photo can be a Photo or photo_id
|
30
|
+
# group can be a Group or group_id
|
31
|
+
def add(photo,group)
|
32
|
+
group = group.nsid if group.class == Flickr::Group
|
33
|
+
photo = photo.id if photo.class == Flickr::Photo
|
34
|
+
@flickr.call_method('flickr.groups.pools.add',
|
35
|
+
'group_id' => group, 'photo_id' => photo)
|
36
|
+
end
|
37
|
+
|
38
|
+
# photo can be a Photo or photo_id
|
39
|
+
# group can be a Group or group_id
|
40
|
+
def remove(photo,group)
|
41
|
+
group = group.nsid if group.class == Flickr::Group
|
42
|
+
photo = photo.id if photo.class == Flickr::Photo
|
43
|
+
@flickr.call_method('flickr.groups.pools.add',
|
44
|
+
'group_id' => group, 'photo_id' => photo)
|
45
|
+
end
|
46
|
+
|
47
|
+
# photo can be a Photo or photo_id
|
48
|
+
# group can be a Group or group_id
|
49
|
+
def getContext(photo,group)
|
50
|
+
group = group.nsid if group.class == Flickr::Group
|
51
|
+
photo = photo.id if photo.class == Flickr::Photo
|
52
|
+
res = @flickr.call_method('flickr.groups.pools.getContex',
|
53
|
+
'group_id' => group, 'photo_id' => photo)
|
54
|
+
return Flickr::Context.from_xml(res)
|
55
|
+
end
|
56
|
+
|
57
|
+
def getGroups
|
58
|
+
res = @flickr.call_method('flickr.groups.pools.getGroups')
|
59
|
+
list = []
|
60
|
+
res.elements['/groups'].each_element do |el|
|
61
|
+
att = el.attributes
|
62
|
+
nsid = att['nsid']
|
63
|
+
g = @flickr.group_cache_lookup(nsid) ||
|
64
|
+
Flickr::Group.new(@flickr,nsid,att['name'])
|
65
|
+
g.name = att['name']
|
66
|
+
g.admin = att['admin'].to_i == 1
|
67
|
+
g.privacy = Flickr::Group::PRIVACY[att['privacy'].to_i]
|
68
|
+
g.photo_count = att['photos'].to_i
|
69
|
+
g.iconserver = att['iconserver'].to_i
|
70
|
+
|
71
|
+
@flickr.group_cache_store(g)
|
72
|
+
list << g
|
73
|
+
end
|
74
|
+
return list
|
75
|
+
end
|
76
|
+
|
77
|
+
def getPhotos(group,tags=nil,extras=nil,per_page=nil,page=nil)
|
78
|
+
group = group.nsid if group.class == Flickr::Group
|
79
|
+
group = group.id.to_s if group.class == Flickr::PhotoPool
|
80
|
+
args = { 'group_id' => group }
|
81
|
+
args['tags'] = tags.map{|t| t.clean if t.class ==
|
82
|
+
Flick::Tag}.join(',') if tags
|
83
|
+
args['extras'] = extras.join(',') if extras.class == Array
|
84
|
+
args['per_page'] = per_page if per_page
|
85
|
+
args['page'] = page if page
|
86
|
+
|
87
|
+
res = @flickr.call_method('flickr.groups.pools.getPhotos', args)
|
88
|
+
return Flickr::PhotoList.from_xml(res,@flickr)
|
89
|
+
end
|
90
|
+
end
|