onebox 1.2.6 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6a66e8e91c7878af02cfc958cef061c9217c53b
4
- data.tar.gz: 6256dc1b8e4e02eb72e20caa760a895ffc92c30b
3
+ metadata.gz: 1b55619a4868f6d5102153589eca14ef237c8f43
4
+ data.tar.gz: c50edc7d7160e7f258687d9b0b7621b2f3a90cb3
5
5
  SHA512:
6
- metadata.gz: 8a883437f3fc2dda06c596813fbc4c20229889d48fb640cae006039e869fc2c5a634922ff7dc5fa8fed7c9b70102168e36ca914df4b16dd3edb48e56ba6f5c63
7
- data.tar.gz: 937fa649b03e96ed98af0ce8dc222bbe04797a70e6d727052706523915bf051ee2534b13f554cb5fcefbed37257820a6aaa9d4d2828cbaca02884b8573ae2ac4
6
+ metadata.gz: ccafd91892941b7d566b34e7033abcab9edefeac0618adab49a2ac9bb9e18d02dbf3a4cb34038b6503597fde42512fce7b4a49ee91ec3746abc51d6008efed8f
7
+ data.tar.gz: 23297d238d7aa71356c67c79f2794315b0c7eb88e4add1da8c4235cfbc1d645199585f19eaa308bfe7b1ed2ef6640cfc623a7445afcb22c0561a666387b5135a
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+
6
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
7
+ end
8
+
data/lib/onebox.rb CHANGED
@@ -12,6 +12,7 @@ require "cgi"
12
12
  module Onebox
13
13
  DEFAULTS = {
14
14
  cache: Moneta.new(:Memory, expires: true, serializer: :json),
15
+ connect_timeout: 5,
15
16
  timeout: 10,
16
17
  load_paths: [File.join(Gem::Specification.find_by_name("onebox").gem_dir, "templates")]
17
18
  }
data/lib/onebox/engine.rb CHANGED
@@ -107,7 +107,8 @@ require_relative "engine/amazon_onebox"
107
107
  require_relative "engine/classic_google_maps_onebox"
108
108
  require_relative "engine/github_blob_onebox"
109
109
  require_relative "engine/github_commit_onebox"
110
- require_relative "engine/github_gist_onebox"
110
+ # broken
111
+ #require_relative "engine/github_gist_onebox"
111
112
  require_relative "engine/github_pullrequest_onebox"
112
113
  require_relative "engine/google_play_app_onebox"
113
114
  require_relative "engine/image_onebox"
@@ -1,3 +1,5 @@
1
+ # This is broken, document.write is only allowed on load
2
+ # See: http://stackoverflow.com/questions/9154026/jquery-dynamically-load-a-gist-embed
1
3
  module Onebox
2
4
  module Engine
3
5
  class GithubGistOnebox
@@ -34,7 +34,12 @@ module Onebox
34
34
  def fetch_response(location, limit = 3)
35
35
  raise Net::HTTPError.new('HTTP redirect too deep', location) if limit == 0
36
36
 
37
- response = Net::HTTP.get_response(URI(location))
37
+ uri = URI(location)
38
+ http = Net::HTTP.new(uri.host, uri.port)
39
+ http.open_timeout = Onebox.options.connect_timeout
40
+ http.read_timeout = Onebox.options.timeout
41
+ response = http.request_get(uri.request_uri)
42
+
38
43
  case response
39
44
  when Net::HTTPSuccess then response
40
45
  when Net::HTTPRedirection then fetch_response(response['location'], limit - 1)
@@ -6,8 +6,33 @@ module Onebox
6
6
 
7
7
  matches_regexp /^https?:\/\/(?:www\.)?(?:youtube\.com|youtu\.be)\/.+$/
8
8
 
9
+ # Try to get the video ID. Works for URLs of the form:
10
+ # * https://www.youtube.com/watch?v=Z0UISCEe52Y
11
+ # * http://youtu.be/afyK1HSFfgw
12
+ def video_id
13
+ match = @url.match(/^https?:\/\/(www\.)?(youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9_\-]{11})$/)
14
+ match && match[3]
15
+ end
16
+
17
+ def placeholder_html
18
+ if video_id
19
+ "<img src='http://i1.ytimg.com/vi/#{video_id}/hqdefault.jpg' width='480' height='270'>"
20
+ else
21
+ to_html
22
+ end
23
+ end
24
+
9
25
  def to_html
