snip-snap 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@
5
5
  SnipSnap is a Ruby library that will allow you to extract the URL of an image from
6
6
  one of many popular image sharing services. Just give it the shortened URL and it can
7
7
  give you the full URL to the embedded image. This library currently supports Img.ly,
8
- Skitch, Twitpic, Flickr, and Yfrog - others are coming.
8
+ Skitch, Twitpic, Flickr, Yfrog, and Twitgoo - others are coming.
9
9
 
10
10
  == Installation
11
11
 
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ spec = Gem::Specification.new do |s|
14
14
  s.author = 'Patrick Reagan'
15
15
  s.email = 'reaganpr@gmail.com'
16
16
  s.homepage = 'http://sneaq.net'
17
- s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
17
+ s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*") - ['test/flickr_api_key']
18
18
  # s.executables = ['snip-snap']
19
19
 
20
20
  s.add_dependency('curb', '>= 0.5.1.0')
@@ -11,6 +11,7 @@ require 'snip_snap/imgly'
11
11
  require 'snip_snap/yfrog'
12
12
  require 'snip_snap/twitpic'
13
13
  require 'snip_snap/flickr'
14
+ require 'snip_snap/twitgoo'
14
15
  require 'snip_snap/image'
15
16
 
16
17
  # = SnipSnap
@@ -23,6 +24,7 @@ require 'snip_snap/image'
23
24
  # * Twitpic
24
25
  # * Yfrog
25
26
  # * Flickr
27
+ # * Twitgoo
26
28
  #
27
29
  # To use, just point it at a URL:
28
30
  #
@@ -38,11 +40,12 @@ module SnipSnap
38
40
 
39
41
  def self.host_map # :nodoc:
40
42
  {
41
- /^(www\.)?skitch.com/ => 'Skitch',
42
- /img.ly\/[0-9a-z]+$/i => 'Imgly',
43
- /^twitpic.com/ => 'Twitpic',
44
- /yfrog\.(com|us)/ => 'Yfrog',
45
- /^(flic.kr|(www\.)?flickr.com)/ => 'Flickr'
43
+ /^(www\.)?skitch\.com/ => 'Skitch',
44
+ /img\.ly\/[0-9a-z]+$/i => 'Imgly',
45
+ /^twitpic\.com/ => 'Twitpic',
46
+ /yfrog\.(com|us)/ => 'Yfrog',
47
+ /^(flic\.kr|(www\.)?flickr.com)/ => 'Flickr',
48
+ /^twitgoo\.com/ => 'Twitgoo'
46
49
  }
47
50
  end
48
51
 
@@ -5,11 +5,18 @@ module SnipSnap
5
5
 
6
6
  request_method :head
7
7
 
8
+ def endpoint_url
9
+ response.last_effective_url
10
+ end
11
+
8
12
  def identifier
9
- url = response.last_effective_url
10
- url.match(/([^\/]+)\/$/)[1]
13
+ pattern = /^http:\/\/(?:www\.)?flickr.com\/photos\/[^\/]+\/(\d+)/
14
+ match = endpoint_url.match(pattern)
15
+
16
+ match[1] unless match.nil?
11
17
  end
12
18
 
19
+ # TODO: Handle case when this fetch fails (e.g. invalid photo ID)
13
20
  def photo
14
21
  Fleakr::Objects::Photo.find_by_id(identifier)
15
22
  end
@@ -0,0 +1,17 @@
1
+ module SnipSnap
2
+ class Twitgoo
3
+
4
+ include Client
5
+
6
+ def url
7
+ identifier = @url.match(/([^\/]+)$/)[1]
8
+ "http://twitgoo.com/api/message/info/#{identifier}"
9
+ end
10
+
11
+ def image_url
12
+ body = response.body_str
13
+ body.match(/<imageurl>(.+)<\/imageurl>/)[1]
14
+ end
15
+
16
+ end
17
+ end
@@ -3,7 +3,7 @@ module SnipSnap
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 3
6
+ TINY = 4
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?><rsp status="ok">
2
+ <username>darthapo</username>
3
+ <mediaid>2r5hv</mediaid>
4
+ <mediaurl>http://twitgoo.com/</mediaurl>
5
+ <imageurl>http://i29.tinypic.com/9sxqpx.png</imageurl>
6
+ <thumburl>http://i29.tinypic.com/9sxqpx_th.png</thumburl>
7
+ </rsp>
@@ -16,7 +16,7 @@ class ResponseTest < Test::Unit::TestCase
16
16
 
17
17
  should "be able to find the image in a Skitch URL" do
18
18
  client = SnipSnap.from_url('http://skitch.com/reagent/bh4ei/inbox-gmail-29466-messages-130-unread')
