Class: Flickr::Photo

Inherits:
Object
  • Object
show all
Defined in:
lib/flickr/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flickr, id) ⇒ Photo

Returns a new instance of Photo.



376
377
378
379
# File 'lib/flickr/base.rb', line 376

def initialize(flickr,id)
	@flickr = flickr
	@id = id
end

Instance Attribute Details

#canaddmetaObject

Returns the value of attribute canaddmeta.



358
359
360
# File 'lib/flickr/base.rb', line 358

def canaddmeta
  @canaddmeta
end

#cancommentObject

Returns the value of attribute cancomment.



358
359
360
# File 'lib/flickr/base.rb', line 358

def cancomment
  @cancomment
end

#commentsObject

Returns the value of attribute comments.



358
359
360
# File 'lib/flickr/base.rb', line 358

def comments
  @comments
end

#dateaddedObject

Returns the value of attribute dateadded.



358
359
360
# File 'lib/flickr/base.rb', line 358

def dateadded
  @dateadded
end

#datesObject

Returns the value of attribute dates.



358
359
360
# File 'lib/flickr/base.rb', line 358

def dates
  @dates
end

#descriptionObject

Returns the value of attribute description.



358
359
360
# File 'lib/flickr/base.rb', line 358

def description
  @description
end

#flickrObject (readonly)

Returns the value of attribute flickr.



365
366
367
# File 'lib/flickr/base.rb', line 365

def flickr
  @flickr
end

#idObject

Returns the value of attribute id.



358
359
360
# File 'lib/flickr/base.rb', line 358

def id
  @id
end

#isfamilyObject

Returns the value of attribute isfamily.



358
359
360
# File 'lib/flickr/base.rb', line 358

def isfamily
  @isfamily
end

#isfriendObject

Returns the value of attribute isfriend.



358
359
360
# File 'lib/flickr/base.rb', line 358

def isfriend
  @isfriend
end

#ispublicObject

Returns the value of attribute ispublic.



358
359
360
# File 'lib/flickr/base.rb', line 358

def ispublic
  @ispublic
end

#lastupdateObject

Returns the value of attribute lastupdate.



358
359
360
# File 'lib/flickr/base.rb', line 358

def lastupdate
  @lastupdate
end

#license_idObject

Returns the value of attribute license_id.



358
359
360
# File 'lib/flickr/base.rb', line 358

def license_id
  @license_id
end

#notesObject

Returns the value of attribute notes.



358
359
360
# File 'lib/flickr/base.rb', line 358

def notes
  @notes
end

#originalformatObject

Returns the value of attribute originalformat.



358
359
360
# File 'lib/flickr/base.rb', line 358

def originalformat
  @originalformat
end

#owner_idObject

Returns the value of attribute owner_id.



358
359
360
# File 'lib/flickr/base.rb', line 358

def owner_id
  @owner_id
end

#ownernameObject

Returns the value of attribute ownername.



358
359
360
# File 'lib/flickr/base.rb', line 358

def ownername
  @ownername
end

#permaddmetaObject

Returns the value of attribute permaddmeta.



358
359
360
# File 'lib/flickr/base.rb', line 358

def permaddmeta
  @permaddmeta
end

#permcommentObject

Returns the value of attribute permcomment.



358
359
360
# File 'lib/flickr/base.rb', line 358

def permcomment
  @permcomment
end

#rotationObject

Returns the value of attribute rotation.



358
359
360
# File 'lib/flickr/base.rb', line 358

def rotation
  @rotation
end

#secretObject

Returns the value of attribute secret.



358
359
360
# File 'lib/flickr/base.rb', line 358

def secret
  @secret
end

#serverObject

Returns the value of attribute server.



358
359
360
# File 'lib/flickr/base.rb', line 358

def server
  @server
end

#takenObject

Returns the value of attribute taken.



358
359
360
# File 'lib/flickr/base.rb', line 358

def taken
  @taken
end

#takengranularityObject

Returns the value of attribute takengranularity.



358
359
360
# File 'lib/flickr/base.rb', line 358

def takengranularity
  @takengranularity
end

#titleObject

Returns the value of attribute title.



358
359
360
# File 'lib/flickr/base.rb', line 358

def title
  @title
end

#urlsObject

Returns the value of attribute urls.



358
359
360
# File 'lib/flickr/base.rb', line 358

def urls
  @urls
end

Class Method Details

.from_xml(xml, flickr = nil) ⇒ Object



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/flickr/base.rb', line 401

