onebox 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +4 -0
- data/.travis.yml +4 -0
- data/README.md +154 -113
- data/lib/onebox.rb +6 -3
- data/lib/onebox/engine.rb +28 -26
- data/lib/onebox/engine/amazon_onebox.rb +4 -2
- data/lib/onebox/engine/bliptv_onebox.rb +4 -2
- data/lib/onebox/engine/clikthrough_onebox.rb +4 -2
- data/lib/onebox/engine/college_humor_onebox.rb +3 -2
- data/lib/onebox/engine/dailymotion_onebox.rb +4 -2
- data/lib/onebox/engine/dotsub_onebox.rb +4 -2
- data/lib/onebox/engine/example_onebox.rb +4 -5
- data/lib/onebox/engine/flickr_onebox.rb +3 -2
- data/lib/onebox/engine/funny_or_die_onebox.rb +4 -2
- data/lib/onebox/engine/github_blob_onebox.rb +28 -0
- data/lib/onebox/engine/github_commit_onebox.rb +43 -0
- data/lib/onebox/engine/github_gist_onebox.rb +33 -0
- data/lib/onebox/engine/github_pullrequest_onebox.rb +43 -0
- data/lib/onebox/engine/html.rb +1 -1
- data/lib/onebox/engine/hulu_onebox.rb +5 -2
- data/lib/onebox/engine/imgur_image_onebox.rb +26 -0
- data/lib/onebox/engine/itunes_onebox.rb +28 -0
- data/lib/onebox/engine/json.rb +11 -0
- data/lib/onebox/engine/kinomap_onebox.rb +27 -0
- data/lib/onebox/engine/nfb_onebox.rb +5 -2
- data/lib/onebox/engine/open_graph.rb +1 -1
- data/lib/onebox/engine/qik_onebox.rb +4 -2
- data/lib/onebox/engine/revision3_onebox.rb +3 -2
- data/lib/onebox/engine/slideshare_onebox.rb +4 -2
- data/lib/onebox/engine/sound_cloud_onebox.rb +4 -2
- data/lib/onebox/engine/spotify_onebox.rb +27 -0
- data/lib/onebox/engine/stack_exchange_onebox.rb +4 -2
- data/lib/onebox/engine/ted_onebox.rb +5 -2
- data/lib/onebox/engine/twitter_onebox.rb +31 -0
- data/lib/onebox/engine/viddler_onebox.rb +5 -3
- data/lib/onebox/engine/vimeo_onebox.rb +3 -2
- data/lib/onebox/engine/wikipedia_onebox.rb +4 -2
- data/lib/onebox/engine/yfrog_onebox.rb +5 -2
- data/lib/onebox/version.rb +1 -1
- data/lib/onebox/view.rb +21 -0
- data/onebox.gemspec +1 -1
- data/spec/fixtures/githubblob.response +922 -0
- data/spec/fixtures/githubcommit.response +87 -0
- data/spec/fixtures/githubgist.response +468 -0
- data/spec/fixtures/githubpullrequest.response +216 -0
- data/spec/fixtures/imguralbum.response +941 -0
- data/spec/fixtures/{imgur.response → imgurimage.response} +870 -890
- data/spec/fixtures/itunes.response +402 -0
- data/spec/fixtures/{rottentomatoes_fresh.response → rottentomatoesfresh.response} +0 -0
- data/spec/fixtures/{rottentomatoes_incomplete.response → rottentomatoesincomplete.response} +0 -0
- data/spec/fixtures/{rottentomatoes_rotten.response → rottentomatoesrotten.response} +0 -0
- data/spec/fixtures/spotify.response +250 -0
- data/spec/fixtures/{wikipedia_redirected.response → wikipediaredirected.response} +0 -0
- data/spec/lib/onebox/engine/{amazon_spec.rb → amazon_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{bliptv_spec.rb → bliptv_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{clikthrough_spec.rb → clikthrough_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{college_humor_spec.rb → college_humor_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{dailymotion_spec.rb → dailymotion_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{dotsub_spec.rb → dotsub_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/example_onebox_spec.rb +21 -0
- data/spec/lib/onebox/engine/{flickr_spec.rb → flickr_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{funny_or_die_spec.rb → funny_or_die_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/github_blob_onebox_spec.rb +30 -0
- data/spec/lib/onebox/engine/github_commit_onebox_spec.rb +61 -0
- data/spec/lib/onebox/engine/github_gist_onebox_spec.rb +29 -0
- data/spec/lib/onebox/engine/github_pullrequest_onebox_spec.rb +58 -0
- data/spec/lib/onebox/engine/html_spec.rb +27 -0
- data/spec/lib/onebox/engine/{hulu_spec.rb → hulu_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/imgur_image_onebox_spec.rb +29 -0
- data/spec/lib/onebox/engine/itunes_onebox_spec.rb +29 -0
- data/spec/lib/onebox/engine/json_spec.rb +27 -0
- data/spec/lib/onebox/engine/kinomap_onebox_spec.rb +37 -0
- data/spec/lib/onebox/engine/{nfb_spec.rb → nfb_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/open_graph_spec.rb +27 -0
- data/spec/lib/onebox/engine/{qik_spec.rb → qik_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{revision3_spec.rb → revision3_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{slideshare_spec.rb → slideshare_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{sound_cloud_spec.rb → sound_cloud_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/spotify_onebox_spec.rb +36 -0
- data/spec/lib/onebox/engine/{stack_exchange_spec.rb → stack_exchange_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{ted_spec.rb → ted_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/twitter_onebox_spec.rb +47 -0
- data/spec/lib/onebox/engine/{viddler_spec.rb → viddler_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{vimeo_spec.rb → vimeo_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{wikipedia_spec.rb → wikipedia_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine/{yfrog_spec.rb → yfrog_onebox_spec.rb} +7 -4
- data/spec/lib/onebox/engine_spec.rb +38 -27
- data/spec/lib/onebox/preview_spec.rb +3 -1
- data/spec/lib/onebox/view_spec.rb +16 -0
- data/spec/lib/onebox_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -3
- data/spec/support/html_spec_helper.rb +1 -1
- data/templates/_layout.mustache +4 -0
- data/templates/amazon.mustache +5 -0
- data/templates/bliptv.mustache +5 -0
- data/templates/clikthrough.mustache +4 -0
- data/templates/collegehumor.mustache +5 -0
- data/templates/dailymotion.mustache +5 -0
- data/templates/dotsub.mustache +5 -0
- data/templates/example.mustache +2 -0
- data/templates/flickr.mustache +4 -0
- data/templates/funnyordie.mustache +6 -0
- data/templates/githubblob.mustache +5 -0
- data/templates/githubcommit.mustache +11 -0
- data/templates/githubgist.mustache +3 -0
- data/templates/githubpullrequest.mustache +14 -0
- data/templates/hulu.mustache +6 -0
- data/templates/imgurimage.mustache +3 -0
- data/templates/itunes.mustache +4 -0
- data/templates/kinomap.mustache +5 -0
- data/templates/nfb.mustache +5 -0
- data/templates/qik.mustache +4 -0
- data/templates/revision3.mustache +5 -0
- data/templates/slideshare.mustache +4 -0
- data/templates/soundcloud.mustache +5 -0
- data/templates/spotify.mustache +4 -0
- data/templates/stackexchange.mustache +3 -0
- data/templates/ted.mustache +5 -0
- data/templates/twitter.mustache +7 -0
- data/templates/viddler.mustache +5 -0
- data/templates/vimeo.mustache +5 -0
- data/templates/wikipedia.mustache +4 -0
- data/templates/yfrog.mustache +4 -0
- metadata +139 -90
- data/spec/fixtures/apple.response +0 -391
- data/spec/fixtures/clickthrough.response +0 -1472
- data/spec/fixtures/gist.response +0 -282
- data/spec/fixtures/github_blob.response +0 -706
- data/spec/fixtures/github_commit.response +0 -881
- data/spec/fixtures/github_pullrequest.response +0 -1619
- data/spec/lib/onebox/engine/example_spec.rb +0 -18
- data/templates/amazon.handlebars +0 -9
- data/templates/bliptv.handlebars +0 -10
- data/templates/clickthrough.handlebars +0 -8
- data/templates/clikthrough.handlebars +0 -8
- data/templates/collegehumor.handlebars +0 -9
- data/templates/dailymotion.handlebars +0 -9
- data/templates/dotsub.handlebars +0 -9
- data/templates/flickr.handlebars +0 -8
- data/templates/funnyordie.handlebars +0 -9
- data/templates/hulu.handlebars +0 -9
- data/templates/nfb.handlebars +0 -8
- data/templates/qik.handlebars +0 -7
- data/templates/revision3.handlebars +0 -9
- data/templates/slideshare.handlebars +0 -8
- data/templates/soundcloud.handlebars +0 -9
- data/templates/stackexchange.handlebars +0 -7
- data/templates/ted.handlebars +0 -8
- data/templates/viddler.handlebars +0 -9
- data/templates/vimeo.handlebars +0 -9
- data/templates/wikipedia.handlebars +0 -8
- data/templates/yfrog.handlebars +0 -8
@@ -5,8 +5,10 @@ module Onebox
|
|
5
5
|
include OpenGraph
|
6
6
|
|
7
7
|
matches do
|
8
|
-
|
9
|
-
|
8
|
+
http
|
9
|
+
maybe("www.")
|
10
|
+
domain("clikthrough")
|
11
|
+
has(".com").either("/theater", "/video").maybe("/")
|
10
12
|
end
|
11
13
|
|
12
14
|
private
|
@@ -5,7 +5,10 @@ module Onebox
|
|
5
5
|
include HTML
|
6
6
|
|
7
7
|
matches do
|
8
|
-
|
8
|
+
http
|
9
|
+
maybe("www.")
|
10
|
+
domain("example")
|
11
|
+
has(".com").maybe("/")
|
9
12
|
end
|
10
13
|
|
11
14
|
private
|
@@ -15,10 +18,6 @@ module Onebox
|
|
15
18
|
header: raw.css("h1").inner_text
|
16
19
|
}
|
17
20
|
end
|
18
|
-
|
19
|
-
def template
|
20
|
-
%|<div class="onebox">{{header}}</div>|
|
21
|
-
end
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class GithubBlobOnebox
|
4
|
+
include Engine
|
5
|
+
include HTML
|
6
|
+
|
7
|
+
matches do
|
8
|
+
http
|
9
|
+
maybe("www")
|
10
|
+
domain("github")
|
11
|
+
tld("com")
|
12
|
+
anything
|
13
|
+
with("/blob/")
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def data
|
19
|
+
{
|
20
|
+
url: @url,
|
21
|
+
filename: raw.css(".final-path").inner_text,
|
22
|
+
lines: raw.css("#files .file .info .mode + span").inner_text,
|
23
|
+
file: raw.css("#files .file .blob-wrapper").inner_text
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class GithubCommitOnebox
|
4
|
+
include Engine
|
5
|
+
include JSON
|
6
|
+
|
7
|
+
matches do
|
8
|
+
http
|
9
|
+
maybe("www.")
|
10
|
+
domain("github")
|
11
|
+
tld("com")
|
12
|
+
anything
|
13
|
+
with("/commit/")
|
14
|
+
end
|
15
|
+
|
16
|
+
def url
|
17
|
+
"https://api.github.com/repos/#{match[:owner]}/#{match[:repo]}/commits/#{match[:number]}"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def match
|
23
|
+
@url.match(/github\.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/commit\/(?<number>[^\/]+)/)
|
24
|
+
end
|
25
|
+
|
26
|
+
def data
|
27
|
+
{
|
28
|
+
url: @url,
|
29
|
+
owner: match[:owner],
|
30
|
+
repo: match[:repo],
|
31
|
+
sha: raw["sha"],
|
32
|
+
gravatar: raw["author"]["avatar_url"],
|
33
|
+
message: raw["commit"]["message"],
|
34
|
+
author: raw["author"]["login"],
|
35
|
+
time_date: raw["commit"]["committer"]["date"],
|
36
|
+
files_changed: raw["files"].length,
|
37
|
+
additions: raw["stats"]["additions"],
|
38
|
+
deletions: raw["stats"]["deletions"]
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class GithubGistOnebox
|
4
|
+
include Engine
|
5
|
+
include JSON
|
6
|
+
|
7
|
+
matches do
|
8
|
+
http
|
9
|
+
with("gist.")
|
10
|
+
domain("github")
|
11
|
+
tld("com")
|
12
|
+
end
|
13
|
+
|
14
|
+
def url
|
15
|
+
"https://api.github.com/gists/#{match[:number]}"
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def match
|
21
|
+
@url.match(/gist\.github\.com\/([^\/]+\/)?(?<number>[0-9a-f]+)/)
|
22
|
+
end
|
23
|
+
|
24
|
+
def data
|
25
|
+
{
|
26
|
+
url: @url,
|
27
|
+
content: raw["files"].first[1]["content"],
|
28
|
+
author: raw["user"]["login"]
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class GithubPullRequestOnebox
|
4
|
+
include Engine
|
5
|
+
include JSON
|
6
|
+
|
7
|
+
matches do
|
8
|
+
http
|
9
|
+
maybe("www.")
|
10
|
+
domain("github")
|
11
|
+
tld("com")
|
12
|
+
anything
|
13
|
+
with("/pull/")
|
14
|
+
end
|
15
|
+
|
16
|
+
def url
|
17
|
+
"https://api.github.com/repos/#{match[:owner]}/#{match[:repo]}/pulls/#{match[:number]}"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def match
|
23
|
+
@url.match(/github\.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/pull\/(?<number>[^\/]+)/)
|
24
|
+
end
|
25
|
+
|
26
|
+
def data
|
27
|
+
{
|
28
|
+
url: @url,
|
29
|
+
author: raw["user"]["login"],
|
30
|
+
gravatar: raw["user"]["avatar_url"],
|
31
|
+
title: raw["title"],
|
32
|
+
repo: raw["base"]["repo"]["full_name"],
|
33
|
+
time_date: raw["created_at"],
|
34
|
+
commits: raw["commits"],
|
35
|
+
additions: raw["additions"],
|
36
|
+
deletions: raw["deletions"],
|
37
|
+
changed_files: raw["changed_files"],
|
38
|
+
description: raw["body"]
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/onebox/engine/html.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class ImgurImageOnebox
|
4
|
+
include Engine
|
5
|
+
include HTML
|
6
|
+
|
7
|
+
matches do
|
8
|
+
http
|
9
|
+
domain("imgur")
|
10
|
+
tld("com")
|
11
|
+
with("/gallery")
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def data
|
17
|
+
{
|
18
|
+
url: @url,
|
19
|
+
title: raw.css("h2#image-title").inner_text,
|
20
|
+
image: raw.css("#image img").first["src"]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class ItunesOnebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
# matcher /^https?:\/\/itunes.apple.com\/.+$/
|
9
|
+
http
|
10
|
+
domain("itunes")
|
11
|
+
has(".")
|
12
|
+
domain("apple")
|
13
|
+
tld("com")
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def data
|
19
|
+
{
|
20
|
+
url: @url,
|
21
|
+
title: raw.title,
|
22
|
+
image: raw.images.first,
|
23
|
+
description: raw.description,
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class KinomapOnebox
|
4
|
+
include Engine
|
5
|
+
include OpenGraph
|
6
|
+
|
7
|
+
matches do
|
8
|
+
http
|
9
|
+
domain("kinomap")
|
10
|
+
tld("com")
|
11
|
+
with("/watch/")
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def data
|
17
|
+
{
|
18
|
+
url: @url,
|
19
|
+
title: raw.title,
|
20
|
+
image: raw.images.first,
|
21
|
+
description: raw.description,
|
22
|
+
video: raw.metadata[:video].first[:_value]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|