thornbed 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/thornbed/providers/imgur.rb +11 -20
- data/lib/thornbed/version.rb +1 -1
- data/spec/providers/imgur_spec.rb +8 -0
- data/spec/thornbed_spec.rb +1 -16
- metadata +4 -4
@@ -6,37 +6,28 @@ module Thornbed::Providers
|
|
6
6
|
attr_accessor :pattern
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
self.pattern = /^
|
9
|
+
self.pattern = /^https?:\/\/(www\.|i\.)?imgur\.com\/(gallery\/)?(?<pid>\w{5,})(s|l|b|m|t)?(?<ptype>\.gif|\.jpg|\.jpeg|\.png)?(\?full)?$/
|
10
10
|
end
|
11
11
|
|
12
12
|
def get(url)
|
13
13
|
raise Thornbed::NotValid, url if !valid?(url)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
ptype = "jpg"
|
14
|
+
res = pattern.match(url)
|
15
|
+
pid = res[:pid]
|
16
|
+
md = /(?<pid>\w{5,})(s|l|b|m|t)$/.match(pid)
|
17
|
+
pid = md[:pid] if md else pid
|
18
|
+
ptype = res[:ptype] || ".jpg"
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
elsif thumb
|
24
|
-
pic_id = thumb[0][1..5]
|
25
|
-
elsif direct
|
26
|
-
pic_id = direct[0][1..5]
|
27
|
-
ptype = /(\.gif|\.jpg|\.jpeg|\.png)$/.match(url.path)[0][1..-1]
|
28
|
-
else
|
29
|
-
raise Thornbed::NotValid, url
|
30
|
-
end
|
20
|
+
|
21
|
+
raise Thornbed::NotValid, url if not pid
|
31
22
|
|
32
23
|
{
|
33
|
-
url: "http://i.imgur.com/#{
|
24
|
+
url: "http://i.imgur.com/#{pid}#{ptype}",
|
34
25
|
type: "photo",
|
35
26
|
provider_name: provider_name,
|
36
27
|
provider_url: "http://imgur.com",
|
37
|
-
thumbnail_url: "http://i.imgur.com/#{
|
28
|
+
thumbnail_url: "http://i.imgur.com/#{pid}s#{ptype}",
|
38
29
|
version: "1.0",
|
39
|
-
page: "http://imgur.com/#{
|
30
|
+
page: "http://imgur.com/#{pid}",
|
40
31
|
width: nil,
|
41
32
|
height: nil
|
42
33
|
}
|
data/lib/thornbed/version.rb
CHANGED
@@ -17,6 +17,7 @@ describe "Imgur" do
|
|
17
17
|
imgur.valid?('http://i.imgur.com/N2IDN.gif').should be_true
|
18
18
|
imgur.valid?('http://i.imgur.com/A0TP9s.jpg').should be_true
|
19
19
|
imgur.valid?('http://www.imgur.com/RUUuR.jpeg').should be_true
|
20
|
+
imgur.valid?('http://imgur.com/LcbbCHv').should be_true
|
20
21
|
imgur.valid?('http://imgur.com/none').should be_false
|
21
22
|
imgur.valid?('http://imgur.com/none.jpg').should be_false
|
22
23
|
imgur.valid?('http://imgur.com/a/pq0N2').should be_false
|
@@ -25,6 +26,7 @@ describe "Imgur" do
|
|
25
26
|
it "should return OEmbed hash for imgur urls" do
|
26
27
|
imgur = Thornbed::Providers::Imgur.new
|
27
28
|
res = imgur.get('http://imgur.com/gallery/A0TP9')
|
29
|
+
puts "*** #{res}"
|
28
30
|
res.should include(url: 'http://i.imgur.com/A0TP9.jpg')
|
29
31
|
|
30
32
|
res = imgur.get('http://i.imgur.com/A0TP9.png')
|
@@ -54,6 +56,12 @@ describe "Imgur" do
|
|
54
56
|
res = imgur.get('http://www.imgur.com/RUUuR.jpeg')
|
55
57
|
res.should include(url: 'http://i.imgur.com/RUUuR.jpeg')
|
56
58
|
|
59
|
+
res = imgur.get('http://imgur.com/LcbbCHv')
|
60
|
+
res.should include(url: 'http://i.imgur.com/LcbbCHv.jpg')
|
61
|
+
|
62
|
+
res = imgur.get('http://i.imgur.com/LcbbCHvs.jpg')
|
63
|
+
res.should include(url: 'http://i.imgur.com/LcbbCHv.jpg')
|
64
|
+
|
57
65
|
lambda { imgur.get('http://imgur.com/none') }.should raise_error(Thornbed::NotValid)
|
58
66
|
lambda { imgur.get('http://imgur.com/none.jpg') }.should raise_error(Thornbed::NotValid)
|
59
67
|
lambda { imgur.get('http://imgur.com/a/pq0N2') }.should raise_error(Thornbed::NotValid)
|
data/spec/thornbed_spec.rb
CHANGED
@@ -2,22 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Thornbed do
|
4
4
|
it "should rely on ruby-oembed when querying for a oembed provider" do
|
5
|
-
good_response = {
|
6
|
-
"provider_url"=>"http://www.youtube.com/",
|
7
|
-
"thumbnail_url"=>"http://i1.ytimg.com/vi/xJbJayhYxG4/hqdefault.jpg",
|
8
|
-
"title"=>"How can I know if God Exists?",
|
9
|
-
"html"=>
|
10
|
-
"<iframe width=\"459\" height=\"344\" src=\"http://www.youtube.com/embed/xJbJayhYxG4?fs=1&feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
|
11
|
-
"author_name"=>"radhanathswamionline",
|
12
|
-
"height"=>344,
|
13
|
-
"thumbnail_width"=>480,
|
14
|
-
"width"=>459,
|
15
|
-
"version"=>"1.0",
|
16
|
-
"author_url"=>"http://www.youtube.com/user/radhanathswamionline",
|
17
|
-
"provider_name"=>"YouTube",
|
18
|
-
"type"=>"video",
|
19
|
-
"thumbnail_height"=>360
|
20
|
-
}
|
5
|
+
good_response = {"thumbnail_width"=>480, "author_url"=>"http://www.youtube.com/user/radhanathswamionline", "version"=>"1.0", "type"=>"video", "thumbnail_height"=>360, "provider_url"=>"http://www.youtube.com/", "thumbnail_url"=>"http://i1.ytimg.com/vi/xJbJayhYxG4/hqdefault.jpg", "html"=>"<iframe width=\"459\" height=\"344\" src=\"http://www.youtube.com/embed/xJbJayhYxG4?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>", "provider_name"=>"YouTube", "height"=>344, "title"=>"How can I know if God Exists?", "width"=>459, "author_name"=>"Balarama Lila Das"}
|
21
6
|
FakeWeb.register_uri(:get, /http(s)?:\/\/*(\.)?google\.com\/*/, body: good_response)
|
22
7
|
url = "http://www.youtube.com/watch?v=xJbJayhYxG4&feature=g-vrec"
|
23
8
|
res = Thornbed.get(url)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thornbed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-oembed
|
@@ -170,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
170
|
version: '0'
|
171
171
|
segments:
|
172
172
|
- 0
|
173
|
-
hash:
|
173
|
+
hash: -3319635208009761846
|
174
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
175
|
none: false
|
176
176
|
requirements:
|
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
179
|
version: '0'
|
180
180
|
segments:
|
181
181
|
- 0
|
182
|
-
hash:
|
182
|
+
hash: -3319635208009761846
|
183
183
|
requirements: []
|
184
184
|
rubyforge_project:
|
185
185
|
rubygems_version: 1.8.24
|