Module: SnipSnap
- Defined in:
- lib/snip_snap.rb,
lib/snip_snap/image.rb,
lib/snip_snap/imgly.rb,
lib/snip_snap/yfrog.rb,
lib/snip_snap/client.rb,
lib/snip_snap/flickr.rb,
lib/snip_snap/skitch.rb,
lib/snip_snap/twitgoo.rb,
lib/snip_snap/twitpic.rb,
lib/snip_snap/version.rb
Overview
SnipSnap
This is a small Ruby library that allows you to extract images from the more popular image sharing services. Currently supported services are:
-
Img.ly
-
Skitch
-
Twitpic
-
Yfrog
-
Flickr
-
Twitgoo
To use, just point it at a URL:
require 'rubygems'
require 'snip_snap'
client = SnipSnap.from_url('http://yfrog.com/7hb9lj')
puts client.image_url
That’s it.
Defined Under Namespace
Modules: Client, Version Classes: Flickr, Image, Imgly, Skitch, Twitgoo, Twitpic, Yfrog
Class Method Summary collapse
-
.class_name_for(url) ⇒ Object
:nodoc:.
-
.flickr_api_key=(key) ⇒ Object
Set the Flickr API key for use by the underlying Flickr API library.
-
.from_url(url) ⇒ Object
Use the correct class to handle image extraction for a given URL.
-
.host_map ⇒ Object
:nodoc:.
Class Method Details
.class_name_for(url) ⇒ Object
:nodoc:
57 58 59 60 61 62 63 64 |
# File 'lib/snip_snap.rb', line 57 def self.class_name_for(url) # :nodoc: uri = URI.parse(url) subject = "#{uri.host}#{uri.path}" match = host_map.detect {|k,v| Regexp.new(k) =~ subject } match.nil? ? 'Image' : match[1] end |
.flickr_api_key=(key) ⇒ Object
Set the Flickr API key for use by the underlying Flickr API library
67 68 69 |
# File 'lib/snip_snap.rb', line 67 def self.flickr_api_key=(key) Fleakr.api_key = key end |
.from_url(url) ⇒ Object
Use the correct class to handle image extraction for a given URL
53 54 55 |
# File 'lib/snip_snap.rb', line 53 def self.from_url(url) const_get(class_name_for(url)).new(url) end |
.host_map ⇒ Object
:nodoc:
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/snip_snap.rb', line 41 def self.host_map # :nodoc: { /^(www\.)?skitch\.com/ => 'Skitch', /img\.ly\/[0-9a-z]+$/i => 'Imgly', /^twitpic\.com/ => 'Twitpic', /yfrog\.(com|us)/ => 'Yfrog', /^(flic\.kr|(www\.)?flickr.com)/ => 'Flickr', /^twitgoo\.com/ => 'Twitgoo' } end |