Class: Flickr::Object::Photo

Inherits:
Flickr::Object show all
Defined in:
lib/flickr/object/photo.rb,
lib/flickr/object/photo/tag.rb,
lib/flickr/object/photo/exif.rb,
lib/flickr/object/photo/note.rb,
lib/flickr/object/photo/size.rb,
lib/flickr/object/attribute_locations/photo.rb,
lib/flickr/object/attribute_locations/photo/tag.rb,
lib/flickr/object/attribute_locations/photo/exif.rb,
lib/flickr/object/attribute_locations/photo/note.rb

Overview

Probably the most important class in this library.

Sizes

It has an interface for assigning the photo's size. Current Flickr's photo sizes are:

  • Square 75/150
  • Thumbnail
  • Medium 500/640/800
  • Large 1024/1600/2048
  • Original

Important: When fetching photos, the information about the sizes (URL, width, height) isn't automatically available. If you're fetching multiple photos (e.g. using Flickr.photos.search), you need to pass :sizes => true. For individual photos, use #get_sizes.

Any of the following ways will change the photo's size to "Medium 500":

photo.medium500!
photo.medium!(500)
photo.medium!("500")

A change to photo's size affects the following attributes: #source_url, #width and #height.

You may often just want to assign the largest possible size to the photo:

photo.largest!

You may also want to assign the largest size to the photo, but that it's not larger/smaller than "Medium 500":

photo.medium500_or_smaller!
photo.medium500_at_least!

Note: The corresponding non-bang versions of the methods are also available:

photo.medium500
photo.medium(500)
photo.medium("500")
photo.largest
photo.medium500_or_smaller
photo.medium500_at_least

However, these are not recommended, since they duplicate the photo, taking up twice as much memory. Use them only if you really have to.

Defined Under Namespace

Classes: Exif, Note, Tag

Constant Summary collapse

SIZES =
[
  "Square 75", "Thumbnail", "Square 150",
  "Small 240", "Small 320",
  "Medium 500", "Medium 640", "Medium 800",
  "Large 1024", "Large 1600", "Large 2048",
  "Original",
]

Instance Attribute Summary collapse

Attributes inherited from Flickr::Object

#attributes

Instance Method Summary collapse

Methods inherited from Flickr::Object

#==, #[], #inspect, #matches?

Instance Attribute Details

#available_sizesArray[String] (readonly)

Returns:

  • (Array[String])

106
# File 'lib/flickr/object/photo.rb', line 106

attribute :available_sizes,      Array[String]

#cameraString (readonly)

Returns:

  • (String)

93
# File 'lib/flickr/object/photo.rb', line 93

attribute :camera,               String

#comments_countInteger (readonly)

Returns:

  • (Integer)

84
# File 'lib/flickr/object/photo.rb', line 84

attribute :comments_count,       Integer

#descriptionString (readonly)

Returns:

  • (String)

63
# File 'lib/flickr/object/photo.rb', line 63

attribute :description,          String

#editabilityPermissions (readonly)

Returns:


86
# File 'lib/flickr/object/photo.rb', line 86

attribute :editability,          Permissions

#exifExif (readonly)

Returns:


94
# File 'lib/flickr/object/photo.rb', line 94

attribute :exif,                 Exif

#farmInteger (readonly)

Returns:

  • (Integer)

61
# File 'lib/flickr/object/photo.rb', line 61

attribute :farm,                 Integer

#favoriteBoolean (readonly)

Returns:

  • (Boolean)

97
# File 'lib/flickr/object/photo.rb', line 97

attribute :favorite,             Boolean

#has_peopleBoolean (readonly)

Returns:

  • (Boolean)

96
# File 'lib/flickr/object/photo.rb', line 96

attribute :has_people,           Boolean

#heightInteger (readonly)

Returns:

  • (Integer)

110
# File 'lib/flickr/object/photo.rb', line 110

attribute :height,               Integer

#idString (readonly)

Returns:

  • (String)

58
# File 'lib/flickr/object/photo.rb', line 58

attribute :id,                   String

#largest_sizeString (readonly)

Returns:

  • (String)

107
# File 'lib/flickr/object/photo.rb', line 107

attribute :largest_size,         String

#licenseInteger (readonly)

Returns:

  • (Integer)

64
# File 'lib/flickr/object/photo.rb', line 64

