onebox 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +4 -0
  3. data/.travis.yml +4 -0
  4. data/README.md +154 -113
  5. data/lib/onebox.rb +6 -3
  6. data/lib/onebox/engine.rb +28 -26
  7. data/lib/onebox/engine/amazon_onebox.rb +4 -2
  8. data/lib/onebox/engine/bliptv_onebox.rb +4 -2
  9. data/lib/onebox/engine/clikthrough_onebox.rb +4 -2
  10. data/lib/onebox/engine/college_humor_onebox.rb +3 -2
  11. data/lib/onebox/engine/dailymotion_onebox.rb +4 -2
  12. data/lib/onebox/engine/dotsub_onebox.rb +4 -2
  13. data/lib/onebox/engine/example_onebox.rb +4 -5
  14. data/lib/onebox/engine/flickr_onebox.rb +3 -2
  15. data/lib/onebox/engine/funny_or_die_onebox.rb +4 -2
  16. data/lib/onebox/engine/github_blob_onebox.rb +28 -0
  17. data/lib/onebox/engine/github_commit_onebox.rb +43 -0
  18. data/lib/onebox/engine/github_gist_onebox.rb +33 -0
  19. data/lib/onebox/engine/github_pullrequest_onebox.rb +43 -0
  20. data/lib/onebox/engine/html.rb +1 -1
  21. data/lib/onebox/engine/hulu_onebox.rb +5 -2
  22. data/lib/onebox/engine/imgur_image_onebox.rb +26 -0
  23. data/lib/onebox/engine/itunes_onebox.rb +28 -0
  24. data/lib/onebox/engine/json.rb +11 -0
  25. data/lib/onebox/engine/kinomap_onebox.rb +27 -0
  26. data/lib/onebox/engine/nfb_onebox.rb +5 -2
  27. data/lib/onebox/engine/open_graph.rb +1 -1
  28. data/lib/onebox/engine/qik_onebox.rb +4 -2
  29. data/lib/onebox/engine/revision3_onebox.rb +3 -2
  30. data/lib/onebox/engine/slideshare_onebox.rb +4 -2
  31. data/lib/onebox/engine/sound_cloud_onebox.rb +4 -2
  32. data/lib/onebox/engine/spotify_onebox.rb +27 -0
  33. data/lib/onebox/engine/stack_exchange_onebox.rb +4 -2
  34. data/lib/onebox/engine/ted_onebox.rb +5 -2
  35. data/lib/onebox/engine/twitter_onebox.rb +31 -0
  36. data/lib/onebox/engine/viddler_onebox.rb +5 -3
  37. data/lib/onebox/engine/vimeo_onebox.rb +3 -2
  38. data/lib/onebox/engine/wikipedia_onebox.rb +4 -2
  39. data/lib/onebox/engine/yfrog_onebox.rb +5 -2
  40. data/lib/onebox/version.rb +1 -1
  41. data/lib/onebox/view.rb +21 -0
  42. data/onebox.gemspec +1 -1
  43. data/spec/fixtures/githubblob.response +922 -0
  44. data/spec/fixtures/githubcommit.response +87 -0
  45. data/spec/fixtures/githubgist.response +468 -0
  46. data/spec/fixtures/githubpullrequest.response +216 -0
  47. data/spec/fixtures/imguralbum.response +941 -0
  48. data/spec/fixtures/{imgur.response → imgurimage.response} +870 -890
  49. data/spec/fixtures/itunes.response +402 -0
  50. data/spec/fixtures/{rottentomatoes_fresh.response → rottentomatoesfresh.response} +0 -0
  51. data/spec/fixtures/{rottentomatoes_incomplete.response → rottentomatoesincomplete.response} +0 -0
  52. data/spec/fixtures/{rottentomatoes_rotten.response → rottentomatoesrotten.response} +0 -0
  53. data/spec/fixtures/spotify.response +250 -0
  54. data/spec/fixtures/{wikipedia_redirected.response → wikipediaredirected.response} +0 -0
  55. data/spec/lib/onebox/engine/{amazon_spec.rb → amazon_onebox_spec.rb} +7 -4
  56. data/spec/lib/onebox/engine/{bliptv_spec.rb → bliptv_onebox_spec.rb} +7 -4
  57. data/spec/lib/onebox/engine/{clikthrough_spec.rb → clikthrough_onebox_spec.rb} +7 -4
  58. data/spec/lib/onebox/engine/{college_humor_spec.rb → college_humor_onebox_spec.rb} +7 -4
  59. data/spec/lib/onebox/engine/{dailymotion_spec.rb → dailymotion_onebox_spec.rb} +7 -4
  60. data/spec/lib/onebox/engine/{dotsub_spec.rb → dotsub_onebox_spec.rb} +7 -4
  61. data/spec/lib/onebox/engine/example_onebox_spec.rb +21 -0
  62. data/spec/lib/onebox/engine/{flickr_spec.rb → flickr_onebox_spec.rb} +7 -4
  63. data/spec/lib/onebox/engine/{funny_or_die_spec.rb → funny_or_die_onebox_spec.rb} +7 -4
  64. data/spec/lib/onebox/engine/github_blob_onebox_spec.rb +30 -0
  65. data/spec/lib/onebox/engine/github_commit_onebox_spec.rb +61 -0
  66. data/spec/lib/onebox/engine/github_gist_onebox_spec.rb +29 -0
  67. data/spec/lib/onebox/engine/github_pullrequest_onebox_spec.rb +58 -0
  68. data/spec/lib/onebox/engine/html_spec.rb +27 -0
  69. data/spec/lib/onebox/engine/{hulu_spec.rb → hulu_onebox_spec.rb} +7 -4
  70. data/spec/lib/onebox/engine/imgur_image_onebox_spec.rb +29 -0
  71. data/spec/lib/onebox/engine/itunes_onebox_spec.rb +29 -0
  72. data/spec/lib/onebox/engine/json_spec.rb +27 -0
  73. data/spec/lib/onebox/engine/kinomap_onebox_spec.rb +37 -0
  74. data/spec/lib/onebox/engine/{nfb_spec.rb → nfb_onebox_spec.rb} +7 -4
  75. data/spec/lib/onebox/engine/open_graph_spec.rb +27 -0
  76. data/spec/lib/onebox/engine/{qik_spec.rb → qik_onebox_spec.rb} +7 -4
  77. data/spec/lib/onebox/engine/{revision3_spec.rb → revision3_onebox_spec.rb} +7 -4
  78. data/spec/lib/onebox/engine/{slideshare_spec.rb → slideshare_onebox_spec.rb} +7 -4
  79. data/spec/lib/onebox/engine/{sound_cloud_spec.rb → sound_cloud_onebox_spec.rb} +7 -4
  80. data/spec/lib/onebox/engine/spotify_onebox_spec.rb +36 -0
  81. data/spec/lib/onebox/engine/{stack_exchange_spec.rb → stack_exchange_onebox_spec.rb} +7 -4
  82. data/spec/lib/onebox/engine/{ted_spec.rb → ted_onebox_spec.rb} +7 -4
  83. data/spec/lib/onebox/engine/twitter_onebox_spec.rb +47 -0
  84. data/spec/lib/onebox/engine/{viddler_spec.rb → viddler_onebox_spec.rb} +7 -4
  85. data/spec/lib/onebox/engine/{vimeo_spec.rb → vimeo_onebox_spec.rb} +7 -4
  86. data/spec/lib/onebox/engine/{wikipedia_spec.rb → wikipedia_onebox_spec.rb} +7 -4
  87. data/spec/lib/onebox/engine/{yfrog_spec.rb → yfrog_onebox_spec.rb} +7 -4
  88. data/spec/lib/onebox/engine_spec.rb +38 -27
  89. data/spec/lib/onebox/preview_spec.rb +3 -1
  90. data/spec/lib/onebox/view_spec.rb +16 -0
  91. data/spec/lib/onebox_spec.rb +1 -1
  92. data/spec/spec_helper.rb +8 -3
  93. data/spec/support/html_spec_helper.rb +1 -1
  94. data/templates/_layout.mustache +4 -0
  95. data/templates/amazon.mustache +5 -0
  96. data/templates/bliptv.mustache +5 -0
  97. data/templates/clikthrough.mustache +4 -0
  98. data/templates/collegehumor.mustache +5 -0
  99. data/templates/dailymotion.mustache +5 -0
  100. data/templates/dotsub.mustache +5 -0
  101. data/templates/example.mustache +2 -0
  102. data/templates/flickr.mustache +4 -0
  103. data/templates/funnyordie.mustache +6 -0
  104. data/templates/githubblob.mustache +5 -0
  105. data/templates/githubcommit.mustache +11 -0
  106. data/templates/githubgist.mustache +3 -0
  107. data/templates/githubpullrequest.mustache +14 -0
  108. data/templates/hulu.mustache +6 -0
  109. data/templates/imgurimage.mustache +3 -0
  110. data/templates/itunes.mustache +4 -0
  111. data/templates/kinomap.mustache +5 -0
  112. data/templates/nfb.mustache +5 -0
  113. data/templates/qik.mustache +4 -0
  114. data/templates/revision3.mustache +5 -0
  115. data/templates/slideshare.mustache +4 -0
  116. data/templates/soundcloud.mustache +5 -0
  117. data/templates/spotify.mustache +4 -0
  118. data/templates/stackexchange.mustache +3 -0
  119. data/templates/ted.mustache +5 -0
  120. data/templates/twitter.mustache +7 -0
  121. data/templates/viddler.mustache +5 -0
  122. data/templates/vimeo.mustache +5 -0
  123. data/templates/wikipedia.mustache +4 -0
  124. data/templates/yfrog.mustache +4 -0
  125. metadata +139 -90
  126. data/spec/fixtures/apple.response +0 -391
  127. data/spec/fixtures/clickthrough.response +0 -1472
  128. data/spec/fixtures/gist.response +0 -282
  129. data/spec/fixtures/github_blob.response +0 -706
  130. data/spec/fixtures/github_commit.response +0 -881
  131. data/spec/fixtures/github_pullrequest.response +0 -1619
  132. data/spec/lib/onebox/engine/example_spec.rb +0 -18
  133. data/templates/amazon.handlebars +0 -9
  134. data/templates/bliptv.handlebars +0 -10
  135. data/templates/clickthrough.handlebars +0 -8
  136. data/templates/clikthrough.handlebars +0 -8
  137. data/templates/collegehumor.handlebars +0 -9
  138. data/templates/dailymotion.handlebars +0 -9
  139. data/templates/dotsub.handlebars +0 -9
  140. data/templates/flickr.handlebars +0 -8
  141. data/templates/funnyordie.handlebars +0 -9
  142. data/templates/hulu.handlebars +0 -9
  143. data/templates/nfb.handlebars +0 -8
  144. data/templates/qik.handlebars +0 -7
  145. data/templates/revision3.handlebars +0 -9
  146. data/templates/slideshare.handlebars +0 -8
  147. data/templates/soundcloud.handlebars +0 -9
  148. data/templates/stackexchange.handlebars +0 -7
  149. data/templates/ted.handlebars +0 -8
  150. data/templates/viddler.handlebars +0 -9
  151. data/templates/vimeo.handlebars +0 -9
  152. data/templates/wikipedia.handlebars +0 -8
  153. data/templates/yfrog.handlebars +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 292535107d74004655646908fd33b6a4aba4229c
