Class: Myflickr::Photo

Inherits:
Struct
  • Object
show all
Defined in:
lib/myflickr/photo.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



2
3
4
# File 'lib/myflickr/photo.rb', line 2

def description
  @description
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



2
3
4
# File 'lib/myflickr/photo.rb', line 2

def id
  @id
end

#machine_tagsObject

Returns the value of attribute machine_tags

Returns:

  • (Object)

    the current value of machine_tags



2
3
4
# File 'lib/myflickr/photo.rb', line 2

def machine_tags
  @machine_tags
end

#sizesObject (readonly)

Get the photo sizes for the photo in an array



31
32
33
# File 'lib/myflickr/photo.rb', line 31

def sizes
  @sizes
end

#tagsObject

Returns the value of attribute tags

Returns:

  • (Object)

    the current value of tags



2
3
4
# File 'lib/myflickr/photo.rb', line 2

def tags
  @tags
end

#takenObject

Returns the value of attribute taken

Returns:

  • (Object)

    the current value of taken



2
3
4
# File 'lib/myflickr/photo.rb', line 2

def taken
  @taken
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



2
3
4
# File 'lib/myflickr/photo.rb', line 2

def title
  @title
end

Class Method Details

.find(id) ⇒ Object

Find will grab all sizes of images, process the tags and standard attributes of a photo



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/myflickr/photo.rb', line 16

def self.find(id)
  photo_call = Query.api_call('flickr.photos.getInfo', "photo_id=#{id}")
  
  # Set basic attributes
  photo = Photo.new(id, *%w(title description).map {|a| (photo_call/a).inner_text })
  photo.taken = Time.parse(photo_call.at(:dates)['taken'])
  
  # Set tags for photo
  photo.tags = (photo_call/"tag[@machine_tag=0]").map{|tag| Tag.new tag.inner_text }
  photo.machine_tags = (photo_call/"tag[@machine_tag=1]").map{|tag| MachineTag.from_s tag.inner_text }
  
  return photo
end

.recentObject

Get recent photos



6
7
8
# File 'lib/myflickr/photo.rb', line 6

def self.recent
  parse(Query.api_call('flickr.photos.search'))
end

.search(search_string) ⇒ Object

Find a collection of photos by text



11
12
13
# File 'lib/myflickr/photo.rb', line 11

def self.search(search_string)
  parse(Query.api_call('flickr.photos.search', "text=#{search_string}"))
end