def self.from_xml(xml,flickr=nil)
	att = xml.attributes
	phid = att['id']

	photo = flickr.photo_cache_lookup(phid) if flickr
	photo ||= Flickr::Photo.new(flickr,phid)

	photo.owner_id ||= att['owner'] || (xml.elements['owner'] &&
		 xml.elements['owner'].attributes['nsid'])
	photo.secret = att['secret'] if att['secret']
	photo.originalformat = att['originalformat'] if
		att['originalformat']
	photo.server = att['server'].to_i if att['server']
	photo.title = att['title'] || cond_text(xml.elements,'title')
	photo.license_id = att['license']
	photo.rotation = att['rotation'].to_i if att['rotation']

	photo.ispublic = (att['ispublic'].to_i == 1) if att['ispublic']
	photo.isfriend = (att['isfriend'].to_i == 1) if att['isfriend']
	photo.isfamily = (att['isfamily'].to_i == 1) if att['isfamily']
	photo.ownername = att['ownername'] || (xml.elements['owner'] &&
		 xml.elements['owner'].attributes['username'])
	photo.description = cond_text(xml.elements,'description')
	photo.dateadded = Time.at(att['dateadded'].to_i) if
		att['dateadded']
	if xml.elements['exif']
		list = []
		xml.elements.each('exif') do |el|
			exif = Flickr::Exif.from_xml(el)
			list << exif
		end
		photo.exif = list
	end
	if xml.elements['visibility']
		att = xml.elements['visibility'].attributes
		photo.ispublic = (att['ispublic'].to_i == 1)
		photo.isfriend = (att['isfriend'].to_i == 1)
		photo.isfamily = (att['isfamily'].to_i == 1)
	end
	if xml.elements['dates']
		att = xml.elements['dates'].attributes
		dates = {}
		dates[:posted] = Time.at(att['posted'].to_i)
		dates[:taken] = Time.gm(*ParseDate.parsedate(att['taken']))
		dates[:lastupdate] = Time.at(att['lastupdate'].to_i)
		dates[:takengranularity] = att['takengranularity'].to_i
		photo.dates = dates
	end
	if xml.elements['editability']
		att = xml.elements['editability'].attributes
		photo.cancomment = (att['cancomment'].to_i == 1)
		photo.canaddmeta = (att['canaddmeta'].to_i == 1)
	end
	photo.comments = cond_text(xml.elements,'comments')
	photo.comments &&= photo.comments.to_i
	if xml.elements['notes']
		notes = []
		xml.elements['notes'].each_element do |el|
			notes << Flickr::Note.from_xml(el,photo)
		end
		photo.notes = notes
	end
	if xml.elements['tags']
		tags = []
		xml.elements['tags'].each_element do |el|
			tags << Flickr::Tag.from_xml(el,photo)
		end
		photo.tags = tags
	end
	if xml.elements['urls']
		urls = {}
		xml.elements['urls'].each_element do |el|
			att = el.attributes
			urls[att['type'].intern] = el.text
		end
		photo.urls = urls
	end
		
	flickr.photo_cache_store(photo) if flickr
	return photo
end

Instance Method Details

#contextsObject



389
# File 'lib/flickr/base.rb', line 389

def contexts() @contexts ||= @flickr.photos.getAllContexts(self) end

#deleteObject



399
# File 'lib/flickr/base.rb', line 399

def delete() @flickr.photos.delete(self) end

#exifObject



381
# File 'lib/flickr/base.rb', line 381

def exif() @exif ||= @flickr.photos.getExif(self) end

#exif=(set) ⇒ Object



382
# File 'lib/flickr/base.rb', line 382

def exif=(set) @exif = set end

#licenseObject



387
# File 'lib/flickr/base.rb', line 387

def license() @flickr.photos.licenses.getInfo[@license_id] end

#max_sizeObject



371
372
373
374
# File 'lib/flickr/base.rb', line 371

def max_size
	sizes[:Original] ||  sizes[:Large] || sizes[:Medium] ||
		sizes[:Small]
end

#ownerObject



367
# File 'lib/flickr/base.rb', line 367

def owner() @owner ||= @flickr.people.getInfo(owner_id) end

#sizesObject



368
# File 'lib/flickr/base.rb', line 368

def sizes() @sizes || @flickr.photos.getSizes(self).sizes end

#sizes=(sizes) ⇒ Object



369
# File 'lib/flickr/base.rb', line 369

def sizes=(sizes) @sizes = sizes end

#tagsObject



384
# File 'lib/flickr/base.rb', line 384

def tags() @tags ||= @flickr.tags.getListPhoto(self) end

#tags=(set) ⇒ Object



385
# File 'lib/flickr/base.rb', line 385

def tags=(set) @tags = set end

#url(size = nil) ⇒ Object



391
392
393
394
395
396
397
# File 'lib/flickr/base.rb', line 391

def url(size=nil)
	base = 'http://static.flickr.com'
	ext = (size == 'o') ? self.originalformat : 'jpg'
	return size ?
		"#{base}/#@server/#{@id}_#{@secret}_#{size}.#{ext}" :
		"#{base}/#@server/#{@id}_#{@secret}.jpg"
end