19
- client.image_url.should == 'http://img.skitch.com/20090909-bw3tnhse6rhn68erk6wpa882ea.jpg'
19
+ client.image_url.should =~ /^http:\/\/img\.skitch\.com\/\d{8}-bw3tnhse6rhn68erk6wpa882ea\.jpg$/
20
20
  end
21
21
 
22
22
  should "be able to find an image in a shortened Yfrog URL" do
@@ -49,11 +49,26 @@ class ResponseTest < Test::Unit::TestCase
49
49
  client.image_url.should == 'http://farm4.static.flickr.com/3449/3212555327_14d2d3f8b0.jpg'
50
50
  end
51
51
 
52
+ should "be able to find an image in an expanded Flickr URL without a trailing slash" do
53
+ client = SnipSnap.from_url('http://www.flickr.com/photos/sares/3579062921')
54
+ client.image_url.should == 'http://farm3.static.flickr.com/2439/3579062921_d5da30b0a9.jpg'
55
+ end
56
+
57
+ should "be able to find an image in an expanded Flickr photo's set URL" do
58
+ client = SnipSnap.from_url('http://www.flickr.com/photos/viget/3852378037/in/set-72157621982815973/')
59
+ client.image_url.should == 'http://farm3.static.flickr.com/2482/3852378037_11e9e3b14b.jpg'
60
+ end
61
+
52
62
  should "be able to find an image in an img.ly URL" do
53
63
  client = SnipSnap.from_url('http://img.ly/3ey')
54
64
  client.image_url.should =~ /http:\/\/img\.ly\/media\/12434\/large_ChillPill13\.jpg/
55
65
  end
56
66
 
67
+ should "be able to find an image in a Twitgoo URL" do
68
+ client = SnipSnap.from_url('http://twitgoo.com/2r5hv')
69
+ client.image_url.should == 'http://i29.tinypic.com/9sxqpx.png'
70
+ end
71
+
57
72
  should "be able to find an image from a URL with a correct MIME type" do
58
73
  client = SnipSnap.from_url('http://img.ly/media/12434/large_ChillPill13.jpg')
59
74
  client.image_url.should == 'http://img.ly/media/12434/large_ChillPill13.jpg'
@@ -14,16 +14,48 @@ module SnipSnap
14
14
  f.should be_image
15
15
  end
16
16
 
17
- should "know the identifier for the photo" do
17
+ should "know the endpoint URL" do
18
18
  response = stub()
19
19
  response.stubs(:last_effective_url).with().returns(@expanded_url)
20
-
20
+
21
21
  f = SnipSnap::Flickr.new(@url)
22
22
  f.stubs(:response).with().returns(response)
23
+
24
+ f.endpoint_url.should == @expanded_url
25
+ end
26
+
27
+ should "know the identifier for the basic photo URL" do
28
+ f = SnipSnap::Flickr.new('')
29
+ f.stubs(:endpoint_url).with().returns('http://www.flickr.com/photos/northernraven/3317998738/')
30
+
31
+ f.identifier.should == '3317998738'
32
+ end
33
+
34
+ should "know the identifier for the basic photo URL without a trailing slash" do
35
+ f = SnipSnap::Flickr.new('')
36
+ f.stubs(:endpoint_url).with().returns('http://www.flickr.com/photos/northernraven/3317998738')
23
37
 
24
38
  f.identifier.should == '3317998738'
25
39
  end
26
40
 
41
+ should "return nil if it can't find the identifier in the URL" do
42
+ url = 'http://www.flickr.com/photos/viget'
43
+
44
+ f = SnipSnap::Flickr.new('')
45
+ f.stubs(:endpoint_url).with().returns(url)
46
+
47
+ f.identifier.should be_nil
48
+ end
49
+
50
+ should "know the identifier for the photo URL as part of a set" do
51
+ url = 'http://www.flickr.com/photos/viget/3852378037/in/set-72157621982815973/'
52
+
53
+ f = SnipSnap::Flickr.new(@url)
54
+ f.stubs(:endpoint_url).with().returns(url)
55
+
56
+ f.identifier.should == '3852378037'
57
+ end
58
+
27
59
  should "be able to find the photo for the identifier" do
28
60
  identifier = '3317998738'