attribute :license,              Integer

#locationLocation (readonly)

Returns:


101
# File 'lib/flickr/object/photo.rb', line 101

attribute :location,             Location

#location_visibilityVisibility (readonly)

Returns:


102
# File 'lib/flickr/object/photo.rb', line 102

attribute :location_visibility,  Visibility

#moderateBoolean (readonly)

Returns:

  • (Boolean)

69
# File 'lib/flickr/object/photo.rb', line 69

attribute :moderate,             Boolean

#notesList[Note] (readonly)

Returns:


90
# File 'lib/flickr/object/photo.rb', line 90

attribute :notes,                List[Note]

#ownerPerson (readonly)

Returns:


75
# File 'lib/flickr/object/photo.rb', line 75

attribute :owner,                Person

#path_aliasString (readonly)

Returns:

  • (String)

99
# File 'lib/flickr/object/photo.rb', line 99

attribute :path_alias,           String

#posted_atTime (readonly)

Returns:

  • (Time)

78
# File 'lib/flickr/object/photo.rb', line 78

attribute :posted_at,            Time

#public_editabilityPermissions (readonly)

Returns:


87
# File 'lib/flickr/object/photo.rb', line 87

attribute :public_editability,   Permissions

#restrictedBoolean (readonly)

Returns:

  • (Boolean)

70
# File 'lib/flickr/object/photo.rb', line 70

attribute :restricted,           Boolean

#rotationInteger (readonly)

Returns:

  • (Integer)

104
# File 'lib/flickr/object/photo.rb', line 104

attribute :rotation,             Integer

#safeBoolean (readonly)

Returns:

  • (Boolean)

68
# File 'lib/flickr/object/photo.rb', line 68

attribute :safe,                 Boolean

#safety_levelInteger (readonly)

Returns:

  • (Integer)

67
# File 'lib/flickr/object/photo.rb', line 67

attribute :safety_level,         Integer

#secretString (readonly)

Returns:

  • (String)

59
# File 'lib/flickr/object/photo.rb', line 59

attribute :secret,               String

#serverString (readonly)

Returns:

  • (String)

60
# File 'lib/flickr/object/photo.rb', line 60

attribute :server,               String

#short_urlString (readonly)

Returns:

  • (String)

73
# File 'lib/flickr/object/photo.rb', line 73

attribute :short_url,            String

#source_urlString (readonly)

Returns:

  • (String)

109
# File 'lib/flickr/object/photo.rb', line 109

attribute :source_url,           String

#tagsList[Tag] (readonly)

Returns:


91
# File 'lib/flickr/object/photo.rb', line 91

attribute :tags,                 List[Tag]

#taken_atTime (readonly)

Returns:

  • (Time)

79
# File 'lib/flickr/object/photo.rb', line 79

attribute :taken_at,             Time

#taken_at_granularityInteger (readonly)

Returns:

  • (Integer)

80
# File 'lib/flickr/object/photo.rb', line 80

attribute :taken_at_granularity, Integer

#titleString (readonly)

Returns:

  • (String)

62
# File 'lib/flickr/object/photo.rb', line 62

attribute :title,                String

#updated_atTime (readonly)

Returns:

  • (Time)

81
# File 'lib/flickr/object/photo.rb', line 81

attribute :updated_at,           Time

#uploaded_atTime (readonly)

Returns:

  • (Time)

77
# File 'lib/flickr/object/photo.rb', line 77

attribute :uploaded_at,          Time

#urlString (readonly)

Returns:

  • (String)

72
# File 'lib/flickr/object/photo.rb', line 72

attribute :url,                  String

#usagePermissions (readonly)

Returns:


88
# File 'lib/flickr/object/photo.rb', line 88

attribute :usage,                Permissions

#views_countInteger (readonly)

Returns:

  • (Integer)

83
# File 'lib/flickr/object/photo.rb', line 83

attribute :views_count,          Integer

#visibilityVisibility (readonly)

Returns:


65
# File 'lib/flickr/object/photo.rb', line 65

attribute :visibility,           Visibility

#widthInteger (readonly)

Returns:

  • (Integer)

111
# File 'lib/flickr/object/photo.rb', line 111

attribute :width,                Integer

Instance Method Details

#add_tags(tags, params = {}) ⇒ response

Returns:

  • (response)

