onebox 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.rubocop.yml +476 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +92 -0
- data/Rakefile +22 -0
- data/lib/onebox.rb +33 -0
- data/lib/onebox/engine.rb +93 -0
- data/lib/onebox/engine/amazon_onebox.rb +25 -0
- data/lib/onebox/engine/bliptv_onebox.rb +26 -0
- data/lib/onebox/engine/clikthrough_onebox.rb +23 -0
- data/lib/onebox/engine/college_humor_onebox.rb +26 -0
- data/lib/onebox/engine/dailymotion_onebox.rb +26 -0
- data/lib/onebox/engine/dotsub_onebox.rb +25 -0
- data/lib/onebox/engine/example_onebox.rb +25 -0
- data/lib/onebox/engine/flickr_onebox.rb +25 -0
- data/lib/onebox/engine/funny_or_die_onebox.rb +26 -0
- data/lib/onebox/engine/html.rb +11 -0
- data/lib/onebox/engine/hulu_onebox.rb +26 -0
- data/lib/onebox/engine/nfb_onebox.rb +25 -0
- data/lib/onebox/engine/open_graph.rb +11 -0
- data/lib/onebox/engine/qik_onebox.rb +23 -0
- data/lib/onebox/engine/revision3_onebox.rb +26 -0
- data/lib/onebox/engine/slideshare_onebox.rb +25 -0
- data/lib/onebox/engine/sound_cloud_onebox.rb +25 -0
- data/lib/onebox/engine/stack_exchange_onebox.rb +23 -0
- data/lib/onebox/engine/ted_onebox.rb +25 -0
- data/lib/onebox/engine/viddler_onebox.rb +26 -0
- data/lib/onebox/engine/vimeo_onebox.rb +26 -0
- data/lib/onebox/engine/wikipedia_onebox.rb +24 -0
- data/lib/onebox/engine/yfrog_onebox.rb +25 -0
- data/lib/onebox/matcher.rb +13 -0
- data/lib/onebox/preview.rb +31 -0
- data/lib/onebox/version.rb +3 -0
- data/onebox.gemspec +36 -0
- data/spec/fixtures/amazon.response +3098 -0
- data/spec/fixtures/android.response +138 -0
- data/spec/fixtures/apple.response +391 -0
- data/spec/fixtures/bliptv.response +724 -0
- data/spec/fixtures/clickthrough.response +1472 -0
- data/spec/fixtures/clikthrough.response +1472 -0
- data/spec/fixtures/collegehumor.response +1272 -0
- data/spec/fixtures/dailymotion.response +575 -0
- data/spec/fixtures/dotsub.response +1257 -0
- data/spec/fixtures/example.response +50 -0
- data/spec/fixtures/flickr.response +1292 -0
- data/spec/fixtures/funnyordie.response +2010 -0
- data/spec/fixtures/gist.response +282 -0
- data/spec/fixtures/github_blob.response +706 -0
- data/spec/fixtures/github_commit.response +881 -0
- data/spec/fixtures/github_pullrequest.response +1619 -0
- data/spec/fixtures/hulu.response +339 -0
- data/spec/fixtures/image.response +0 -0
- data/spec/fixtures/imgur.response +892 -0
- data/spec/fixtures/kinomap.response +299 -0
- data/spec/fixtures/nfb.response +810 -0
- data/spec/fixtures/opengraph.response +27 -0
- data/spec/fixtures/qik.response +371 -0
- data/spec/fixtures/revision3.response +985 -0
- data/spec/fixtures/rottentomatoes_fresh.response +3275 -0
- data/spec/fixtures/rottentomatoes_incomplete.response +2313 -0
- data/spec/fixtures/rottentomatoes_rotten.response +3549 -0
- data/spec/fixtures/slideshare.response +1745 -0
- data/spec/fixtures/soundcloud.response +1409 -0
- data/spec/fixtures/stackexchange.response +1889 -0
- data/spec/fixtures/ted.response +1341 -0
- data/spec/fixtures/twitter.response +1712 -0
- data/spec/fixtures/viddler.response +442 -0
- data/spec/fixtures/video.response +0 -0
- data/spec/fixtures/vimeo.response +571 -0
- data/spec/fixtures/wikipedia.response +1236 -0
- data/spec/fixtures/wikipedia_redirected.response +899 -0
- data/spec/fixtures/yfrog.response +464 -0
- data/spec/lib/onebox/engine/amazon_spec.rb +34 -0
- data/spec/lib/onebox/engine/bliptv_spec.rb +34 -0
- data/spec/lib/onebox/engine/clikthrough_spec.rb +26 -0
- data/spec/lib/onebox/engine/college_humor_spec.rb +34 -0
- data/spec/lib/onebox/engine/dailymotion_spec.rb +36 -0
- data/spec/lib/onebox/engine/dotsub_spec.rb +36 -0
- data/spec/lib/onebox/engine/example_spec.rb +18 -0
- data/spec/lib/onebox/engine/flickr_spec.rb +30 -0
- data/spec/lib/onebox/engine/funny_or_die_spec.rb +34 -0
- data/spec/lib/onebox/engine/hulu_spec.rb +34 -0
- data/spec/lib/onebox/engine/nfb_spec.rb +35 -0
- data/spec/lib/onebox/engine/qik_spec.rb +35 -0
- data/spec/lib/onebox/engine/revision3_spec.rb +36 -0
- data/spec/lib/onebox/engine/slideshare_spec.rb +30 -0
- data/spec/lib/onebox/engine/sound_cloud_spec.rb +36 -0
- data/spec/lib/onebox/engine/stack_exchange_spec.rb +27 -0
- data/spec/lib/onebox/engine/ted_spec.rb +30 -0
- data/spec/lib/onebox/engine/viddler_spec.rb +36 -0
- data/spec/lib/onebox/engine/vimeo_spec.rb +34 -0
- data/spec/lib/onebox/engine/wikipedia_spec.rb +30 -0
- data/spec/lib/onebox/engine/yfrog_spec.rb +30 -0
- data/spec/lib/onebox/engine_spec.rb +78 -0
- data/spec/lib/onebox/matcher_spec.rb +20 -0
- data/spec/lib/onebox/preview_spec.rb +21 -0
- data/spec/lib/onebox_spec.rb +49 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/html_spec_helper.rb +17 -0
- data/templates/amazon.handlebars +9 -0
- data/templates/bliptv.handlebars +10 -0
- data/templates/clickthrough.handlebars +8 -0
- data/templates/clikthrough.handlebars +8 -0
- data/templates/collegehumor.handlebars +9 -0
- data/templates/dailymotion.handlebars +9 -0
- data/templates/dotsub.handlebars +9 -0
- data/templates/flickr.handlebars +8 -0
- data/templates/funnyordie.handlebars +9 -0
- data/templates/hulu.handlebars +9 -0
- data/templates/nfb.handlebars +8 -0
- data/templates/qik.handlebars +7 -0
- data/templates/revision3.handlebars +9 -0
- data/templates/slideshare.handlebars +8 -0
- data/templates/soundcloud.handlebars +9 -0
- data/templates/stackexchange.handlebars +7 -0
- data/templates/ted.handlebars +8 -0
- data/templates/viddler.handlebars +9 -0
- data/templates/vimeo.handlebars +9 -0
- data/templates/wikipedia.handlebars +8 -0
- data/templates/yfrog.handlebars +8 -0
- metadata +447 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class ExampleOnebox
|
4
|
+
include Engine
|
5
|
+
include HTML
|
6
|
+
|
7
|
+
matches do
|
8
|
+
find "example.com"
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def data
|
14
|
+
{
|
15
|
+
header: raw.css("h1").inner_text
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def template
|
20
|
+
%|<div class="onebox">{{header}}</div>|
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class FlickrOnebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^https?\:\/\/.*\.flickr\.com\/.*$/
|
9
|
+
find "flickr.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.title,
|
18
|
+
image: raw.images.first,
|
19
|
+
description: raw.description
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class FunnyOrDieOnebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^https?\:\/\/(www\.)?funnyordie\.com\/videos\/.*$/$/
|
9
|
+
find "funnyordie.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.title,
|
18
|
+
image: raw.images.first,
|
19
|
+
description: raw.description,
|
20
|
+
video: raw.metadata[:video].first[:url].first[:_value]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class HuluOnebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
#/^https?\:\/\/www\.hulu\.com\/watch\/.*$/
|
9
|
+
find "hulu.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.title,
|
18
|
+
image: raw.images.first,
|
19
|
+
description: raw.description,
|
20
|
+
video: raw.metadata[:video][1][:_value]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class NFBOnebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^https?:\/\/(?:www\.)?nfb\.ca\/film\/[-\w]+\/?/
|
9
|
+
find "nfb.ca"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.title,
|
18
|
+
description: raw.description,
|
19
|
+
video: raw.metadata[:video].first[:_value]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class QikOnebox
|
4
|
+
include Engine
|
5
|
+
include HTML
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^https?\:\/\/qik\.com\/video\/.*$/
|
9
|
+
find "qik.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.css(".info h2").inner_text,
|
18
|
+
image: raw.css(".userphoto").first["src"]
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class Revision3Onebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^http\:\/\/(.*\.)?revision3\.com\/.*$/
|
9
|
+
find "revision3.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.title,
|
18
|
+
image: raw.images.first,
|
19
|
+
description: raw.description,
|
20
|
+
video: raw.metadata[:video].first[:_value]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class SlideshareOnebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^https?\:\/\/(www\.)?slideshare\.net\/*\/.*$/
|
9
|
+
find "slideshare.net"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.title,
|
18
|
+
image: raw.images.first,
|
19
|
+
description: raw.description
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class SoundCloudOnebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^https?:\/\/(?:www\.)?soundcloud\.com\/.+$/
|
9
|
+
find "soundcloud.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.title,
|
18
|
+
image: raw.images.first,
|
19
|
+
description: raw.description,
|
20
|
+
video: raw.metadata[:video][1][:_value]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class StackExchangeOnebox
|
4
|
+
include Engine
|
5
|
+
include HTML
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^http:\/\/(?:(?:(?<subsubdomain>\w*)\.)?(?<subdomain>\w*)\.)?(?<domain>#{DOMAINS.join('|')})\.com\/(?:questions|q)\/(?<question>\d*)/
|
9
|
+
find "stackexchange.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.css(".question-hyperlink").inner_text,
|
18
|
+
question: raw.css(".question .post-text p").first.inner_text
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class TedOnebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^https?\:\/\/(www\.)?ted\.com\/talks\/.*$/
|
9
|
+
find "ted.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.title,
|
18
|
+
image: raw.images.first,
|
19
|
+
description: raw.description
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class ViddlerOnebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^https?:\/\/(?:www\.)?viddler\.com\/.+$/
|
9
|
+
find "viddler.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.title,
|
18
|
+
image: raw.images.first,
|
19
|
+
description: raw.description,
|
20
|
+
video: raw.metadata[:video].first[:_value]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class VimeoOnebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^https?\:\/\/vimeo\.com\/.*$/
|
9
|
+
find "vimeo.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.title,
|
18
|
+
image: raw.images.first,
|
19
|
+
description: raw.description,
|
20
|
+
video: raw.metadata[:video].first[:_value]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class WikipediaOnebox
|
4
|
+
include Engine
|
5
|
+
include HTML
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^https?:\/\/.*wikipedia\.(com|org)\/.*$/
|
9
|
+
find "wikipedia.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
name: raw.css("html body h1").inner_text,
|
18
|
+
image: raw.css(".infobox .image img").first["src"],
|
19
|
+
description: raw.css("html body p").inner_text
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class YfrogOnebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# /^https?:\/\/(?:www\.)?yfrog\.(com|ru|com\.tr|it|fr|co\.il|co\.uk|com\.pl|pl|eu|us)\/[a-zA-Z0-9]+/
|
9
|
+
find "yfrog.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
url: @url,
|
17
|
+
title: raw.title,
|
18
|
+
image: raw.images.first,
|
19
|
+
description: raw.description
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Onebox
|
2
|
+
class Preview
|
3
|
+
attr_reader :cache
|
4
|
+
|
5
|
+
def initialize(link, parameters = Onebox.defaults)
|
6
|
+
@url = link
|
7
|
+
@options = parameters
|
8
|
+
@cache = options.cache
|
9
|
+
@engine = Matcher.new(@url).oneboxed
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
engine.to_html
|
14
|
+
end
|
15
|
+
|
16
|
+
def options
|
17
|
+
OpenStruct.new(@options)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def engine
|
23
|
+
@engine.new(@url, cache)
|
24
|
+
end
|
25
|
+
|
26
|
+
class InvalidURI < StandardError
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|