10
- rewrite_agnostic(append_params(raw[:html]))
26
+ if video_id
27
+ # Avoid making HTTP requests if we are able to get the video ID from the
28
+ # URL.
29
+ html = "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/#{video_id}?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>"
30
+ else
31
+ # Fall back to making HTTP requests.
32
+ html = raw[:html]
33
+ end
34
+
35
+ rewrite_agnostic(append_params(html))
11
36
  end
12
37
 
13
38
  def append_params(html)
@@ -1,3 +1,3 @@
1
1
  module Onebox
2
- VERSION = "1.2.6"
2
+ VERSION = "1.2.7"
3
3
  end
data/onebox.gemspec CHANGED
@@ -35,4 +35,8 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "mocha", "~> 0.14"
36
36
  spec.add_development_dependency "rubocop", "~> 0.11"
37
37
  spec.add_development_dependency "twitter", "~> 4.8"
38
+ spec.add_development_dependency "guard-rspec", "~> 4.2.8"
39
+ # listen current is a bit broken
40
+ # http://stackoverflow.com/questions/21319753/readline-seems-to-be-broken
41
+ spec.add_development_dependency "listen", "= 2.6.0"
38
42
  end
@@ -1,21 +1,23 @@
1
- require "spec_helper"
2
-
3
- describe Onebox::Engine::GithubGistOnebox do
4
- before(:all) do
5
- @link = "https://gist.github.com/anikalindtner/153044e9bea3331cc103"
6
- @uri = "https://api.github.com/gists/153044e9bea3331cc103"
7
- end
8
-
9
- include_context "engines"
10
- it_behaves_like "an engine"
11
-
12
- describe "#to_html" do
13
- it "includes sha" do
14
- expect(html).to include("153044e9bea3331cc103")
15
- end
16
-
17
- it "includes script" do
18
- expect(html).to include("script")
19
- end
20
- end
21
- end
1
+ # Broken for now
2
+ #
3
+ # require "spec_helper"
4
+ #
5
+ # describe Onebox::Engine::GithubGistOnebox do
6
+ # before(:all) do
7
+ # @link = "https://gist.github.com/anikalindtner/153044e9bea3331cc103"
8
+ # @uri = "https://api.github.com/gists/153044e9bea3331cc103"
9
+ # end
10
+ #
11
+ # include_context "engines"
12
+ # it_behaves_like "an engine"
13
+ #
14
+ # describe "#to_html" do
15
+ # it "includes sha" do
16
+ # expect(html).to include("153044e9bea3331cc103")
17
+ # end
18
+ #
19
+ # it "includes script" do
20
+ # expect(html).to include("script")
21
+ # end
22
+ # end
23
+ # end
@@ -2,16 +2,30 @@ require 'spec_helper'
2
2
 
3
3
  describe Onebox::Engine::YoutubeOnebox do
4
4
  before do
5
- fake("https://www.youtube.com/watch?v=21Lk4YiASMo", response("youtube"))
5
+ fake("http://www.youtube.com/watch?feature=player_embedded&v=21Lk4YiASMo", response("youtube"))
6
6
  fake("http://www.youtube.com/oembed?format=json&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D21Lk4YiASMo", response("youtube-json"))
7
7
  end
8
8
 
9
- it "should add wmode=opaque" do
9
+ it "adds wmode=opaque" do
10
10
  Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').to_s.should match(/wmode=opaque/)
11
11
  end
12
12
 
13
- it "should rewrite URLs to be agnostic" do
13
+ it "rewrites URLs to be agnostic" do
14
14
  Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').to_s.should match(/"\/\//)
15
15
  end
16
+
17
+ it "does not make HTTP requests unless necessary" do
18
+ # We haven't defined any fixture for requests associated with this ID, so if
19
+ # any HTTP requests are made fakeweb will complain and the test will fail.
20
+ Onebox.preview('http://www.youtube.com/watch?v=q39Ce3zDScI').to_s
21
+ end
22
+
23
+ it "does not fail if we cannot get the video ID from the URL" do
24
+ Onebox.preview('http://www.youtube.com/watch?feature=player_embedded&v=21Lk4YiASMo').to_s.should match(/embed/)
25
+ end
26
+
27
+ it "returns an image as the placeholder" do
28
+ Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').placeholder_html.should match(/<img/)
29
+ end
16
30
  end
