onebox 1.0.1 → 1.1.0
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.
- 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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 63d6aa188d0386a68d9d81be75ae88c844bfcf25
|
|
4
|
+
data.tar.gz: 705d8c65d0578efc9bb5c21bffcf47183c1d0d87
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8518dc4c517c676a6afef5c61fb19bb2b249fce47883997ce1420cf75973cf67f75fe143c5c223f762beb3aced6955201eaeff8b5e1484442b634e8692b8b4e4
|
|
7
|
+
data.tar.gz: 73286c370651b4dad2721246d044b14ac9f3ab52c5ef1c6855ffdf92a530c4dd8c493061222494f1c902d3c9d258cf2e4331e649fdcf5a94f932953f797cfacb
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
|
@@ -1,159 +1,200 @@
|
|
|
1
1
|
onebox
|
|
2
2
|
----------
|
|
3
3
|
|
|
4
|
-
-
|
|
4
|
+
- [](https://rubygems.org/gems/onebox)
|
|
5
5
|
- [](https://codeclimate.com/github/dysania/onebox)
|
|
6
6
|
- [](https://travis-ci.org/dysania/onebox)
|
|
7
7
|
- [](https://gemnasium.com/dysania/onebox)
|
|
8
8
|
- [](https://coveralls.io/r/dysania/onebox)
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
Onebox is a library for turning media URLs into previews.
|
|
11
|
+
Onebox is a library for turning media URLs into simple HTML previews of the resource.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- College Humor
|
|
20
|
-
- Dailymotion
|
|
21
|
-
- Dotsub
|
|
22
|
-
- Flickr
|
|
23
|
-
- Funny or Die
|
|
24
|
-
- Gist
|
|
25
|
-
- Github
|
|
26
|
-
- Blob
|
|
27
|
-
- Commit
|
|
28
|
-
- Pull Request
|
|
29
|
-
- Hulu
|
|
30
|
-
- Imgur
|
|
31
|
-
- Kinomap
|
|
32
|
-
- NFB
|
|
33
|
-
- Open Graph
|
|
34
|
-
- Qik
|
|
35
|
-
- Revision
|
|
36
|
-
- Rotten Tomatoes
|
|
37
|
-
- Slideshare
|
|
38
|
-
- Smugmug
|
|
39
|
-
- Soundcloud
|
|
40
|
-
- Stack Exchange
|
|
41
|
-
- TED
|
|
42
|
-
- Twitter
|
|
43
|
-
- Wikipedia
|
|
44
|
-
- yFrog
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Using onebox
|
|
48
|
-
===============
|
|
13
|
+
|
|
14
|
+
Usage
|
|
15
|
+
=====
|
|
16
|
+
|
|
17
|
+
Using onebox is fairly simple!
|
|
18
|
+
First, make sure the library is required:
|
|
49
19
|
|
|
50
20
|
``` ruby
|
|
51
21
|
require "onebox"
|
|
52
22
|
```
|
|
53
23
|
|
|
54
|
-
|
|
24
|
+
Then pass a link to the library's interface:
|
|
55
25
|
|
|
56
26
|
``` ruby
|
|
57
|
-
|
|
58
|
-
source "https://rubygems.org"
|
|
27
|
+
require "onebox"
|
|
59
28
|
|
|
60
|
-
|
|
29
|
+
url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
|
|
30
|
+
preview = Onebox.preview(url)
|
|
61
31
|
```
|
|
62
32
|
|
|
63
|
-
|
|
64
|
-
|
|
33
|
+
This will contain a simple Onebox::Preview object that handles all the transformation.
|
|
34
|
+
From here you either call `Onebox::Preview#to_s` or just pass the object to a string:
|
|
35
|
+
|
|
36
|
+
``` ruby
|
|
37
|
+
require "onebox"
|
|
38
|
+
|
|
39
|
+
url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
|
|
40
|
+
preview = Onebox.preview(url)
|
|
41
|
+
"#{preview}" == preview.to_s #=> true
|
|
42
|
+
```
|
|
65
43
|
|
|
66
|
-
|
|
44
|
+
Onebox has its own caching system but you can also provide (or turn off) your own system:
|
|
67
45
|
|
|
68
46
|
``` ruby
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
include Engine
|
|
75
|
-
|
|
76
|
-
private
|
|
77
|
-
|
|
78
|
-
def extracted_data
|
|
79
|
-
{
|
|
80
|
-
url: @url,
|
|
81
|
-
name: @body.css("h1").inner_text,
|
|
82
|
-
image: @body.css("#main-image").first["src"],
|
|
83
|
-
description: @body.css("#postBodyPS").inner_text
|
|
84
|
-
}
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
47
|
+
require "onebox"
|
|
48
|
+
|
|
49
|
+
url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
|
|
50
|
+
preview = Onebox.preview(url, cache: Rails.cache)
|
|
51
|
+
"#{preview}" == preview.to_s #=> true
|
|
89
52
|
```
|
|
90
53
|
|
|
91
|
-
|
|
54
|
+
In addition you can set your own defaults with this handy interface:
|
|
92
55
|
|
|
93
56
|
``` ruby
|
|
94
|
-
|
|
95
|
-
require "spec_helper"
|
|
57
|
+
require "onebox"
|
|
96
58
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
59
|
+
Onebox.defaults = {
|
|
60
|
+
cache: Rails.cache
|
|
61
|
+
}
|
|
100
62
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
63
|
+
url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
|
|
64
|
+
preview = Onebox.preview(url)
|
|
65
|
+
"#{preview}" == preview.to_s #=> true
|
|
66
|
+
```
|
|
104
67
|
|
|
105
|
-
it "returns video title" do
|
|
106
|
-
expect(html).to include("title")
|
|
107
|
-
end
|
|
108
68
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
end
|
|
69
|
+
Setup
|
|
70
|
+
=====
|
|
112
71
|
|
|
113
|
-
|
|
114
|
-
expect(html).to include("description")
|
|
115
|
-
end
|
|
72
|
+
1. Create new onebox engine
|
|
116
73
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
```
|
|
74
|
+
``` ruby
|
|
75
|
+
# in lib/onebox/engine/name_onebox.rb
|
|
122
76
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
<a href="{{url}}">
|
|
129
|
-
<h1>{{name}}</h1>
|
|
130
|
-
<h2 class="host">yoursitename.com</h2>
|
|
131
|
-
<img src="{{image}}" />
|
|
132
|
-
<p>{{description}}</p>
|
|
133
|
-
</a>
|
|
134
|
-
</div>
|
|
135
|
-
```
|
|
77
|
+
module Onebox
|
|
78
|
+
module Engine
|
|
79
|
+
class NameOnebox
|
|
80
|
+
include Engine
|
|
81
|
+
include HTML
|
|
136
82
|
|
|
137
|
-
|
|
83
|
+
private
|
|
138
84
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
85
|
+
def data
|
|
86
|
+
{
|
|
87
|
+
url: @url,
|
|
88
|
+
name: raw.css("h1").inner_text,
|
|
89
|
+
image: raw.css("#main-image").first["src"],
|
|
90
|
+
description: raw.css("#postBodyPS").inner_text
|
|
91
|
+
}
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
```
|
|
142
97
|
|
|
143
|
-
|
|
98
|
+
2. Create new onebox spec
|
|
144
99
|
|
|
145
|
-
``` ruby
|
|
146
|
-
# in lib/onebox/engine/
|
|
147
|
-
|
|
148
|
-
|
|
100
|
+
``` ruby
|
|
101
|
+
# in spec/lib/onebox/engine/name_spec.rb
|
|
102
|
+
require "spec_helper"
|
|
103
|
+
|
|
104
|
+
describe Onebox::Engine::NameOnebox do
|
|
105
|
+
let(:link) { "http://example.com" }
|
|
106
|
+
let(:html) { described_class.new(link).to_html }
|
|
107
|
+
|
|
108
|
+
before do
|
|
109
|
+
fake(link, response("name.response"))
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "has the video's title" do
|
|
113
|
+
expect(html).to include("title")
|
|
114
|
+
end
|
|
149
115
|
|
|
116
|
+
it "has the video's still shot" do
|
|
117
|
+
expect(html).to include("photo.jpg")
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "has the video's description" do
|
|
121
|
+
expect(html).to include("description")
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "has the URL to the resource" do
|
|
125
|
+
expect(html).to include(link)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
3. Create new handlebars template
|
|
131
|
+
|
|
132
|
+
``` html
|
|
133
|
+
# in templates/name.handlebars
|
|
134
|
+
<div class="onebox">
|
|
135
|
+
<a href="{{url}}">
|
|
136
|
+
<h1>{{name}}</h1>
|
|
137
|
+
<h2 class="host">example.com</h2>
|
|
138
|
+
<img src="{{image}}" />
|
|
139
|
+
<p>{{description}}</p>
|
|
140
|
+
</a>
|
|
141
|
+
</div>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
4. Create new fixture from HTML response
|
|
145
|
+
|
|
146
|
+
``` bash
|
|
147
|
+
curl --output spec/fixtures/oneboxname.response -L -X -GET http://example.com
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
5. Require in Engine module
|
|
151
|
+
|
|
152
|
+
``` ruby
|
|
153
|
+
# in lib/onebox/engine/engine.rb
|
|
154
|
+
require_relative "engine/name_onebox"
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Onebox currently has support for page, image, and video URLs from these sites:
|
|
150
158
|
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
- Amazon
|
|
160
|
+
- Android App Store
|
|
161
|
+
- Apple Store
|
|
162
|
+
- BlipTV
|
|
163
|
+
- Clikthrough
|
|
164
|
+
- College Humor
|
|
165
|
+
- Dailymotion
|
|
166
|
+
- Dotsub
|
|
167
|
+
- Flickr
|
|
168
|
+
- Funny or Die
|
|
169
|
+
- GitHub
|
|
170
|
+
- Blob
|
|
171
|
+
- Commit
|
|
172
|
+
- Gist
|
|
173
|
+
- Pull Request
|
|
174
|
+
- Hulu
|
|
175
|
+
- Imgur
|
|
176
|
+
- Kinomap
|
|
177
|
+
- NFB
|
|
178
|
+
- Open Graph
|
|
179
|
+
- Qik
|
|
180
|
+
- Revision
|
|
181
|
+
- Rotten Tomatoes
|
|
182
|
+
- Slideshare
|
|
183
|
+
- SmugMug
|
|
184
|
+
- SoundCloud
|
|
185
|
+
- Stack Exchange
|
|
186
|
+
- TED
|
|
187
|
+
- Twitter
|
|
188
|
+
- Wikipedia
|
|
189
|
+
- yFrog
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
Installing
|
|
193
|
+
==========
|
|
153
194
|
|
|
154
195
|
Add this line to your application's Gemfile:
|
|
155
196
|
|
|
156
|
-
gem
|
|
197
|
+
gem "onebox". "~> 1.0"
|
|
157
198
|
|
|
158
199
|
And then execute:
|
|
159
200
|
|
data/lib/onebox.rb
CHANGED
|
@@ -3,7 +3,8 @@ require "multi_json"
|
|
|
3
3
|
require "nokogiri"
|
|
4
4
|
require "mustache"
|
|
5
5
|
require "opengraph_parser"
|
|
6
|
-
require "
|
|
6
|
+
require "hexpress"
|
|
7
|
+
require "hexpress/web"
|
|
7
8
|
require "ostruct"
|
|
8
9
|
require "moneta"
|
|
9
10
|
|
|
@@ -11,10 +12,12 @@ require_relative "onebox/version"
|
|
|
11
12
|
require_relative "onebox/preview"
|
|
12
13
|
require_relative "onebox/matcher"
|
|
13
14
|
require_relative "onebox/engine"
|
|
15
|
+
require_relative "onebox/view"
|
|
14
16
|
|
|
15
17
|
module Onebox
|
|
16
18
|
DEFAULTS = {
|
|
17
|
-
cache: Moneta.new(:Memory, expires: true, serializer: :json)
|
|
19
|
+
cache: Moneta.new(:Memory, expires: true, serializer: :json),
|
|
20
|
+
timeout: 10
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
@@defaults = DEFAULTS
|
|
@@ -24,7 +27,7 @@ module Onebox
|
|
|
24
27
|
end
|
|
25
28
|
|
|
26
29
|
def self.defaults
|
|
27
|
-
@@defaults
|
|
30
|
+
OpenStruct.new(@@defaults)
|
|
28
31
|
end
|
|
29
32
|
|
|
30
33
|
def self.defaults=(options)
|
data/lib/onebox/engine.rb
CHANGED
|
@@ -10,24 +10,29 @@ module Onebox
|
|
|
10
10
|
end.map(&method(:const_get))
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
attr_reader :url
|
|
13
14
|
attr_reader :cache
|
|
15
|
+
attr_reader :timeout
|
|
16
|
+
attr_reader :view
|
|
14
17
|
|
|
15
|
-
def initialize(link, cache =
|
|
18
|
+
def initialize(link, cache = nil, timeout = nil)
|
|
16
19
|
@url = link
|
|
17
|
-
@cache = cache
|
|
20
|
+
@cache = cache || Onebox.defaults.cache
|
|
21
|
+
@timeout = timeout || Onebox.defaults.timeout
|
|
22
|
+
@view = View.new(self.class.template_name, true)
|
|
18
23
|
end
|
|
19
24
|
|
|
20
25
|
def to_html
|
|
21
|
-
|
|
26
|
+
view.to_html(record)
|
|
22
27
|
end
|
|
23
28
|
|
|
24
29
|
private
|
|
25
30
|
|
|
26
31
|
def record
|
|
27
|
-
if cache.key?(
|
|
28
|
-
cache.fetch(
|
|
32
|
+
if cache.key?(url)
|
|
33
|
+
cache.fetch(url)
|
|
29
34
|
else
|
|
30
|
-
cache.store(
|
|
35
|
+
cache.store(url, data)
|
|
31
36
|
end
|
|
32
37
|
end
|
|
33
38
|
|
|
@@ -37,24 +42,6 @@ module Onebox
|
|
|
37
42
|
raise NoMethodError, "Engines need to implement this method"
|
|
38
43
|
end
|
|
39
44
|
|
|
40
|
-
def template
|
|
41
|
-
File.read(template_path)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def template_path
|
|
45
|
-
File.join(root, "templates", "#{template_name}.handlebars")
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# returns the gem root directory
|
|
49
|
-
def root
|
|
50
|
-
Gem::Specification.find_by_name("onebox").gem_dir
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# calculates handlebars template name for onebox using name of engine
|
|
54
|
-
def template_name
|
|
55
|
-
self.class.name.split("::").last.downcase.gsub(/onebox/, "")
|
|
56
|
-
end
|
|
57
|
-
|
|
58
45
|
# raises error if not defined in onebox engine
|
|
59
46
|
# in each onebox, returns hash of desired onebox content
|
|
60
47
|
def data
|
|
@@ -71,7 +58,12 @@ module Onebox
|
|
|
71
58
|
end
|
|
72
59
|
|
|
73
60
|
def matches(&block)
|
|
74
|
-
class_variable_set :@@matcher,
|
|
61
|
+
class_variable_set :@@matcher, Hexpress.new(&block).to_r
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# calculates handlebars template name for onebox using name of engine
|
|
65
|
+
def template_name
|
|
66
|
+
name.split("::").last.downcase.gsub(/onebox/, "")
|
|
75
67
|
end
|
|
76
68
|
end
|
|
77
69
|
end
|
|
@@ -79,6 +71,7 @@ end
|
|
|
79
71
|
|
|
80
72
|
require_relative "engine/open_graph"
|
|
81
73
|
require_relative "engine/html"
|
|
74
|
+
require_relative "engine/json"
|
|
82
75
|
require_relative "engine/example_onebox"
|
|
83
76
|
require_relative "engine/amazon_onebox"
|
|
84
77
|
require_relative "engine/bliptv_onebox"
|
|
@@ -88,14 +81,23 @@ require_relative "engine/dailymotion_onebox"
|
|
|
88
81
|
require_relative "engine/dotsub_onebox"
|
|
89
82
|
require_relative "engine/flickr_onebox"
|
|
90
83
|
require_relative "engine/funny_or_die_onebox"
|
|
84
|
+
require_relative "engine/github_blob_onebox"
|
|
85
|
+
require_relative "engine/github_commit_onebox"
|
|
86
|
+
require_relative "engine/github_gist_onebox"
|
|
87
|
+
require_relative "engine/github_pullrequest_onebox"
|
|
91
88
|
require_relative "engine/hulu_onebox"
|
|
89
|
+
require_relative "engine/imgur_image_onebox"
|
|
90
|
+
require_relative "engine/itunes_onebox"
|
|
91
|
+
require_relative "engine/kinomap_onebox"
|
|
92
92
|
require_relative "engine/nfb_onebox"
|
|
93
|
-
require_relative "engine/sound_cloud_onebox"
|
|
94
93
|
require_relative "engine/qik_onebox"
|
|
95
94
|
require_relative "engine/revision3_onebox"
|
|
96
95
|
require_relative "engine/slideshare_onebox"
|
|
96
|
+
require_relative "engine/sound_cloud_onebox"
|
|
97
|
+
require_relative "engine/spotify_onebox"
|
|
97
98
|
require_relative "engine/stack_exchange_onebox"
|
|
98
99
|
require_relative "engine/ted_onebox"
|
|
100
|
+
require_relative "engine/twitter_onebox"
|
|
99
101
|
require_relative "engine/viddler_onebox"
|
|
100
102
|
require_relative "engine/vimeo_onebox"
|
|
101
103
|
require_relative "engine/wikipedia_onebox"
|