See Also:


294
295
296
# File 'lib/flickr/object/photo.rb', line 294

def add_tags(tags, params = {})
  api.add_tags(id, tags, params)
end

#delete(params = {}) ⇒ response

Returns:

  • (response)

See Also:


268
269
270
# File 'lib/flickr/object/photo.rb', line 268

def delete(params = {})
  api.delete(id, params)
end

#get_exif!(params = {}) ⇒ self

Returns:

  • (self)

See Also:


251
252
253
254
# File 'lib/flickr/object/photo.rb', line 251

def get_exif!(params = {})
  photo = api.get_exif(id, params)
  update(photo.attributes)
end

#get_favorites(params = {}) ⇒ Flickr::Object::List<Flickr::Object::Person>


260
261
262
# File 'lib/flickr/object/photo.rb', line 260

def get_favorites(params = {})
  api.get_favorites(id, params)
end

#get_info!(params = {}) ⇒ self

Returns:

  • (self)

See Also:


233
234
235
236
# File 'lib/flickr/object/photo.rb', line 233

def get_info!(params = {})
  photo = api.get_info(id, params)
  update(photo.attributes)
end

#get_sizes!(params = {}) ⇒ self

Returns:

  • (self)

See Also:


242
243
244
245
# File 'lib/flickr/object/photo.rb', line 242

def get_sizes!(params = {})
  photo = api.get_sizes(id, params)
  update(photo.attributes)
end

#largestself

Returns:

  • (self)

212
213
214
# File 'lib/flickr/object/photo.rb', line 212

def largest
  dup.largest!
end

#largest!self

Returns:

  • (self)

205
206
207
# File 'lib/flickr/object/photo.rb', line 205

def largest!
  size! largest_size
end

#remove_tag(tag_or_id, params = {}) ⇒ response

Returns:

  • (response)

See Also:


302
303
304
# File 'lib/flickr/object/photo.rb', line 302

def remove_tag(tag_or_id, params = {})
  api.remove_tag(id, tag_or_id, params)
end

#set_content_type(content_type, params = {}) ⇒ response Also known as: content_type=

Returns:

  • (response)

See Also:


276
277
278
# File 'lib/flickr/object/photo.rb', line 276

def set_content_type(content_type, params = {})
  api.set_content_type(id, content_type, params)
end

#set_dates(params = {}) ⇒ response

Returns:

  • (response)

See Also:


310
311
312
# File 'lib/flickr/object/photo.rb', line 310

def set_dates(params = {})
  api.set_dates(id, params)
end

#set_license(license_id, params = {}) ⇒ response

Returns:

  • (response)

See Also:


342
343
344
# File 'lib/flickr/object/photo.rb', line 342

def set_license(license_id, params = {})
  api.set_license(id, license_id, params)
end

#set_meta(params = {}) ⇒ response

Returns:

  • (response)

See Also:


318
319
320
# File 'lib/flickr/object/photo.rb', line 318

def set_meta(params = {})
  api.set_meta(id, params)
end

#set_permissions(params = {}) ⇒ response

Returns:

  • (response)

See Also:


326
327
328
# File 'lib/flickr/object/photo.rb', line 326

def set_permissions(params = {})
  api.set_permissions(id, params)
end

#set_safety_level(params = {}) ⇒ response

Returns:

  • (response)

See Also:


334
335
336
# File 'lib/flickr/object/photo.rb', line 334

def set_safety_level(params = {})
  api.set_safety_level(id, params)
end

#set_tags(tags, params = {}) ⇒ response Also known as: tags=

Returns:

  • (response)

See Also:


285
286
287
# File 'lib/flickr/object/photo.rb', line 285

def set_tags(tags, params = {})
  api.set_tags(id, tags, params)
end

#sizeString

The size of the photo, can be changed with modifer methods (see the definition of this class for details).

Returns:

  • (String)

127
128
129
# File 'lib/flickr/object/photo.rb', line 127

def size
  @size.name if @size
end

#size!(name) ⇒ Object

Changes the size of the photo.


219
220
221
222
223
224
225
226
227
# File 'lib/flickr/object/photo.rb', line 219

def size!(name)
  if name != nil and not Size.exists?(name)
    raise ArgumentError, "\"#{name}\" isn't a valid photo size"
  end

  @size = Size.new(name)

  self
end