4
- data.tar.gz: 7b2da58a31b11b745b7f0e4cffa96c050f190637
3
+ metadata.gz: 63d6aa188d0386a68d9d81be75ae88c844bfcf25
4
+ data.tar.gz: 705d8c65d0578efc9bb5c21bffcf47183c1d0d87
5
5
  SHA512:
6
- metadata.gz: 544481fff1bba95af38f1467c35b509d5aa8f6a725f6912ab7f63d31055f2d0073ffce2962b3d546eb06834ddc2d81bcb01eb108d963661c4987e2729b590a23
7
- data.tar.gz: 8b7970957af9cd698f52e242d6092acbaca945dd8fbe3f45617d471562c787b8c00b7223846342ca5cd08f4801b097e4fee9892b9d6ae8973ced5c4e34f7d67f
6
+ metadata.gz: 8518dc4c517c676a6afef5c61fb19bb2b249fce47883997ce1420cf75973cf67f75fe143c5c223f762beb3aced6955201eaeff8b5e1484442b634e8692b8b4e4
7
+ data.tar.gz: 73286c370651b4dad2721246d044b14ac9f3ab52c5ef1c6855ffdf92a530c4dd8c493061222494f1c902d3c9d258cf2e4331e649fdcf5a94f932953f797cfacb
data/.rspec CHANGED
@@ -1 +1,5 @@
1
1
  --color
