Class: Aviary::ImageHost::Flickr

Inherits:
Aviary::ImageHost show all
Defined in:
lib/aviary/image_host/flickr.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Aviary::ImageHost

available, match, matches

Class Method Details

.api_key(key = nil) ⇒ Object

Get and set the API key. Passing an argument sets the API key. Passing nothing gets the API key.

Returns api key.



12
13
14
15
# File 'lib/aviary/image_host/flickr.rb', line 12

def self.api_key(key = nil)
  @api_key = key if key
  @api_key
end

.available?Boolean

True if the API key has been set.

Returns boolean.

Returns:

  • (Boolean)


20
21
22
# File 'lib/aviary/image_host/flickr.rb', line 20

def self.available?
  !api_key.nil?
end

.match_and_create(status) ⇒ Object



24
25
26
27
28
29
# File 'lib/aviary/image_host/flickr.rb', line 24

def self.match_and_create(status)
  match(status.text).each do |capture|
    create :token  => (capture =~ /^\d+$/ ? Base58.encode(capture.to_i) : capture),
           :status => status
  end
end

Instance Method Details

#hrefObject



31
32
33
# File 'lib/aviary/image_host/flickr.rb', line 31

def href
  "http://flic.kr/p/#{self.token}"
end

#set_metaObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/aviary/image_host/flickr.rb', line 40

def set_meta
  uri = URI.parse "http://api.flickr.com/services/rest/?method=flickr" +
                  ".photos.getInfo&api_key=#{self.class.api_key}" + 
                  "&photo_id=#{Base58.decode(self.token)}"  
  photo = Nokogiri::XML(open(uri)).css('photo')
  self.meta = {
    :farm_id   => photo.first['farm'],
    :server_id => photo.first['server'],
    :id        => photo.first['id'],
    :secret    => photo.first['secret']
  }
end

#srcObject



35
36
37
38
# File 'lib/aviary/image_host/flickr.rb', line 35

def src
  "http://farm#{self.meta[:farm_id]}.static.flickr.com/" + 
  "#{self.meta[:server_id]}/#{self.meta[:id]}_#{self.meta[:secret]}_z.jpg"
end