Class: Flickr::Photo
- Inherits:
-
Object
- Object
- Flickr::Photo
- Defined in:
- lib/flickr.rb
Instance Attribute Summary (collapse)
-
- (Object) client
readonly
Returns the value of attribute client.
-
- (Object) id
readonly
Returns the value of attribute id.
-
- (Object) title
Returns the value of attribute title.
Instance Method Summary (collapse)
-
- (Object) [](param_name)
Allows access to all photos instance variables through hash like interface, e.g.
-
- (Object) add_note(note)
Implements flickr.photos.notes.add.
-
- (Object) add_tag(tag)
Implements flickr.photos.addTags.
-
- (Object) context
Implements flickr.photos.getContext.
-
- (Object) dates=(dates)
Implements flickr.photos.setDates.
-
- (Object) deleteNote(note_id)
Implements flickr.photos.notes.delete.
- - (Object) description
- - (Object) description=(title)
-
- (Object) editNote(note_id)
Implements flickr.photos.notes.edit.
-
- (Object) exif
Implements flickr.photos.getExif.
-
- (Object) file(size = 'Medium')
Returns the photo file data itself, in any specified size.
-
- (Object) filename
Unique filename for the image, based on the Flickr NSID.
-
- (Photo) initialize(id = nil, api_key = {}, extra_params = {})
constructor
A new instance of Photo.
- - (Object) isfavorite
- - (Object) license
-
- (Object) normalize_size(size)
converts string or symbol size to a capitalized string.
- - (Object) notes
-
- (Object) owner
Returns the owner of the photo as a Flickr::User.
-
- (Object) permissions
Implements flickr.photos.getPerms.
-
- (Object) perms=(perms)
Implements flickr.photos.setPerms.
-
- (Object) postToBlog(blog_id, title = '', description = '')
Implements flickr.blogs.postPhoto.
-
- (Object) pretty_url
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/.
-
- (Object) remove_tag(tag)
Implements flickr.photos.removeTag.
-
- (Object) rotate
Implements flickr.photos.transform.rotate.
- - (Object) rotation
- - (Object) server
-
- (Object) size_url(size = 'Medium')
Returns the URL for the photo size page defaults to 'Medium' other valid sizes are in the VALID_SIZES hash.
-
- (Object) sizes(size = nil)
Implements flickr.photos.getSizes.
-
- (Object) source(size = 'Medium')
Returns the URL for the image (default or any specified size).
-
- (Object) tags
flickr.tags.getListPhoto.
-
- (Object) tags=(tags)
Implements flickr.photos.setTags.
-
- (Object) to_s
Converts the Photo to a string by returning its title.
-
- (Object) url(size = nil)
the URL for the main photo page if getInfo has already been called, this will return the pretty url.
Constructor Details
- (Photo) initialize(id = nil, api_key = {}, extra_params = {})
Returns a new instance of Photo
436 437 438 439 440 441 |
# File 'lib/flickr.rb', line 436 def initialize(id=nil, api_key={}, 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
- (Object) client (readonly)
Returns the value of attribute client
434 435 436 |
# File 'lib/flickr.rb', line 434 def client @client end |
- (Object) id (readonly)
Returns the value of attribute id
434 435 436 |
# File 'lib/flickr.rb', line 434 def id @id end |
- (Object) title
Returns the value of attribute title
434 435 436 |
# File 'lib/flickr.rb', line 434 def title @title end |
Instance Method Details
- (Object) [](param_name)
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
449 450 451 |
# File 'lib/flickr.rb', line 449 def [](param_name) instance_variable_get("@#{param_name}") end |
- (Object) add_note(note)
Implements flickr.photos.notes.add
577 578 |
# File 'lib/flickr.rb', line 577 def add_note(note) end |
- (Object) add_tag(tag)
Implements flickr.photos.addTags
599 600 |
# File 'lib/flickr.rb', line 599 def add_tag(tag) end |
- (Object) context
Implements flickr.photos.getContext
546 547 548 549 550 551 |
# File 'lib/flickr.rb', line 546 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 |
- (Object) dates=(dates)
Implements flickr.photos.setDates
581 582 |
# File 'lib/flickr.rb', line 581 def dates=(dates) end |
- (Object) deleteNote(note_id)
Implements flickr.photos.notes.delete
616 617 |
# File 'lib/flickr.rb', line 616 def deleteNote(note_id) end |
- (Object) description
488 489 490 |
# File 'lib/flickr.rb', line 488 def description @description || getInfo("description") end |
- (Object) description=(title)
595 596 |
# File 'lib/flickr.rb', line 595 def description=(title) end |
- (Object) editNote(note_id)
Implements flickr.photos.notes.edit
620 621 |
# File 'lib/flickr.rb', line 620 def editNote(note_id) end |
- (Object) exif
Implements flickr.photos.getExif
554 555 556 |
# File 'lib/flickr.rb', line 554 def exif @client.photos_getExif('photo_id'=>@id)['photo'] end |
- (Object) file(size = 'Medium')
Returns the photo file data itself, in any specified size. Example: File.open(photo.title, 'w') { |f| f.puts photo.file }
536 537 538 |
# File 'lib/flickr.rb', line 536 def file(size='Medium') Net::HTTP.get_response(URI.parse(source(size))).body end |
- (Object) filename
Unique filename for the image, based on the Flickr NSID
541 542 543 |
# File 'lib/flickr.rb', line 541 def filename "#{@id}.jpg" end |
- (Object) isfavorite
476 477 478 |
# File 'lib/flickr.rb', line 476 def isfavorite @isfavorite.nil? ? getInfo("isfavorite") : @isfavorite end |
- (Object) license
480 481 482 |
# File 'lib/flickr.rb', line 480 def license @license.nil? ? getInfo("license") : @license end |
- (Object) normalize_size(size)
converts string or symbol size to a capitalized string
504 505 506 |
# File 'lib/flickr.rb', line 504 def normalize_size(size) size ? size.to_s.capitalize : size end |
- (Object) notes
492 493 494 |
# File 'lib/flickr.rb', line 492 def notes @notes.nil? ? getInfo("notes") : @notes end |
- (Object) owner
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
461 462 463 464 465 466 467 468 469 470 |
# File 'lib/flickr.rb', line 461 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 |
- (Object) permissions
Implements flickr.photos.getPerms
559 560 561 |
# File 'lib/flickr.rb', line 559 def @client.photos_getPerms('photo_id'=>@id)['perms'] end |
- (Object) perms=(perms)
Implements flickr.photos.setPerms
585 586 |
# File 'lib/flickr.rb', line 585 def perms=(perms) end |
- (Object) postToBlog(blog_id, title = '', description = '')
Implements flickr.blogs.postPhoto
611 612 613 |
# File 'lib/flickr.rb', line 611 def postToBlog(blog_id, title='', description='') @client.blogs_postPhoto('photo_id'=>@id, 'title'=>title, 'description'=>description) end |
- (Object) pretty_url
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/
526 527 528 |
# File 'lib/flickr.rb', line 526 def pretty_url @url || getInfo("pretty_url") end |
- (Object) remove_tag(tag)
Implements flickr.photos.removeTag
603 604 |
# File 'lib/flickr.rb', line 603 def remove_tag(tag) end |
- (Object) rotate
Implements flickr.photos.transform.rotate
607 608 |
# File 'lib/flickr.rb', line 607 def rotate end |
- (Object) rotation
484 485 486 |
# File 'lib/flickr.rb', line 484 def rotation @rotation.nil? ? getInfo("rotation") : @rotation end |
- (Object) server
472 473 474 |
# File 'lib/flickr.rb', line 472 def server @server.nil? ? getInfo("server") : @server end |
- (Object) size_url(size = 'Medium')
Returns the URL for the photo size page defaults to 'Medium' other valid sizes are in the VALID_SIZES hash
499 500 501 |
# File 'lib/flickr.rb', line 499 def size_url(size='Medium') uri_for_photo_from_self(size) || sizes(size)['url'] end |
- (Object) sizes(size = nil)
Implements flickr.photos.getSizes
564 565 566 567 568 569 |
# File 'lib/flickr.rb', line 564 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 |
- (Object) source(size = 'Medium')
Returns the URL for the image (default or any specified size)
531 532 533 |
# File 'lib/flickr.rb', line 531 def source(size='Medium') image_source_uri_from_self(size) || sizes(size)['source'] end |
- (Object) tags
flickr.tags.getListPhoto
572 573 574 |
# File 'lib/flickr.rb', line 572 def @client.('photo_id'=>@id)['photo']['tags'] end |
- (Object) tags=(tags)
Implements flickr.photos.setTags
589 590 |
# File 'lib/flickr.rb', line 589 def () end |
- (Object) to_s
Converts the Photo to a string by returning its title
624 625 626 |
# File 'lib/flickr.rb', line 624 def to_s title end |
- (Object) url(size = nil)
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
514 515 516 517 518 519 520 |
# File 'lib/flickr.rb', line 514 def url(size = nil) if normalize_size(size) != 'Medium' size_url(size) else @url || uri_for_photo_from_self end end |