2
+ --format documentation
3
+ --fail-fast
4
+ --backtrace
5
+
data/.travis.yml CHANGED
@@ -1,3 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
+ notifications:
5
+ email:
6
+ on_success: change
7
+ on_failure: change
data/README.md CHANGED
@@ -1,159 +1,200 @@
1
1
  onebox
2
2
  ----------
3
3
 
4
- - TODO: register to rubygems.org
4
+ - [![Gem Version](https://badge.fury.io/rb/onebox.png)](https://rubygems.org/gems/onebox)
5
5
  - [![Code Climate](https://codeclimate.com/github/dysania/onebox.png)](https://codeclimate.com/github/dysania/onebox)
6
6
  - [![Build Status](https://travis-ci.org/dysania/onebox.png)](https://travis-ci.org/dysania/onebox)
7
7
  - [![Dependency Status](https://gemnasium.com/dysania/onebox.png)](https://gemnasium.com/dysania/onebox)
8
8
  - [![Coverage Status](https://coveralls.io/repos/dysania/onebox/badge.png)](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
- Onebox currently has support for page, image, and video URLs from these sites:
14
- - Amazon
15
- - Android App Store
16
- - Apple Store
17
- - BlipTV
18
- - Clikthrough
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
- The `Gemfile` file would look like this:
24
+ Then pass a link to the library's interface:
55
25
 
56
26
  ``` ruby
57
- # source/Gemfile
58
- source "https://rubygems.org"
27
+ require "onebox"
59
28
 
60
- gem "onebox", "~> 1.0"
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
- How to create a new onebox
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
- 1. Create new onebox engine
44
+ Onebox has its own caching system but you can also provide (or turn off) your own system:
67
45
 
68
46
  ``` ruby
69
- # in lib/onebox/engine/name_onebox.rb
70
-
71
- module Onebox
72
- module Engine
73
- class NameOnebox
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
- 2. Create new onebox spec
54
+ In addition you can set your own defaults with this handy interface:
92
55
 
93
56
  ``` ruby
94
- # in spec/lib/onebox/engine/name_spec.rb
95
- require "spec_helper"
57
+ require "onebox"
96
58
 
97
- describe Onebox::Engine::NameOnebox do
98
- let(:link) { "http://yoursitename.com" }
99
- let(:html) { described_class.new(link).to_html }
59
+ Onebox.defaults = {
60
+ cache: Rails.cache
61
+ }
100
62
 
101
- before do
102
- fake(link, response("name.response"))
103
- end
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
- it "returns video photo" do
110
- expect(html).to include("photo.jpg")
111
- end
69
+ Setup
70
+ =====
112
71
 
113
- it "returns video description" do
114
- expect(html).to include("description")
115
- end
72
+ 1. Create new onebox engine
116
73
 
117
- it "returns URL" do
118
- expect(html).to include(link)
119
- end
120
- end
121
- ```
74
+ ``` ruby
75
+ # in lib/onebox/engine/name_onebox.rb
122
76
 
123
- 3. Create new handlebars template
124
-
125
- ``` html
126
- # in templates/name.handlebars
127
- <div class="onebox">
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
- 4. Create new fixture from HTML response
83
+ private
138
84
 
139
- ``` bash
140
- curl --output spec/fixtures/name.response -L -X -GET http://yoursitename.com
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
- 5. Require in Engine module
98
+ 2. Create new onebox spec
144
99
 
145
- ``` ruby
146
- # in lib/onebox/engine/engine.rb
147
- require_relative "engine/name_onebox"
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
- Installing onebox
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 'onebox'
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 "verbal_expressions"
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 = Onebox.defaults)
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
- Mustache.render(template, record)
26
+ view.to_html(record)
22
27
  end
23
28
 
24
29
  private
25
30
 
26
31
  def record
27
- if cache.key?(@url)
28
- cache.fetch(@url)
32
+ if cache.key?(url)
33
+ cache.fetch(url)
29
34
  else
30
- cache.store(@url, data)
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, VerEx.new(&block)
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"