Class: Net::Flickr::Photo

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

Overview

A Flickr photo.

Don’t instantiate this class yourself. Use the methods in Flickr::Photos to retrieve photos from Flickr.

Constant Summary collapse

SIZE_SUFFIX =
{
  :square   => 's',
  :thumb    => 't',
  :small    => 'm',
  :medium   => nil,
  :large    => 'b',
  :original => 'o'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flickr, photo_xml) ⇒ Photo

Returns a new instance of Photo.



51
52
53
54
55
56
57
58
59
# File 'lib/net/flickr/photo.rb', line 51

def initialize(flickr, photo_xml)
  @flickr = flickr
  
  parse_xml(photo_xml)
  
  # Detailed photo info.
  @context_xml = nil
  @info_xml    = nil
end

Instance Attribute Details

#farmObject (readonly)

– Public Instance Methods ++



49
50
51
# File 'lib/net/flickr/photo.rb', line 49

def farm
  @farm
end

#idObject (readonly)

– Public Instance Methods ++



49
50
51
# File 'lib/net/flickr/photo.rb', line 49

def id
  @id
end

#secretObject (readonly)

– Public Instance Methods ++



49
50
51
# File 'lib/net/flickr/photo.rb', line 49

def secret
  @secret
end

#serverObject (readonly)

– Public Instance Methods ++



49
50
51
# File 'lib/net/flickr/photo.rb', line 49

def server
  @server
end

Instance Method Details

#deleteObject

Deletes this photo from Flickr. This method requires authentication with delete permission.



63
64
65
# File 'lib/net/flickr/photo.rb', line 63

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

#descriptionObject

Gets this photo’s description.



68
69
70
71
# File 'lib/net/flickr/photo.rb', line 68

def description
  info_xml = get_info
  return info_xml.at('description').inner_text
end

#description=(value) ⇒ Object

Sets this photo’s description. This method requires authentication with write permission.



75
76
77
# File 'lib/net/flickr/photo.rb', line 75

def description=(value)
  set_meta(@title, value)
end

#exifObject

flickr.photos.getExif

Raises:

  • (NotImplementedError)


80
81
82
# File 'lib/net/flickr/photo.rb', line 80

def exif
  raise NotImplementedError
end

#family?Boolean

Whether or not this photo is visible to family.

Returns:

  • (Boolean)


85
86
87
88
# File 'lib/net/flickr/photo.rb', line 85

def family?
  get_info if @is_family.nil?
  return @is_family || @is_public
end

#favoritesObject

flickr.photos.getFavorites

Raises:

  • (NotImplementedError)


91
92
93
# File 'lib/net/flickr/photo.rb', line 91

def favorites
  raise NotImplementedError
end

#friend?Boolean

Whether or not this photo is visible to friends.

Returns:

  • (Boolean)


96
97
98
99
# File 'lib/net/flickr/photo.rb', line 96

def friend?
  get_info if @is_friend.nil?
  return @is_friend || @is_public
end

#gpsObject

flickr.photos.getExif

Raises:

  • (NotImplementedError)


102
103
104
# File 'lib/net/flickr/photo.rb', line 102

def gps
  raise NotImplementedError
end

#modifiedObject

Gets the time this photo was last modified.



107
108
109
110
# File 'lib/net/flickr/photo.rb', line 107

def modified
  info_xml = get_info
  return Time.at(info_xml.at('dates')[:lastupdate].to_i)
end

#nextObject

Gets the next photo in the owner’s photo stream, or nil if this is the last photo in the stream.



114
115
116
117
118
119
120
# File 'lib/net/flickr/photo.rb', line 114

def next
  context_xml = get_context
  next_xml    = context_xml.at('nextphoto')
  
  return Photo.new(@flickr, next_xml) if next_xml[:id] != '0'
  return nil
end

#ownerObject

Gets the user id of this photo’s owner.



123
124
125
# File 'lib/net/flickr/photo.rb', line 123

def owner
  @owner
end

#page_urlObject

Gets the URL of this photo’s Flickr photo page.



128
129
130
# File 'lib/net/flickr/photo.rb', line 128

