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



37
38
39
# File 'lib/myflickr/photo.rb', line 37

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



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/myflickr/photo.rb', line 22

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['raw'] }
  photo.machine_tags = (photo_call/"tag[@machine_tag=1]").map{|tag| MachineTag.from_s tag['raw'] }
  
  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

.search_tags(tags = []) ⇒ Object

Find photos by tag Tags should be an Array



17
18
19
# File 'lib/myflickr/photo.rb', line 17

def self.search_tags(tags=[])
  tags.empty? ? [] : parse(Query.api_call('flickr.photos.search', "tags=#{tags.join(',')}"))
end