29
61
  photo = stub()
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module SnipSnap
4
+ class TwitgooTest < Test::Unit::TestCase
5
+
6
+ context "An instance of the Twitgoo class" do
7
+ setup do
8
+ @url = 'http://twitgoo.com/2r5hv'
9
+ @expanded_url = 'http://twitgoo.com/api/message/info/2r5hv'
10
+ end
11
+
12
+ should "know that it's an image" do
13
+ t = SnipSnap::Twitgoo.new(@url)
14
+ t.should be_image
15
+ end
16
+
17
+ should "have a URL derived from the source URL" do
18
+ t = SnipSnap::Twitgoo.new(@url)
19
+ t.url.should == @expanded_url
20
+ end
21
+
22
+ should "know the image URL" do
23
+ response = stub()
24
+ response.stubs(:body_str).with().returns(read_fixture('twitgoo.xml'))
25
+
26
+ t = SnipSnap::Twitgoo.new(@url)
27
+ t.stubs(:response).with().returns(response)
28
+
29
+ t.image_url.should == 'http://i29.tinypic.com/9sxqpx.png'
30
+ end
31
+
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -2,90 +2,56 @@ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class SnipSnapTest < Test::Unit::TestCase
4
4
 
5
- context "The SnipSnap module" do
5
+ def self.should_know_the_class_name_for(matcher)
6
+ url = matcher.keys.first
7
+ class_name = matcher.values.first
6
8
 
7
- should "know the correct class name for a Skitch URL" do
8
- url = 'http://skitch.com/reagent/bh4ei/bleeergh'
9
- SnipSnap.class_name_for(url).should == 'Skitch'
10
- end
11
-
12
- should "know the correct class name for an Imgly URL" do
13
- url = 'http://img.ly/3ey'
14
- SnipSnap.class_name_for(url).should == 'Imgly'
15
- end
16
-
17
- should "know the correct class name for a Twitpic URL" do
18
- url = 'http://twitpic.com/203o0'
19
- SnipSnap.class_name_for(url).should == 'Twitpic'
20
- end
21
-
22
- should "know the correct class name for a Yfrog.com URL" do
23
- url = 'http://yfrog.com/ahb97j'
24
- SnipSnap.class_name_for(url).should == 'Yfrog'
25
- end
26
-
27
- should "know the correct class name for a Yfrog.us URL" do
28
- url = 'http://yfrog.us/ahb97j'
29
- SnipSnap.class_name_for(url).should == 'Yfrog'
30
- end
31
-
32
- should "know the correct class name for an expanded Yfrog URL" do
33
- url = 'http://img377.yfrog.com/i/b97.jpg/'
34
- SnipSnap.class_name_for(url).should == 'Yfrog'
35
- end
36
-
37
- should "know the correct class name for a Flickr URL" do
38
- url = 'http://flic.kr/p/64cBqN'
39
- SnipSnap.class_name_for(url).should == 'Flickr'
40
- end
41
-
42
- should "use the default class when it can't match on other URLs" do
43
- url = 'http://example.com/image.jpg'
44
- SnipSnap.class_name_for(url).should == 'Image'
45
- end
46
-
47
- should "be able to create an instance of the Skitch class with the supplied URL" do
48
- url = 'http://skitch.com/reagent/bh4ei/bleeergh'
49
- SnipSnap::Skitch.expects(:new).with(url).returns('skitch')
50
-
51
- SnipSnap.from_url(url).should == 'skitch'
9
+ should "know that the class name for #{url} is #{class_name}" do
10
+ SnipSnap.class_name_for(url).should == class_name
52
11
  end
12
+ end
13
+
14
+ def self.should_create_an_instance_for(matcher)
15
+ url = matcher.keys.first
16
+ class_name = matcher.values.first
53
17
 
54
- should "be able to create an instance of the Imgly class with the supplied URL" do
55
- url = 'http://img.ly/3ey'
56
- SnipSnap::Imgly.expects(:new).with(url).returns('imgly')
18
+ should "be able to create an instance of the #{class_name} class for the url: '#{url}'" do
19
+ klass = SnipSnap.const_get(class_name)
20
+ klass.expects(:new).with(url).returns('instance')
57
21
 
58
- SnipSnap.from_url(url).should == 'imgly'
22
+ SnipSnap.from_url(url).should == 'instance'
59
23
  end
60
24
 
61
- should "be able to create an instance of the Twitpic class with the supplied URL" do
62
- url = 'http://twitpic.com/203o0'
63
- SnipSnap::Twitpic.expects(:new).with(url).returns('twitpic')
64
-
65
- SnipSnap.from_url(url).should == 'twitpic'
66
- end
25
+ end
67
26
 
68
- should "be able to create an instance of the Yfrog class with the supplied URL" do
69
- url = 'http://yfrog.com/ahb97j'
70
- SnipSnap::Yfrog.expects(:new).with(url).returns('yfrog')
27
+ context "The SnipSnap module" do
71
28
 
