Class: Flickrip::FlickrImage
- Inherits:
-
Object
- Object
- Flickrip::FlickrImage
- Defined in:
- lib/flickrip/flickr_image.rb
Instance Method Summary collapse
- #compute_page_url_for_user_imageid_size(user, imageid, size) ⇒ Object
- #image_for_size(size = "l", allow_redirect = false) ⇒ Object
-
#initialize(url) ⇒ FlickrImage
constructor
A new instance of FlickrImage.
- #largest_image ⇒ Object
- #original_image ⇒ Object
Constructor Details
#initialize(url) ⇒ FlickrImage
Returns a new instance of FlickrImage.
8 9 10 |
# File 'lib/flickrip/flickr_image.rb', line 8 def initialize(url) @url = url end |
Instance Method Details
#compute_page_url_for_user_imageid_size(user, imageid, size) ⇒ Object
44 45 46 |
# File 'lib/flickrip/flickr_image.rb', line 44 def compute_page_url_for_user_imageid_size(user, imageid, size) "http://www.flickr.com/photos/#{user}/#{imageid}/sizes/#{size}/" end |
#image_for_size(size = "l", allow_redirect = false) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/flickrip/flickr_image.rb', line 12 def image_for_size(size="l",allow_redirect=false) #TODO: if size is a symbol (.sym?), then convert it to the character representation toks = Flickrip::UrlParser.parse @url if toks.has_key?(:user) && toks.has_key?(:imageid) pageurl = compute_page_url_for_user_imageid_size toks[:user], toks[:imageid], size begin page = Nokogiri::HTML( open( pageurl, :redirect => allow_redirect ) ) src = page.css("div#allsizes-photo > img").first.attributes["src"].value return open( src ) rescue Exception => ex if ex.class == OpenURI::HTTPRedirect # Original image size not found end # TODO: Raise NonFlickrImageUrl exception # TODO: if there is a 404 or 302 error, or a Flickr unauthorized request, then # the file size requested does not exist. Raise InvalidFlickrImageSize exception end else # TODO: Raise NonFlickrImageUrl exception end end |
#largest_image ⇒ Object
39 40 41 42 |
# File 'lib/flickrip/flickr_image.rb', line 39 def largest_image # Let flickr try to redirect us to the largest size image image_for_size "o", true end |
#original_image ⇒ Object
35 36 37 |
# File 'lib/flickrip/flickr_image.rb', line 35 def original_image image_for_size "o" end |