Class: Thumbnailer::Flickr

Inherits:
Base
  • Object
show all
Defined in:
lib/thumbnailer/sites/flickr.rb

Instance Attribute Summary

Attributes inherited from Base

#embed_url, #small_thumb_image, #thumb_image

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Flickr

Returns a new instance of Flickr.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/thumbnailer/sites/flickr.rb', line 3

def initialize(uri)
  if uri.path =~ /\/photos\/.*?\/\d+/
    image_id = uri.path.split(/\/photos\/.*?\/(\d+)/)[1]
    data = open("http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=#{FLICKR_KEY}&photo_id=#{image_id}")
    doc = XML::Parser.string(data.read).parse.find("//rsp/sizes/size")
    doc.each { |item|
      case item['label']
        when 'Thumbnail'
          @thumb_image = item['source']
        when 'Square'
          @small_thumb_image = item['source']
        when 'Medium'
          @embed_url = item['source']
      end
    }
  end
end