72
- SnipSnap.from_url(url).should == 'yfrog'
73
- end
29
+ should_know_the_class_name_for 'http://skitch.com/reagent/bh4ei/bleeergh' => 'Skitch'
30
+ should_know_the_class_name_for 'http://img.ly/3ey' => 'Imgly'
31
+ should_know_the_class_name_for 'http://twitpic.com/203o0' => 'Twitpic'
32
+ should_know_the_class_name_for 'http://yfrog.com/ahb97j' => 'Yfrog'
33
+ should_know_the_class_name_for 'http://yfrog.us/ahb97j' => 'Yfrog'
34
+ should_know_the_class_name_for 'http://img377.yfrog.com/i/b97.jpg/' => 'Yfrog'
35
+ should_know_the_class_name_for 'http://flic.kr/p/64cBqN' => 'Flickr'
36
+ should_know_the_class_name_for 'http://www.flickr.com/photos/viget/3852378037/' => 'Flickr'
37
+ should_know_the_class_name_for 'http://twitgoo.com/2r5hv' => 'Twitgoo'
38
+ should_know_the_class_name_for 'http://example.com/image.jpg' => 'Image'
74
39
 
75
- should "be able to create an instance of the Flickr class with the supplied URL" do
76
- url = 'http://flic.kr/p/64cBqN'
77
- SnipSnap::Flickr.expects(:new).with(url).returns('flickr')
40
+ should_know_the_class_name_for 'http://www.flickr.com/photos/viget/3852378037/in/set-72157621982815973/' => 'Flickr'
78
41
 
79
- SnipSnap.from_url(url).should == 'flickr'
80
- end
81
-
82
- should "be able to create an instance of the Image class with the supplied URL" do
83
- url = 'http://example.com/image.jpg'
84
- SnipSnap::Image.expects(:new).with(url).returns('image')
42
+ should_create_an_instance_for 'http://skitch.com/reagent/bh4ei/bleeergh' => 'Skitch'
43
+ should_create_an_instance_for 'http://img.ly/3ey' => 'Imgly'
44
+ should_create_an_instance_for 'http://twitpic.com/203o0' => 'Twitpic'
45
+ should_create_an_instance_for 'http://yfrog.com/ahb97j' => 'Yfrog'
46
+ should_create_an_instance_for 'http://yfrog.us/ahb97j' => 'Yfrog'
47
+ should_create_an_instance_for 'http://img377.yfrog.com/i/b97.jpg/' => 'Yfrog'
48
+ should_create_an_instance_for 'http://flic.kr/p/64cBqN' => 'Flickr'
49
+ should_create_an_instance_for 'http://www.flickr.com/photos/viget/3852378037/' => 'Flickr'
50
+ should_create_an_instance_for 'http://twitgoo.com/2r5hv' => 'Twitgoo'
51
+ should_create_an_instance_for 'http://example.com/image.jpg' => 'Image'
52
+
53
+ should_create_an_instance_for 'http://www.flickr.com/photos/viget/3852378037/in/set-72157621982815973/' => 'Flickr'
85
54
 
86
- SnipSnap.from_url(url).should == 'image'
87
- end
88
-
89
55
  should "be able to set the Flickr API key" do
90
56
  key = 'abc123'
91
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snip-snap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Reagan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-09 00:00:00 -04:00
12
+ date: 2009-11-15 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -48,13 +48,14 @@ files:
48
48
  - lib/snip_snap/image.rb
49
49
  - lib/snip_snap/imgly.rb
50
50
  - lib/snip_snap/skitch.rb
51
+ - lib/snip_snap/twitgoo.rb
51
52
  - lib/snip_snap/twitpic.rb
52
53
  - lib/snip_snap/version.rb
53
54
  - lib/snip_snap/yfrog.rb
54
55
  - lib/snip_snap.rb
55
56
  - test/fixtures/skitch.html
57
+ - test/fixtures/twitgoo.xml
56
58
  - test/fixtures/yfrog.html
57
- - test/flickr_api_key
58
59
  - test/flickr_api_key.example
59
60
  - test/integration/response_test.rb
60
61
  - test/test_helper.rb
@@ -63,6 +64,7 @@ files:
63
64
  - test/unit/snip_snap/image_test.rb
64
65
  - test/unit/snip_snap/imgly_test.rb
65
66
  - test/unit/snip_snap/skitch_test.rb
67
+ - test/unit/snip_snap/twitgoo_test.rb
66
68
  - test/unit/snip_snap/twitpic_test.rb
67
69
  - test/unit/snip_snap/yfrog_test.rb
68
70
  - test/unit/snip_snap_test.rb
@@ -1 +0,0 @@
1
- 4e9e84830598c4e546e11a6746a58545