17
31
 
@@ -1,6 +1,11 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Onebox do
4
+
5
+ before do
6
+ fake("http://www.amazon.com", response("amazon"))
7
+ end
8
+
4
9
  describe ".preview" do
5
10
  let(:url) { "http://www.amazon.com" }
6
11
  it "creates a cache that responds as expected" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joanna Zeta
@@ -10,232 +10,260 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-03-06 00:00:00.000000000 Z
13
+ date: 2014-03-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ~>
19
+ - - "~>"
20
20
  - !ruby/object:Gem::Version
21
21
  version: '1.7'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ~>
26
+ - - "~>"
27
27
  - !ruby/object:Gem::Version
28
28
  version: '1.7'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: mustache
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ~>
33
+ - - "~>"
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0.99'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ~>
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0.99'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: nokogiri
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ~>
47
+ - - "~>"
48
48
  - !ruby/object:Gem::Version
49
49
  version: 1.6.1
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ~>
54
+ - - "~>"
55
55
  - !ruby/object:Gem::Version
56
56
  version: 1.6.1
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: opengraph_parser
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ~>
61
+ - - "~>"
62
62
  - !ruby/object:Gem::Version
63
63
  version: 0.2.3
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ~>
68
+ - - "~>"
69
69
  - !ruby/object:Gem::Version
70
70
  version: 0.2.3
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: hexpress
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ~>
75
+ - - "~>"
76
76
  - !ruby/object:Gem::Version
77
77
  version: '1.2'
78
78
  type: :runtime
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ~>
82
+ - - "~>"
83
83
  - !ruby/object:Gem::Version
84
84
  version: '1.2'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: moneta
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ~>
89
+ - - "~>"
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0.7'
92
92
  type: :runtime
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ~>
96
+ - - "~>"
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0.7'
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: bundler
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ~>
103
+ - - "~>"
104
104
  - !ruby/object:Gem::Version
105
105
  version: '1.3'
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - ~>
110
+ - - "~>"
111
111
  - !ruby/object:Gem::Version
112
112
  version: '1.3'
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rake
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - ~>
117
+ - - "~>"
118
118
  - !ruby/object:Gem::Version
119
119
  version: '10.0'
120
120
  type: :development
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - ~>
124
+ - - "~>"
125
125
  - !ruby/object:Gem::Version
126
126
  version: '10.0'
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: rspec
129
129
  requirement: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - ~>
131
+ - - "~>"
132
132
  - !ruby/object:Gem::Version
133
133
  version: '2.14'
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - ~>
138
+ - - "~>"
139
139
  - !ruby/object:Gem::Version
140
140
  version: '2.14'
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: coveralls
143
143
  requirement: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - ~>
145
+ - - "~>"
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0.6'
148
148
  type: :development
149
149
  prerelease: false
150
150
  version_requirements: !ruby/object:Gem::Requirement
151
151
  requirements:
152
- - - ~>
152
+ - - "~>"
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0.6'
155
155
  - !ruby/object:Gem::Dependency
156
156
  name: yard
157
157
  requirement: !ruby/object:Gem::Requirement
158
158
  requirements:
159
- - - ~>
159
+ - - "~>"
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0.8'
162
162
  type: :development
163
163
  prerelease: false
164
164
  version_requirements: !ruby/object:Gem::Requirement
165
165
  requirements:
166
- - - ~>
166
+ - - "~>"
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0.8'
169
169
  - !ruby/object:Gem::Dependency
170
170
  name: fakeweb
171
171
  requirement: !ruby/object:Gem::Requirement
172
172
  requirements:
173
- - - ~>
173
+ - - "~>"
174
174
  - !ruby/object:Gem::Version
175
175
  version: '1.3'
176
176
  type: :development
177
177
  prerelease: false
178
178
  version_requirements: !ruby/object:Gem::Requirement
179
179
  requirements:
180
- - - ~>
180
+ - - "~>"
181
181
  - !ruby/object:Gem::Version
182
182
  version: '1.3'
183
183
  - !ruby/object:Gem::Dependency
184
184
  name: pry
185
185
  requirement: !ruby/object:Gem::Requirement
186
186
  requirements:
187
- - - ~>
187
+ - - "~>"
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0.9'
190
190
  type: :development
191
191
  prerelease: false
192
192
  version_requirements: !ruby/object:Gem::Requirement
193
193
  requirements:
194
- - - ~>
194
+ - - "~>"
195
195
  - !ruby/object:Gem::Version
196
196
  version: '0.9'
197
197
  - !ruby/object:Gem::Dependency
198
198
  name: mocha
199
199
  requirement: !ruby/object:Gem::Requirement
200
200
  requirements:
201
- - - ~>
201
+ - - "~>"
202
202
  - !ruby/object:Gem::Version
203
203
  version: '0.14'
204
204
  type: :development
205
205
  prerelease: false
206
206
  version_requirements: !ruby/object:Gem::Requirement
207
207
  requirements:
208
- - - ~>
208
+ - - "~>"
209
209
  - !ruby/object:Gem::Version
210
210
  version: '0.14'
211
211
  - !ruby/object:Gem::Dependency
212
212
  name: rubocop
213
213
  requirement: !ruby/object:Gem::Requirement
214
214
  requirements:
215
- - - ~>
215
+ - - "~>"
216
216
  - !ruby/object:Gem::Version
217
217
  version: '0.11'
218
218
  type: :development
219
219
  prerelease: false
220
220
  version_requirements: !ruby/object:Gem::Requirement
221
221
  requirements:
222
- - - ~>
222
+ - - "~>"
223
223
  - !ruby/object:Gem::Version
224
224
  version: '0.11'
225
225
  - !ruby/object:Gem::Dependency
226
226
  name: twitter
227
227
  requirement: !ruby/object:Gem::Requirement
228
228
  requirements:
229
- - - ~>
229
+ - - "~>"
230
230
  - !ruby/object:Gem::Version
231
231
  version: '4.8'
232
232
  type: :development
233
233
  prerelease: false
234
234
  version_requirements: !ruby/object:Gem::Requirement
235
235
  requirements:
236
- - - ~>
236
+ - - "~>"
237
237
  - !ruby/object:Gem::Version
238
238
  version: '4.8'
239
+ - !ruby/object:Gem::Dependency
240
+ name: guard-rspec
241
+ requirement: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - "~>"
244
+ - !ruby/object:Gem::Version
245
+ version: 4.2.8
246
+ type: :development
247
+ prerelease: false
248
+ version_requirements: !ruby/object:Gem::Requirement
249
+ requirements:
250
+ - - "~>"
251
+ - !ruby/object:Gem::Version
252
+ version: 4.2.8
253
+ - !ruby/object:Gem::Dependency
254
+ name: listen
255
+ requirement: !ruby/object:Gem::Requirement
256
+ requirements:
257
+ - - '='
258
+ - !ruby/object:Gem::Version
259
+ version: 2.6.0
260
+ type: :development
261
+ prerelease: false
262
+ version_requirements: !ruby/object:Gem::Requirement
263
+ requirements:
264
+ - - '='
265
+ - !ruby/object:Gem::Version
266
+ version: 2.6.0
239
267
  description: A gem for turning URLs into previews.
240
268
  email:
241
269
  - holla@jzeta.com
@@ -245,13 +273,13 @@ executables: []
245
273
  extensions: []
246
274
  extra_rdoc_files: []
247
275
  files:
248
- - .gitignore
249
- - .rspec
250
- - .rubocop.yml
251
- - .ruby-gemset
252
- - .ruby-version
253
- - .travis.yml
276
+ - ".gitignore"
277
+ - ".rspec"
278
+ - ".rubocop.yml"
279
+ - ".ruby-gemset"
280
+ - ".travis.yml"
254
281
  - Gemfile
282
+ - Guardfile
255
283
  - LICENSE.txt
256
284
  - README.md
257
285
  - Rakefile
@@ -340,17 +368,17 @@ require_paths:
340
368
  - lib
341
369
  required_ruby_version: !ruby/object:Gem::Requirement
342
370
  requirements:
343
- - - '>='
371
+ - - ">="
344
372
  - !ruby/object:Gem::Version
345
373
  version: '0'
346
374
  required_rubygems_version: !ruby/object:Gem::Requirement
347
375
  requirements:
348
- - - '>='
376
+ - - ">="
349
377
  - !ruby/object:Gem::Version
350
378
  version: '0'
351
379
  requirements: []
352
380
  rubyforge_project:
353
- rubygems_version: 2.0.6
381
+ rubygems_version: 2.2.0
354
382
  signing_key:
355
383
  specification_version: 4
356
384
  summary: A gem for turning URLs into previews.
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-2.0.0