Class: Flickr::Photo

Inherits:
Base
  • Object
show all
Defined in:
lib/flickr-wrapper/photo.rb

Defined Under Namespace

Classes: Size

Instance Attribute Summary collapse

Attributes inherited from Base

#user_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#photos, #sets

Constructor Details

#initialize(id, title, description) ⇒ Photo

Returns a new instance of Photo.



6
7
8
# File 'lib/flickr-wrapper/photo.rb', line 6

def initialize(id, title, description)
  @id, @title, @description = id, title, description
end

Instance Attribute Details

#callerObject

Returns the value of attribute caller.



4
5
6
# File 'lib/flickr-wrapper/photo.rb', line 4

def caller
  @caller
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/flickr-wrapper/photo.rb', line 4

def description
  @description
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/flickr-wrapper/photo.rb', line 4

def id
  @id
end

#machine_tagsObject

Returns the value of attribute machine_tags.



4
5
6
# File 'lib/flickr-wrapper/photo.rb', line 4

def machine_tags
  @machine_tags
end

#postedObject

Returns the value of attribute posted.



4
5
6
# File 'lib/flickr-wrapper/photo.rb', line 4

def posted
  @posted
end

#tagsObject

Returns the value of attribute tags.



4
5
6
# File 'lib/flickr-wrapper/photo.rb', line 4

def tags
  @tags
end

#takenObject

Returns the value of attribute taken.



4
5
6
# File 'lib/flickr-wrapper/photo.rb', line 4

def taken
  @taken
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/flickr-wrapper/photo.rb', line 4

def title
  @title
end

Class Method Details

.find(user_id, id) ⇒ Object

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



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

def self.find(user_id, id)
  photo_call = Flickr::Query.new(user_id).execute('flickr.photos.getInfo', :photo_id => id)
    
  # Set basic attributes
  photo = self.new(id, *%w(title description).map {|a| (photo_call/a).inner_text })
  photo.taken = Time.parse(photo_call.at(:dates)['taken'])
  photo.posted = Time.at(photo_call.at(:dates)['posted'].to_i)

  # Set tags for photo
  photo.tags = (photo_call/"tag[@machine_tag=0]").map{|tag| Flickr::Tag.new tag['raw'] }
  photo.machine_tags = (photo_call/"tag[@machine_tag=1]").map{|tag| Flickr::MachineTag.from_s tag['raw'] }

  return photo
end

.list(user_id) ⇒ Object



10
11
12
# File 'lib/flickr-wrapper/photo.rb', line 10

def self.list(user_id)
  search(user_id)
end

.search(user_id, search_options = {}) ⇒ Object

Find a collection of photos by text Search options should be hashes with string values or arrays for multiple values



32
33
34
# File 'lib/flickr-wrapper/photo.rb', line 32

def self.search(user_id, search_options={})
  parse(user_id, Flickr::Query.new(user_id).execute('flickr.photos.search', search_options))
end

Instance Method Details

#sizesObject



36
37
38
39
40
41
42
# File 'lib/flickr-wrapper/photo.rb', line 36

def sizes
  hash = {}
  (Flickr::Query.new(user_id).execute('flickr.photos.getSizes', :photo_id => id)/:size).parallel_each(Flickr::MAX_THREADS) do |size|
    hash[size['label'].downcase.to_sym] = Size.new(*%w(width height source url).map{|a| size[a]})
  end
  return hash
end