Class: Flickr::Photos
Instance Attribute Summary
Attributes inherited from APIBase
Instance Method Summary collapse
-
#addTags(photo, tags) ⇒ Object
photo can be a Photo or a photo id tags is an array of tags.
-
#delete(photo) ⇒ Object
photo can be a Photo or photo id string/number.
-
#getAllContexts(photo) ⇒ Object
photo can be a Photo or photo id string/number.
- #getContactsPhotos(count = nil, just_friends = nil, single_photo = nil, include_self = nil) ⇒ Object
-
#getContactsPublicPhotos(user, count = nil, just_friends = nil, single_photo = nil, include_self = nil) ⇒ Object
Person can be a string nsid or anything that responds to the nsid method.
- #getContext(photo) ⇒ Object
- #getCounts(dates = nil, taken_dates = nil) ⇒ Object
- #getExif(photo, secret = nil) ⇒ Object
- #getInfo(photo, secret = nil) ⇒ Object
- #getNotInSet(extras = nil, per_page = nil, page = nil) ⇒ Object
- #getPerms(photo) ⇒ Object
- #getRecent(extras = nil, per_page = nil, page = nil) ⇒ Object
- #getSizes(photo) ⇒ Object
- #getUntagged(extras = nil, per_page = nil, page = nil) ⇒ Object
- #licenses ⇒ Object
- #notes ⇒ Object
- #removeTag(tag) ⇒ Object
- #search(user = nil, tags = nil, tag_mode = nil, text = nil, min_upload_date = nil, max_upload_date = nil, min_taken_date = nil, max_taken_date = nil, license = nil, extras = nil, per_page = nil, page = nil, sort = nil) ⇒ Object
- #setDates(photo, date_posted = nil, date_taken = nil, date_taken_granularity = nil) ⇒ Object
- #setMeta(photo, title, description) ⇒ Object
- #setPerms(photo, is_public, is_friend, is_family, perm_comment, perm_addmeta) ⇒ Object
- #setTags(tags) ⇒ Object
- #transform ⇒ Object
- #upload ⇒ Object
Methods inherited from APIBase
Constructor Details
This class inherits a constructor from Flickr::APIBase
Instance Method Details
#addTags(photo, tags) ⇒ Object
photo can be a Photo or a photo id tags is an array of tags
46 47 48 49 50 51 |
# File 'lib/flickr/photos.rb', line 46 def addTags(photo,) photo = photo.id if photo.class == Flickr::Photo tstr = .join(',') @flickr.call_method('flickr.photos.addTags', 'photo' => photo, 'tags' => tstr) end |
#delete(photo) ⇒ Object
photo can be a Photo or photo id string/number
66 67 68 69 70 |
# File 'lib/flickr/photos.rb', line 66 def delete(photo) photo = photo.id if photo.class == Flickr::Photo res = @flickr.call_method('flickr.photos.delete', 'photo_id'=>photo) end |
#getAllContexts(photo) ⇒ Object
photo can be a Photo or photo id string/number
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/flickr/photos.rb', line 73 def getAllContexts(photo) photo = photo.id if photo.class == Flickr::Photo res @flickr.call_method('flickr.photos.getAllContexts', 'photo_id'=>photo) list = [] res.each_element('set') do |set| att = set.attributes psid = att['id'] set = @flickr.photoset_cache_lookup(psid) || Flickr::PhotoSet.new(att['id'],@flickr) set.title = att['title'] @flickr.photoset_cache_store(set) list << set end res.each_element('pool') do |set| att = set.attributes ppid = att['id'] p = @flickr.photopool_cache_lookup(ppid) || Flickr::PhotoPool.new(ppid,@flickr) p.title = att['title'] @flickr.photopool_cache_store(ppid) list << p end return list end |
#getContactsPhotos(count = nil, just_friends = nil, single_photo = nil, include_self = nil) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/flickr/photos.rb', line 133 def getContactsPhotos(count=nil,just_friends=nil,single_photo=nil, include_self=nil) args = {} args['count'] = count if count args['just_friends'] = just_friends ? '1' : '0' if just_friends != nil args['single_photo'] = single_photo ? '1' : '0' if single_photo != nil args['include_self'] = include_self ? '1' : '0' if include_self != nil res= @flickr.call_method('flickr.photos.getContactsPhotos',args) return Flickr::PhotoList.from_xml(res,@flickr) end |
#getContactsPublicPhotos(user, count = nil, just_friends = nil, single_photo = nil, include_self = nil) ⇒ Object
Person can be a string nsid or anything that responds to the nsid method.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/flickr/photos.rb', line 149 def getContactsPublicPhotos(user, count=nil,just_friends=nil, single_photo=nil, include_self=nil) user = user.nsid if user.respond_to?(:nsid) args = {} args['count'] = count if count args['user_id'] = user args['just_friends'] = just_friends ? '1' : '0' if just_friends != nil args['single_photo'] = single_photo ? '1' : '0' if single_photo != nil args['include_self'] = include_self ? '1' : '0' if include_self != nil res=@flickr.call_method('flickr.photos.getContactsPublicPhotos', args) return Flickr::PhotoList.from_xml(res,@flickr) end |
#getContext(photo) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/flickr/photos.rb', line 166 def getContext(photo) photo = photo.id if photo.class == Flickr::Photo res = @flickr.call_method('flickr.photos.getContext', 'photo_id' => photo) return Flickr::Context.from_xml(res) end |
#getCounts(dates = nil, taken_dates = nil) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/flickr/photos.rb', line 173 def getCounts(dates=nil,taken_dates=nil) args = {} args['dates'] = dates.map{|d| d.to_i}.join(',') if dates args['taken_dates'] = taken_dates.map{|d| d.to_i}.join(',') if taken_dates res = @flickr.call_method('flickr.photos.getCounts',args) list = [] res.elements['/photocounts'].each_element('photocount') do |el| list << Flickr::Count.from_xml(el) end return list end |
#getExif(photo, secret = nil) ⇒ Object
186 187 188 189 190 191 192 |
# File 'lib/flickr/photos.rb', line 186 def getExif(photo,secret = nil) photo = photo.id if photo.class == Flickr::Photo args = {'photo_id' => photo} args['secret'] = secret if secret res = @flickr.call_method('flickr.photos.getExif',args) return Flickr::Photo.from_xml(res.elements['/photo'],@flickr) end |
#getInfo(photo, secret = nil) ⇒ Object
194 195 196 197 198 199 200 |
# File 'lib/flickr/photos.rb', line 194 def getInfo(photo,secret = nil) photo = (photo.class == Flickr::Photo) ? photo.id : photo args= {'photo_id' => photo} args['secret'] = secret if secret res = @flickr.call_method('flickr.photos.getInfo',args) return Flickr::Photo.from_xml(res.elements['photo'],@flickr) end |
#getNotInSet(extras = nil, per_page = nil, page = nil) ⇒ Object
202 203 204 205 206 207 208 209 210 |
# File 'lib/flickr/photos.rb', line 202 def getNotInSet(extras=nil,per_page = nil, page = nil) args = {} extras = extras.join(',') if extras.class == Array args['extras'] = extras if extras args['per_page'] = per_page if per_page args['page'] = page if page res = @flickr.call_method('flickr.photos.getNotInSet',args) return Flickr::PhotoList.from_xml(res,@flickr) end |
#getPerms(photo) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/flickr/photos.rb', line 101 def getPerms(photo) photo = photo.id if photo.class == Flickr::Photo res = @flickr.call_method('flickr.photos.getPerms', 'photo_id' => photo) perms = res.elements['/perms'] att = perms.attributes phid = att['id'] photo = (photo.class == Flickr::Photo) ? photo : (@flickr.photo_cache_lookup(phid) || Flickr::Photo.new(@flickr,phid)) photo.ispublic = (att['ispublic'].to_i == 1) photo.isfriend = (att['isfriend'].to_i == 1) photo.isfamily = (att['isfamily'].to_i == 1) photo.permcomment = att['permcomment'].to_i photo. = att['permaddmeta'].to_i return photo end |
#getRecent(extras = nil, per_page = nil, page = nil) ⇒ Object
212 213 214 215 216 217 218 219 220 |
# File 'lib/flickr/photos.rb', line 212 def getRecent(extras=nil,per_page = nil, page = nil) args = {} extras = extras.join(',') if extras.class == Array args['extras'] = extras if extras args['per_page'] = per_page if per_page args['page'] = page if page res = @flickr.call_method('flickr.photos.getRecent',args) return Flickr::PhotoList.from_xml(res,@flickr) end |
#getSizes(photo) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/flickr/photos.rb', line 232 def getSizes(photo) photo_id = (photo.class == Flickr::Photo) ? photo.id : photo photo = (photo.class == Flickr::Photo) ? photo : (@flickr.photo_cache_lookup(photo_id) || Flickr::Photo.new(@flickr,photo_id)) res = @flickr.call_method('flickr.photos.getSizes', 'photo_id' => photo_id ) photo.sizes = {} res.elements['/sizes'].each_element do |el| size = Flickr::Size.from_xml(el) photo.sizes[size.label.intern] = size end @flickr.photo_cache_store(photo) return photo end |
#getUntagged(extras = nil, per_page = nil, page = nil) ⇒ Object
222 223 224 225 226 227 228 229 230 |
# File 'lib/flickr/photos.rb', line 222 def getUntagged(extras=nil,per_page = nil, page = nil) args = {} extras = extras.join(',') if extras.class == Array args['extras'] = extras if extras args['per_page'] = per_page if per_page args['page'] = page if page res = @flickr.call_method('flickr.photos.getUntagged',args) return Flickr::PhotoList.from_xml(res,@flickr) end |
#licenses ⇒ Object
29 30 31 32 |
# File 'lib/flickr/photos.rb', line 29 def licenses require 'flickr/licenses' @licenses ||= Flickr::Licenses.new(@flickr) end |
#notes ⇒ Object
34 35 36 37 |
# File 'lib/flickr/photos.rb', line 34 def notes require 'flickr/notes' @notes ||= Flickr::Notes.new(@flickr) end |
#removeTag(tag) ⇒ Object
53 54 55 56 |
# File 'lib/flickr/photos.rb', line 53 def removeTag(tag) tag = tag.id if tag.class == Flickr::Tag @flickr.call_method('flickr.photos.removeTag', 'tag_id' => tag) end |
#search(user = nil, tags = nil, tag_mode = nil, text = nil, min_upload_date = nil, max_upload_date = nil, min_taken_date = nil, max_taken_date = nil, license = nil, extras = nil, per_page = nil, page = nil, sort = nil) ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/flickr/photos.rb', line 270 def search(user=nil,=nil,tag_mode=nil,text=nil,min_upload_date=nil, max_upload_date=nil,min_taken_date=nil,max_taken_date=nil, license=nil,extras=nil,per_page=nil,page=nil,sort=nil) user = user.nsid if user.respond_to?(:nsid) = .join(',') if .class == Array min_upload_date = min_upload_date.to_i if min_upload_date.class == Time max_upload_date = max_upload_date.to_i if max_upload_date.class == Time min_taken_date = @flickr.mysql_datetime(min_taken_date) if min_taken_date.class == Time max_taken_date = @flickr.mysql_datetime(max_taken_date) if max_taken_date.class == Time license = license.id if license.class == Flickr::License extras = extras.join(',') if extras.class == Array args = {} args['user_id'] = user if user args['tags'] = if args['tag_mode'] = tag_mode if tag_mode args['text'] = text if text args['min_upload_date'] = min_upload_date if min_upload_date args['max_upload_date'] = max_upload_date if max_upload_date args['min_taken_date'] = min_taken_date if min_taken_date args['max_taken_date'] = max_taken_date if max_taken_date args['license'] = license if license args['extras'] = extras if extras args['per_page'] = per_page if per_page args['page'] = page if page args['sort'] = sort if sort res = @flickr.call_method('flickr.photos.search',args) return Flickr::PhotoList.from_xml(res,@flickr) end |
#setDates(photo, date_posted = nil, date_taken = nil, date_taken_granularity = nil) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/flickr/photos.rb', line 248 def setDates(photo,date_posted=nil,date_taken=nil, date_taken_granularity=nil) photo = photo.id if photo.class == Flickr::Photo date_posted = date_posted.to_i if date_posted.class == Time date_taken = @flickr.mysql_datetime(date_taken) if date_taken.class == Time args = {'photo_id' => photo} args['date_posted'] = date_posted if date_posted args['date_taken'] = date_taken if date_taken args['date_taken_granularity'] = date_taken_granularity if date_taken_granularity @flickr.call_method('flickr.photos.setDates',args) end |
#setMeta(photo, title, description) ⇒ Object
262 263 264 265 266 267 268 |
# File 'lib/flickr/photos.rb', line 262 def setMeta(photo,title,description) photo = photo.id if photo.class == Flickr::Photo args = {'photo_id' => photo, 'title' => title, 'description' => description} @flickr.call_method('flickr.photos.setMeta',args) end |
#setPerms(photo, is_public, is_friend, is_family, perm_comment, perm_addmeta) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/flickr/photos.rb', line 119 def setPerms(photo,is_public,is_friend,is_family,perm_comment, ) photo = photo.id if photo.class == Flickr::Photo args = { 'photo_id' => photo, 'is_public' => (is_public == true || is_public == 1) ? 1 : 0, 'is_friend' => (is_friend == true || is_friend == 1) ? 1 : 0, 'is_family' => (is_family == true || is_family == 1) ? 1 : 0, 'perm_comment' => perm_comment, 'perm_addmeta' => } res = @flickr.call_method('flickr.photos.setPerms',args) end |
#setTags(tags) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/flickr/photos.rb', line 58 def setTags() =.map{|t| (t.class == Flickr::Tag) ? t.id : t}.join(' ') photo = photo.id if photo.class == Flickr::Photo @flickr.call_method('flickr.photos.setTags', 'photo_id' => photo, 'tags' => ) end |