Class: Flickr::Photos

Inherits:
APIBase show all
Defined in:
lib/flickr/photos.rb

Instance Attribute Summary

Attributes inherited from APIBase

#flickr

Instance Method Summary collapse

Methods inherited from APIBase

#initialize

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



34
35
36
37
38
39
# File 'lib/flickr/photos.rb', line 34

def addTags(photo,tags)
  photo = photo.id if photo.class == Flickr::Photo
  tstr = tags.join(',')
  @flickr.call_method('flickr.photos.addTags',
                      'photo_id' => photo, 'tags' => tstr)
end

#delete(photo) ⇒ Object

photo can be a Photo or photo id string/number



54
55
56
57
58
# File 'lib/flickr/photos.rb', line 54

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



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/flickr/photos.rb', line 61

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



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/flickr/photos.rb', line 121

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.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/flickr/photos.rb', line 137

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



154
155
156
157
158
159
# File 'lib/flickr/photos.rb', line 154

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



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/flickr/photos.rb', line 161

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



174
175
176
177
178
179
180
# File 'lib/flickr/photos.rb', line 174

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



182
183
184
185
186
187
188
# File 'lib/flickr/photos.rb', line 182

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



190
191
192
193
194
195
196
197
198
# File 'lib/flickr/photos.rb', line 190

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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/flickr/photos.rb', line 89

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.permaddmeta = att['permaddmeta'].to_i
  return photo
end

#getRecent(extras = nil, per_page = nil, page = nil) ⇒ Object



200
201
202
203
204
205
206
207
208
# File 'lib/flickr/photos.rb', line 200

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



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/flickr/photos.rb', line 220

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



210
211
212
213
214
215
216
217
218
# File 'lib/flickr/photos.rb', line 210

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

#licensesObject



17
18
19
20
# File 'lib/flickr/photos.rb', line 17

def licenses
  require 'flickr/licenses'
  @licenses ||= Flickr::Licenses.new(@flickr)
end

#notesObject



22
23
24
25
# File 'lib/flickr/photos.rb', line 22

def notes
  require 'flickr/notes'
  @notes ||= Flickr::Notes.new(@flickr)
end

#removeTag(tag) ⇒ Object



41
42
43
44
# File 'lib/flickr/photos.rb', line 41

def removeTag(tag)
  tag = tag.id if tag.class == Flickr::Tag
  @flickr.call_method('flickr.photos.removeTag', 'tag_id' => tag)
end

#search(args) ⇒ Object



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/flickr/photos.rb', line 258

def search(args)
  args[:user_id] = args[:user_id].nsid if args[:user_id].respond_to?(:nsid)
  args[:tags] = args[:tags].join(',') if args[:tags].class == Array
  
  [:min_upload_date, :max_upload_date].each do |k|
    args[k] = args[k].to_i if args[k].is_a? Time
  end
  
  [:min_taken_date, :max_taken_date].each do |k|
    args[k] = @flickr.mysql_datetime(args[k]) if args[k].is_a? Time
  end
  
  args[:license] = args[:license].id if args[:license].is_a? Flickr::License
  args[:extras] = args[:extras].join(',') if args[:extras].is_a? Array
  args.each {|k,v| v = args.delete(k); args[k.to_s] = v}

  if block_given?
    thispage = 1
    maxpages = 2
    args['per_page'] ||= 500
    until thispage > maxpages do
      args['page'] = thispage
      res = @flickr.call_method('flickr.photos.search',args)
      list = Flickr::PhotoList.from_xml(res, @flickr)
      maxpages = list.pages
      list.each {|p| yield p}
      thispage += 1
    end
  else
    res = @flickr.call_method('flickr.photos.search',args)
    return Flickr::PhotoList.from_xml(res,@flickr)
  end
rescue StopIteration
  nil
end

#setDates(photo, date_posted = nil, date_taken = nil, date_taken_granularity = nil) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/flickr/photos.rb', line 236

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



250
251
252
253
254
255
256
# File 'lib/flickr/photos.rb', line 250

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



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/flickr/photos.rb', line 107

def setPerms(photo,is_public,is_friend,is_family,perm_comment,
             perm_addmeta)
  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' => perm_addmeta
  }
  res = @flickr.call_method('flickr.photos.setPerms',args)
end

#setTags(tags) ⇒ Object



46
47
48
49
50
51
# File 'lib/flickr/photos.rb', line 46

def setTags(tags)
  tags=tags.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' => tags)
end

#transformObject



27
28
29
30
# File 'lib/flickr/photos.rb', line 27

def transform
  require 'flickr/transform'
  @transform ||= Flickr::Transform.new(@flickr)
end

#uploadObject



12
13
14
15
# File 'lib/flickr/photos.rb', line 12

def upload
  require 'flickr/upload'
  @upload ||= Flickr::Upload.new(@flickr)
end