Class: Flickr::Photo
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#[](param_name) ⇒ Object
Allows access to all photos instance variables through hash like interface, e.g.
-
#add_note(note) ⇒ Object
Implements flickr.photos.notes.add.
-
#add_tag(tag) ⇒ Object
Implements flickr.photos.addTags.
-
#context ⇒ Object
Implements flickr.photos.getContext.
-
#dates=(dates) ⇒ Object
Implements flickr.photos.setDates.
-
#deleteNote(note_id) ⇒ Object
Implements flickr.photos.notes.delete.
- #description ⇒ Object
- #description=(title) ⇒ Object
-
#editNote(note_id) ⇒ Object
Implements flickr.photos.notes.edit.
-
#exif ⇒ Object
Implements flickr.photos.getExif.
-
#file(size = 'Medium') ⇒ Object
Returns the photo file data itself, in any specified size.
-
#filename ⇒ Object
Unique filename for the image, based on the Flickr NSID.
-
#initialize(id = nil, api_key = nil, extra_params = {}) ⇒ Photo
constructor
A new instance of Photo.
- #isfavorite ⇒ Object
- #license ⇒ Object
-
#media ⇒ Object
unvlog.
-
#normalize_size(size) ⇒ Object
converts string or symbol size to a capitalized string.
- #notes ⇒ Object
-
#owner ⇒ Object
Returns the owner of the photo as a Flickr::User.
-
#permissions ⇒ Object
Implements flickr.photos.getPerms.
-
#perms=(perms) ⇒ Object
Implements flickr.photos.setPerms.
-
#postToBlog(blog_id, title = '', description = '') ⇒ Object
Implements flickr.blogs.postPhoto.
-
#pretty_url ⇒ Object
the ‘pretty’ url for a photo (if the user has set up a custom name) eg, flickr.com/photos/granth/2584402507/ instead of flickr.com/photos/23386158@N00/2584402507/.
-
#remove_tag(tag) ⇒ Object
Implements flickr.photos.removeTag.
-
#rotate ⇒ Object
Implements flickr.photos.transform.rotate.
- #rotation ⇒ Object
- #secret ⇒ Object
- #server ⇒ Object
-
#size_url(size = 'Medium') ⇒ Object
Returns the URL for the photo size page defaults to ‘Medium’ other valid sizes are in the VALID_SIZES hash.
-
#sizes(size = nil) ⇒ Object
Implements flickr.photos.getSizes.
-
#source(size = 'Medium') ⇒ Object
Returns the URL for the image (default or any specified size).
-
#tags ⇒ Object
flickr.tags.getListPhoto.
-
#tags=(tags) ⇒ Object
Implements flickr.photos.setTags.
-
#to_s ⇒ Object
Converts the Photo to a string by returning its title.
-
#url(size = nil) ⇒ Object
the URL for the main photo page if getInfo has already been called, this will return the pretty url.
Constructor Details
#initialize(id = nil, api_key = nil, extra_params = {}) ⇒ Photo
Returns a new instance of Photo.
393 394 395 396 397 398 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 393 def initialize(id=nil, api_key=nil, extra_params={}) @id = id @api_key = api_key extra_params.each { |k,v| self.instance_variable_set("@#{k}", v) } # convert extra_params into instance variables @client = Flickr.new @api_key end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
391 392 393 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 391 def client @client end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
391 392 393 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 391 def id @id end |
#title ⇒ Object
Returns the value of attribute title.
391 392 393 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 391 def title @title end |
Instance Method Details
#[](param_name) ⇒ Object
Allows access to all photos instance variables through hash like interface, e.g. photo returns @datetaken instance variable. Useful for accessing any weird and wonderful parameter that may have been returned by Flickr when finding the photo, e.g. those returned by the extras argument in flickr.people.getPublicPhotos
406 407 408 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 406 def [](param_name) instance_variable_get("@#{param_name}") end |
#add_note(note) ⇒ Object
Implements flickr.photos.notes.add
534 535 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 534 def add_note(note) end |
#add_tag(tag) ⇒ Object
Implements flickr.photos.addTags
556 557 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 556 def add_tag(tag) end |
#context ⇒ Object
Implements flickr.photos.getContext
503 504 505 506 507 508 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 503 def context context = @client.photos_getContext('photo_id'=>@id) @previousPhoto = Photo.new(context['prevphoto'].delete('id'), @api_key, context['prevphoto']) if context['prevphoto']['id']!='0' @nextPhoto = Photo.new(context['nextphoto'].delete('id'), @api_key, context['nextphoto']) if context['nextphoto']['id']!='0' return [@previousPhoto, @nextPhoto] end |
#dates=(dates) ⇒ Object
Implements flickr.photos.setDates
538 539 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 538 def dates=(dates) end |
#deleteNote(note_id) ⇒ Object
Implements flickr.photos.notes.delete
573 574 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 573 def deleteNote(note_id) end |
#description ⇒ Object
445 446 447 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 445 def description @description || getInfo("description") end |
#description=(title) ⇒ Object
552 553 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 552 def description=(title) end |
#editNote(note_id) ⇒ Object
Implements flickr.photos.notes.edit
577 578 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 577 def editNote(note_id) end |
#exif ⇒ Object
Implements flickr.photos.getExif
511 512 513 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 511 def exif @client.photos_getExif('photo_id'=>@id)['photo'] end |
#file(size = 'Medium') ⇒ Object
Returns the photo file data itself, in any specified size. Example: File.open(photo.title, ‘w’) { |f| f.puts photo.file }
493 494 495 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 493 def file(size='Medium') Net::HTTP.get_response(URI.parse(source(size))).body end |
#filename ⇒ Object
Unique filename for the image, based on the Flickr NSID
498 499 500 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 498 def filename "#{@id}.jpg" end |
#isfavorite ⇒ Object
433 434 435 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 433 def isfavorite @isfavorite.nil? ? getInfo("isfavorite") : @isfavorite end |
#license ⇒ Object
437 438 439 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 437 def license @license.nil? ? getInfo("license") : @license end |
#media ⇒ Object
unvlog
587 588 589 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 587 def media @media || getInfo("media") end |
#normalize_size(size) ⇒ Object
converts string or symbol size to a capitalized string
461 462 463 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 461 def normalize_size(size) size ? size.to_s.capitalize : size end |
#notes ⇒ Object
449 450 451 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 449 def notes @notes.nil? ? getInfo("notes") : @notes end |
#owner ⇒ Object
Returns the owner of the photo as a Flickr::User. If we have no info about the owner, we make an API call to get it. If we already have the owner’s id, create a user based on that. Either way, we cache the result so we don’t need to check again
418 419 420 421 422 423 424 425 426 427 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 418 def owner case @owner when Flickr::User @owner when String @owner = Flickr::User.new(@owner, nil, nil, nil, @api_key) else getInfo("owner") end end |
#permissions ⇒ Object
Implements flickr.photos.getPerms
516 517 518 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 516 def @client.photos_getPerms('photo_id'=>@id)['perms'] end |
#perms=(perms) ⇒ Object
Implements flickr.photos.setPerms
542 543 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 542 def perms=(perms) end |
#postToBlog(blog_id, title = '', description = '') ⇒ Object
Implements flickr.blogs.postPhoto
568 569 570 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 568 def postToBlog(blog_id, title='', description='') @client.blogs_postPhoto('photo_id'=>@id, 'title'=>title, 'description'=>description) end |
#pretty_url ⇒ Object
the ‘pretty’ url for a photo (if the user has set up a custom name) eg, flickr.com/photos/granth/2584402507/ instead of
http://flickr.com/photos/23386158@N00/2584402507/
483 484 485 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 483 def pretty_url @url || getInfo("pretty_url") end |
#remove_tag(tag) ⇒ Object
Implements flickr.photos.removeTag
560 561 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 560 def remove_tag(tag) end |
#rotate ⇒ Object
Implements flickr.photos.transform.rotate
564 565 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 564 def rotate end |
#rotation ⇒ Object
441 442 443 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 441 def rotation @rotation.nil? ? getInfo("rotation") : @rotation end |
#secret ⇒ Object
591 592 593 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 591 def secret @secret || getInfo("secret") end |
#server ⇒ Object
429 430 431 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 429 def server @server.nil? ? getInfo("server") : @server end |
#size_url(size = 'Medium') ⇒ Object
Returns the URL for the photo size page defaults to ‘Medium’ other valid sizes are in the VALID_SIZES hash
456 457 458 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 456 def size_url(size='Medium') uri_for_photo_from_self(size) || sizes(size)['url'] end |
#sizes(size = nil) ⇒ Object
Implements flickr.photos.getSizes
521 522 523 524 525 526 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 521 def sizes(size=nil) size = normalize_size(size) sizes = @client.photos_getSizes('photo_id'=>@id)['sizes']['size'] sizes = sizes.find{|asize| asize['label']==size} if size return sizes end |
#source(size = 'Medium') ⇒ Object
Returns the URL for the image (default or any specified size)
488 489 490 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 488 def source(size='Medium') image_source_uri_from_self(size) || sizes(size)['source'] end |
#tags ⇒ Object
flickr.tags.getListPhoto
529 530 531 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 529 def @client.('photo_id'=>@id)['photo']['tags'] end |
#tags=(tags) ⇒ Object
Implements flickr.photos.setTags
546 547 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 546 def () end |
#to_s ⇒ Object
Converts the Photo to a string by returning its title
581 582 583 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 581 def to_s title end |
#url(size = nil) ⇒ Object
the URL for the main photo page if getInfo has already been called, this will return the pretty url
for historical reasons, an optional size can be given ‘Medium’ returns the regular url; any other size returns a size page use size_url instead
471 472 473 474 475 476 477 |
# File 'lib/acts_as_unvlogable/flickr.rb', line 471 def url(size = nil) if normalize_size(size) != 'Medium' size_url(size) else @url || uri_for_photo_from_self end end |