Class: Fleakr::Objects::Photo

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Support::Object
Defined in:
lib/fleakr/objects/photo.rb

Overview

Photo

Handles both the retrieval of Photo objects from various associations (e.g. User / Set) as well as the ability to upload images to the Flickr site.

Attributes

id

The ID for this photo

title

The title of this photo

description

The description of this photo

secret

This photo’s secret (used for sharing photo without permissions checking)

original_secret

This photo’s original secret

comment_count

Count of the comments attached to this photo

url

This photo’s page on Flickr

square

The tiny square representation of this photo

thumbnail

The thumbnail for this photo

small

The small representation of this photo

medium

The medium representation of this photo

large

The large representation of this photo

original

The original photo

previous

The previous photo based on the current context

next

The next photo based on the current context

Associations

images

The underlying images for this photo.

tags

The tags for this photo.

comments

The comments associated with this photo

Constant Summary collapse

SIZES =

Available sizes for this photo

[:square, :thumbnail, :small, :medium, :large, :original]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Support::Object

included

Class Method Details

.upload(filename, options = {}) ⇒ Object

Upload the photo specified by filename to the user’s Flickr account. When uploading, there are several options available (none are required):

:title

The title for this photo. Any string is allowed.

:description

The description for this photo. Any string is allowed.

:tags

A collection of tags for this photo. This can be a string or array of strings.

:viewable_by

Who can view this photo? Acceptable values are one of :everyone, :friends or :family. This can also take an array of values (e.g. [:friends, :family]) to make it viewable by friends and family.

:level

The safety level of this photo. Acceptable values are one of :safe, :moderate, or :restricted.

:type

The type of image this is. Acceptable values are one of :photo, :screenshot, or :other.

:hide?

Should this photo be hidden from public searches? Takes a boolean.



82
83
84
85
86
# File 'lib/fleakr/objects/photo.rb', line 82

def self.upload(filename, options = {})
  response = Fleakr::Api::UploadRequest.with_response!(filename, :create, options)
  photo = Photo.new(response.body)
  Photo.find_by_id(photo.id)
end

Instance Method Details

#contextObject

:nodoc:



103
104
105
106
107
108
# File 'lib/fleakr/objects/photo.rb', line 103

def context # :nodoc:
  @context ||= begin
    response = Fleakr::Api::MethodRequest.with_response!('photos.getContext', :photo_id => self.id)
    PhotoContext.new(response.body)
  end
end

#load_infoObject

TODO: Refactor this to remove duplication w/ User#load_info - possibly in the lazily_load class method



98
99
100
101
# File 'lib/fleakr/objects/photo.rb', line 98

def load_info # :nodoc:
  response = Fleakr::Api::MethodRequest.with_response!('photos.getInfo', :photo_id => self.id)
  self.populate_from(response.body)
end

#ownerObject

The user who uploaded this photo. See Fleakr::Objects::User for additional information.



112
113
114
# File 'lib/fleakr/objects/photo.rb', line 112

def owner
  @owner ||= User.find_by_id(owner_id)
end

#posted_atObject

When was this photo posted?



118
119
120
# File 'lib/fleakr/objects/photo.rb', line 118

def posted_at
  Time.at(posted.to_i)
end

#replace_with(filename) ⇒ Object

Replace the current photo’s image with the one specified by filename. This call requires authentication.



91
92
93
94
95
# File 'lib/fleakr/objects/photo.rb', line 91

def replace_with(filename)
  response = Fleakr::Api::UploadRequest.with_response!(filename, :update, :photo_id => self.id)
  self.populate_from(response.body)
  self
end

#taken_atObject

When was this photo taken?



124
125
126
# File 'lib/fleakr/objects/photo.rb', line 124

def taken_at
  Time.parse(taken)
end

#updated_atObject

When was this photo last updated? This includes addition of tags and other metadata.



130
131
132
# File 'lib/fleakr/objects/photo.rb', line 130

def updated_at
  Time.at(updated.to_i)
end