Class: Flickr::Photo
- Inherits:
-
Object
- Object
- Flickr::Photo
- Defined in:
- lib/flickr/base.rb
Instance Attribute Summary collapse
-
#canaddmeta ⇒ Object
Returns the value of attribute canaddmeta.
-
#cancomment ⇒ Object
Returns the value of attribute cancomment.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#dateadded ⇒ Object
Returns the value of attribute dateadded.
-
#dates ⇒ Object
Returns the value of attribute dates.
-
#description ⇒ Object
Returns the value of attribute description.
-
#farm ⇒ Object
Returns the value of attribute farm.
-
#flickr ⇒ Object
readonly
Returns the value of attribute flickr.
-
#id ⇒ Object
Returns the value of attribute id.
-
#isfamily ⇒ Object
Returns the value of attribute isfamily.
-
#isfriend ⇒ Object
Returns the value of attribute isfriend.
-
#ispublic ⇒ Object
Returns the value of attribute ispublic.
-
#lastupdate ⇒ Object
Returns the value of attribute lastupdate.
-
#license_id ⇒ Object
Returns the value of attribute license_id.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#originalformat ⇒ Object
Returns the value of attribute originalformat.
-
#owner_id ⇒ Object
Returns the value of attribute owner_id.
-
#ownername ⇒ Object
Returns the value of attribute ownername.
-
#permaddmeta ⇒ Object
Returns the value of attribute permaddmeta.
-
#permcomment ⇒ Object
Returns the value of attribute permcomment.
-
#rotation ⇒ Object
Returns the value of attribute rotation.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#server ⇒ Object
Returns the value of attribute server.
-
#taken ⇒ Object
Returns the value of attribute taken.
-
#takengranularity ⇒ Object
Returns the value of attribute takengranularity.
-
#title ⇒ Object
Returns the value of attribute title.
-
#urls ⇒ Object
Returns the value of attribute urls.
Class Method Summary collapse
Instance Method Summary collapse
- #contexts ⇒ Object
- #delete ⇒ Object
- #exif ⇒ Object
- #exif=(set) ⇒ Object
-
#initialize(flickr, id) ⇒ Photo
constructor
A new instance of Photo.
- #license ⇒ Object
- #max_size ⇒ Object
- #owner ⇒ Object
- #sizes ⇒ Object
- #sizes=(sizes) ⇒ Object
- #tags ⇒ Object
- #tags=(set) ⇒ Object
- #url(size = nil) ⇒ Object
Constructor Details
#initialize(flickr, id) ⇒ Photo
Returns a new instance of Photo.
392 393 394 395 |
# File 'lib/flickr/base.rb', line 392 def initialize(flickr,id) @flickr = flickr @id = id end |
Instance Attribute Details
#canaddmeta ⇒ Object
Returns the value of attribute canaddmeta.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def @canaddmeta end |
#cancomment ⇒ Object
Returns the value of attribute cancomment.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def cancomment @cancomment end |
#comments ⇒ Object
Returns the value of attribute comments.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def comments @comments end |
#dateadded ⇒ Object
Returns the value of attribute dateadded.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def dateadded @dateadded end |
#dates ⇒ Object
Returns the value of attribute dates.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def dates @dates end |
#description ⇒ Object
Returns the value of attribute description.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def description @description end |
#farm ⇒ Object
Returns the value of attribute farm.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def farm @farm end |
#flickr ⇒ Object (readonly)
Returns the value of attribute flickr.
381 382 383 |
# File 'lib/flickr/base.rb', line 381 def flickr @flickr end |
#id ⇒ Object
Returns the value of attribute id.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def id @id end |
#isfamily ⇒ Object
Returns the value of attribute isfamily.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def isfamily @isfamily end |
#isfriend ⇒ Object
Returns the value of attribute isfriend.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def isfriend @isfriend end |
#ispublic ⇒ Object
Returns the value of attribute ispublic.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def ispublic @ispublic end |
#lastupdate ⇒ Object
Returns the value of attribute lastupdate.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def lastupdate @lastupdate end |
#license_id ⇒ Object
Returns the value of attribute license_id.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def license_id @license_id end |
#notes ⇒ Object
Returns the value of attribute notes.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def notes @notes end |
#originalformat ⇒ Object
Returns the value of attribute originalformat.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def originalformat @originalformat end |
#owner_id ⇒ Object
Returns the value of attribute owner_id.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def owner_id @owner_id end |
#ownername ⇒ Object
Returns the value of attribute ownername.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def ownername @ownername end |
#permaddmeta ⇒ Object
Returns the value of attribute permaddmeta.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def @permaddmeta end |
#permcomment ⇒ Object
Returns the value of attribute permcomment.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def permcomment @permcomment end |
#rotation ⇒ Object
Returns the value of attribute rotation.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def rotation @rotation end |
#secret ⇒ Object
Returns the value of attribute secret.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def secret @secret end |
#server ⇒ Object
Returns the value of attribute server.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def server @server end |
#taken ⇒ Object
Returns the value of attribute taken.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def taken @taken end |
#takengranularity ⇒ Object
Returns the value of attribute takengranularity.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def takengranularity @takengranularity end |
#title ⇒ Object
Returns the value of attribute title.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def title @title end |
#urls ⇒ Object
Returns the value of attribute urls.
374 375 376 |
# File 'lib/flickr/base.rb', line 374 def urls @urls end |
Class Method Details
.from_xml(xml, flickr = nil) ⇒ Object
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 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/flickr/base.rb', line 417 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.farm = att['farm'].to_i if att['farm'] 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. = (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'] = [] xml.elements['tags'].each_element do |el| << Flickr::Tag.from_xml(el,photo) end photo. = 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
#contexts ⇒ Object
405 |
# File 'lib/flickr/base.rb', line 405 def contexts() @contexts ||= @flickr.photos.getAllContexts(self) end |
#delete ⇒ Object
415 |
# File 'lib/flickr/base.rb', line 415 def delete() @flickr.photos.delete(self) end |
#exif ⇒ Object
397 |
# File 'lib/flickr/base.rb', line 397 def exif() @exif ||= @flickr.photos.getExif(self) end |
#exif=(set) ⇒ Object
398 |
# File 'lib/flickr/base.rb', line 398 def exif=(set) @exif = set end |
#license ⇒ Object
403 |
# File 'lib/flickr/base.rb', line 403 def license() @flickr.photos.licenses.getInfo[@license_id] end |
#max_size ⇒ Object
387 388 389 390 |
# File 'lib/flickr/base.rb', line 387 def max_size sizes[:Original] || sizes[:Large] || sizes[:Medium] || sizes[:Small] end |
#owner ⇒ Object
383 |
# File 'lib/flickr/base.rb', line 383 def owner() @owner ||= @flickr.people.getInfo(owner_id) end |
#sizes ⇒ Object
384 |
# File 'lib/flickr/base.rb', line 384 def sizes() @sizes || @flickr.photos.getSizes(self).sizes end |
#sizes=(sizes) ⇒ Object
385 |
# File 'lib/flickr/base.rb', line 385 def sizes=(sizes) @sizes = sizes end |
#tags ⇒ Object
400 |
# File 'lib/flickr/base.rb', line 400 def () @tags ||= @flickr..getListPhoto(self) end |
#tags=(set) ⇒ Object
401 |
# File 'lib/flickr/base.rb', line 401 def (set) @tags = set end |
#url(size = nil) ⇒ Object
407 408 409 410 411 412 413 |
# File 'lib/flickr/base.rb', line 407 def url(size=nil) base = "http://farm#{@farm}.static.flickr.com" ext = (size == 'o') ? self.originalformat : 'jpg' return size ? "#{base}/#@server/#{@id}_#{@secret}_#{size}.#{ext}" : "#{base}/#@server/#{@id}_#{@secret}.jpg" end |