def page_url
  return "http://www.flickr.com/photos/#{@owner}/#{@id}"
end

#poolsObject

flickr.photos.getAllContexts

Raises:

  • (NotImplementedError)


133
134
135
# File 'lib/net/flickr/photo.rb', line 133

def pools
  raise NotImplementedError
end

#postedObject

Gets the time this photo was posted to Flickr.



138
139
140
141
# File 'lib/net/flickr/photo.rb', line 138

def posted
  info_xml = get_info
  return Time.at(info_xml.at('dates')[:posted].to_i)
end

#posted=(time) ⇒ Object

flickr.photos.setDates



144
145
# File 'lib/net/flickr/photo.rb', line 144

def posted=(time)
end

#previousObject Also known as: prev

Gets the previous photo in the owner’s photo stream, or nil if this is the first photo in the stream.



149
150
151
152
153
154
155
# File 'lib/net/flickr/photo.rb', line 149

def previous
  context_xml = get_context
  prev_xml = context_xml.at('prevphoto')
  
  return Photo.new(@flickr, prev_xml) if prev_xml[:id] != '0'
  return nil
end

#public?Boolean

Whether or not this photo is visible to the general public.

Returns:

  • (Boolean)


160
161
162
163
# File 'lib/net/flickr/photo.rb', line 160

def public?
  get_info if @is_public.nil?
  return @is_public
end

#setsObject

flickr.photos.getAllContexts

Raises:

  • (NotImplementedError)


166
167
168
# File 'lib/net/flickr/photo.rb', line 166

def sets
  raise NotImplementedError
end

#sizesObject

flickr.photos.getSizes

Raises:

  • (NotImplementedError)


171
172
173
# File 'lib/net/flickr/photo.rb', line 171

def sizes
  raise NotImplementedError
end

#source_url(size = :medium) ⇒ Object

Gets the source URL for this photo at one of the following specified sizes. Returns nil if the specified size is not available.

:square

75x75px

:thumb

100px on longest side

:small

240px on longest side

:medium

500px on longest side

:large

1024px on longest side (not available for all images)

:original

original image in original file format



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/net/flickr/photo.rb', line 184

def source_url(size = :medium)
  suffix = SIZE_SUFFIX[size]
  
  case size
    when :medium
      return "http://farm#{@farm}.static.flickr.com/#{@server}/#{@id}_" +
          "#{@secret}.jpg"
    
    when :original
      info_xml = get_info
      
      original_secret = info_xml[:originalsecret]
      original_format = info_xml[:originalformat]
      
      return nil if original_secret.nil? || original_format.nil? 
      return "http://farm#{@farm}.static.flickr.com/#{@server}/#{@id}_" +
          "#{original_secret}_o.#{original_format}"

    else
      return "http://farm#{@farm}.static.flickr.com/#{@server}/#{@id}_" +
          "#{@secret}_#{suffix}.jpg"
  end
end

#tagsObject

flickr.photos.getInfo

Raises:

  • (NotImplementedError)


209
210
211
# File 'lib/net/flickr/photo.rb', line 209

def tags
  raise NotImplementedError
end

#takenObject

Gets the time this photo was taken.



214
215
216
217
# File 'lib/net/flickr/photo.rb', line 214

def taken
  info_xml = get_info
  return Time.parse(info_xml.at('dates')[:taken])
end

#taken=(time) ⇒ Object

flickr.photos.setDates

Raises:

  • (NotImplementedError)


220
221
222
# File 'lib/net/flickr/photo.rb', line 220

def taken=(time)
  raise NotImplementedError
end

#tiffObject

flickr.photos.getExif

Raises:

  • (NotImplementedError)


225
226
227
# File 'lib/net/flickr/photo.rb', line 225

def tiff
  raise NotImplementedError
end

#titleObject

Gets this photo’s title.



230
231
232
# File 'lib/net/flickr/photo.rb', line 230

def title
  @title
end

#title=(value) ⇒ Object

Sets this photo’s title. This method requires authentication with write permission.



236
237
238
# File 'lib/net/flickr/photo.rb', line 236

def title=(value)
  set_meta(value, description)
end