onebox 1.5.20 → 1.5.21

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: ecd245b860952c9a28eb5447bc161ac33faf88c7
4
- data.tar.gz: 22c1a7591f80bc67dad9b9b496de3351b167958c
3
+ metadata.gz: d81ab9ca72a2dea627e57a27c47f38afce6cfaca
4
+ data.tar.gz: 01a0b589ea13c180bf59d83acd4a41b96f156d75
5
5
  SHA512:
6
- metadata.gz: 7007497474adad17ad08fefe10c19dfe3a1a5c785b2dfe6de0d34895ef7788b71cfa5d8b31510f4201ba07ace156c7496accf17c14ffea36a0cd2b00385a7a2b
7
- data.tar.gz: 29b0731949d0efdd0285d15b8e920df917725a022f64c2245dbbde689bc70b5ed3fbbe278091d990423f0f220decf33174a8198ee85e2cda613de92cb09266bb
6
+ metadata.gz: e6cfa6120bdbb68a11343f8858e528767d29e94e6fcec54e1c6b60c9ed1e513de6f311cdb5d461f6b0ed090ccd4ec4279e56e0c0ac57ad0a3d5f9448f9563298
7
+ data.tar.gz: 5cddf24c71ff367a226c41cd1b399c4ba288317879ab1537c0b1209ee3179a5a6681c7d676984f8ce464f0d973386858b24f9c3f3116c7c0e300dfe2643c882a
data/README.md CHANGED
@@ -87,7 +87,7 @@ Adding Support for a new URL
87
87
  ============================
88
88
 
89
89
  1. Check if the site supports [oEmbed](http://oembed.com/) or [Open Graph](https://developers.facebook.com/docs/opengraph/).
90
- If it does, you can probably get away with just whitelisting the URL in `Onebox::Engine::WhitelistedGenericOnebox`.
90
+ If it does, you can probably get away with just whitelisting the URL in `Onebox::Engine::WhitelistedGenericOnebox` (see: [Whitelisted Generic Onebox caveats](#user-content-whitelisted-generic-onebox-caveats)).
91
91
  If the site does not support open standards, you can create a new engine.
92
92
 
93
93
  2. Create new onebox engine
@@ -176,12 +176,22 @@ Adding Support for a new URL
176
176
  ```
177
177
 
178
178
 
179
+ Whitelisted Generic Onebox caveats
180
+ ==================================
181
+
182
+ The Whitedlisted Generic Onebox has some caveats for it's use, beyond simply whitelisting the domain.
183
+
184
+ 1. The domain must be whitelisted
185
+ 2. The URL you're oneboxing cannot be a root url (e.g. `http://example.com` won't work, but `http://example.com/page` will)
186
+ 3. If the oneboxed URL responds with oEmbed and has a `rich` type: the `html` content must contain an `<iframe>`. Responses without an iframe will not be oneboxed.
187
+
188
+
179
189
  Installing
180
190
  ==========
181
191
 
182
192
  Add this line to your application's Gemfile:
183
193
 
184
- gem "onebox", "~> 1.2"
194
+ gem "onebox"
185
195
 
186
196
  And then execute:
187
197
 
@@ -192,6 +202,12 @@ Or install it yourself as:
192
202
  $ gem install onebox
193
203
 
194
204
 
205
+ Issues / Discussion
206
+ ===================
207
+
208
+ Discussion of the Onebox gem, its development and features should be done on
209
+ [Discourse Meta](https://meta.discourse.org).
210
+
195
211
  Contributing
196
212
  ============
197
213
 
data/lib/onebox.rb CHANGED
@@ -23,6 +23,10 @@ module Onebox
23
23
  Preview.new(url, options)
24
24
  end
25
25
 
26
+ def self.check(url, options = Onebox.options)
27
+ StatusCheck.new(url, options)
28
+ end
29
+
26
30
  def self.options
27
31
  OpenStruct.new(@@options)
28
32
  end
@@ -39,6 +43,7 @@ end
39
43
 
40
44
  require_relative "onebox/version"
41
45
  require_relative "onebox/preview"
46
+ require_relative "onebox/status_check"
42
47
  require_relative "onebox/matcher"
43
48
  require_relative "onebox/engine"
44
49
  require_relative "onebox/layout"
@@ -0,0 +1,44 @@
1
+ module Onebox
2
+ class StatusCheck
3
+ def initialize(url, options = Onebox.options)
4
+ @url = url
5
+ @options = options
6
+ @status = -1
7
+ end
8
+
9
+ def ok?
10
+ status > 199 && status < 300
11
+ end
12
+
13
+ def status
14
+ check if @status == -1
15
+ @status
16
+ end
17
+
18
+ def human_status
19
+ case status
20
+ when 0
21
+ :connection_error
22
+ when 200..299
23
+ :success
24
+ when 400..499
25
+ :client_error
26
+ when 500..599
27
+ :server_error
28
+ else
29
+ :unknown_error
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def check
36
+ res = open(@url, read_timeout: (@options.timeout || Onebox.options.timeout))
37
+ @status = res.status.first.to_i
38
+ rescue OpenURI::HTTPError => e
39
+ @status = e.io.status.first.to_i
40
+ rescue Timeout::Error, Errno::ECONNREFUSED, Net::HTTPError
41
+ @status = 0
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Onebox
2
- VERSION = "1.5.20"
2
+ VERSION = "1.5.21"
3
3
  end
@@ -0,0 +1,68 @@
1
+ require "spec_helper"
2
+
3
+ describe Onebox::StatusCheck do
4
+ before do
5
+ FakeWeb.register_uri(:get, "http://www.amazon.com/200-url", status: 200)
6
+ FakeWeb.register_uri(:get, "http://www.amazon.com/201-url", status: 201)
7
+ FakeWeb.register_uri(:get, "http://www.amazon.com/401-url", status: 401)
8
+ FakeWeb.register_uri(:get, "http://www.amazon.com/403-url", status: 403)
9
+ FakeWeb.register_uri(:get, "http://www.amazon.com/404-url", status: 404)
10
+ FakeWeb.register_uri(:get, "http://www.amazon.com/500-url", status: 500)
11
+ FakeWeb.register_uri(:get, "http://www.amazon.com/503-url", status: 503)
12
+ FakeWeb.register_uri(:get, "http://www.amazon.com/timeout-url", exception: Timeout::Error)
13
+ FakeWeb.register_uri(:get, "http://www.amazon.com/http-error", exception: Net::HTTPError)
14
+ FakeWeb.register_uri(:get, "http://www.amazon.com/error-connecting", exception: Errno::ECONNREFUSED)
15
+ end
16
+
17
+ describe '#human_status' do
18
+ it 'returns :success on HTTP status code 200' do
19
+ expect(described_class.new("http://www.amazon.com/200-url").human_status).to eq(:success)
20
+ end
21
+
22
+ it 'returns :success on HTTP status code 201' do
23
+ expect(described_class.new("http://www.amazon.com/201-url").human_status).to eq(:success)
24
+ end
25
+
26
+ it 'returns :client_error on HTTP status code 401' do
27
+ expect(described_class.new("http://www.amazon.com/401-url").human_status).to eq(:client_error)
28
+ end
29
+
30
+ it 'returns :client_error on HTTP status code 403' do
31
+ expect(described_class.new("http://www.amazon.com/403-url").human_status).to eq(:client_error)
32
+ end
33
+
34
+ it 'returns :client_error on HTTP status code 404' do
35
+ expect(described_class.new("http://www.amazon.com/404-url").human_status).to eq(:client_error)
36
+ end
37
+
38
+ it 'returns :server_error on HTTP status code 500' do
39
+ expect(described_class.new("http://www.amazon.com/500-url").human_status).to eq(:server_error)
40
+ end
41
+
42
+ it 'returns :server_error on HTTP status code 503' do
43
+ expect(described_class.new("http://www.amazon.com/503-url").human_status).to eq(:server_error)
44
+ end
45
+
46
+ it 'returns :connection_error if there is a connection refused error' do
47
+ expect(described_class.new("http://www.amazon.com/error-connecting").human_status).to eq(:connection_error)
48
+ end
49
+
50
+ it 'returns :connection_error if there is a timeout error' do
51
+ expect(described_class.new("http://www.amazon.com/timeout-url").human_status).to eq(:connection_error)
52
+ end
53
+
54
+ it 'returns :connection_error if there is a general HTTP error' do
55
+ expect(described_class.new("http://www.amazon.com/http-error").human_status).to eq(:connection_error)
56
+ end
57
+ end
58
+
59
+ describe '#ok?' do
60
+ it 'returns true for HTTP status codes 200-299' do
61
+ expect(described_class.new("http://www.amazon.com/200-url").ok?).to be true
62
+ end
63
+
64
+ it 'returns false for any status codes other than 200-299' do
65
+ expect(described_class.new("http://www.amazon.com/404-url").ok?).to be false
66
+ end
67
+ end
68
+ end
@@ -23,7 +23,7 @@
23
23
 
24
24
  <pre class='content' style="white-space: pre-wrap;">{{content}}</pre>
25
25
 
26
- <div class='lables'>
26
+ <div class='labels'>
27
27
  {{#labels}}
28
28
  <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">{{name}}</span>
29
29
  {{/labels}}
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.5.20
4
+ version: 1.5.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joanna Zeta
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-06-10 00:00:00.000000000 Z
13
+ date: 2015-06-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
@@ -316,6 +316,7 @@ files:
316
316
  - lib/onebox/layout_support.rb
317
317
  - lib/onebox/matcher.rb
318
318
  - lib/onebox/preview.rb
319
+ - lib/onebox/status_check.rb
319
320
  - lib/onebox/template_support.rb
320
321
  - lib/onebox/version.rb
321
322
  - lib/onebox/view.rb
@@ -368,6 +369,7 @@ files:
368
369
  - spec/lib/onebox/layout_spec.rb
369
370
  - spec/lib/onebox/matcher_spec.rb
370
371
  - spec/lib/onebox/preview_spec.rb
372
+ - spec/lib/onebox/status_check_spec.rb
371
373
  - spec/lib/onebox_spec.rb
372
374
  - spec/spec_helper.rb
373
375
  - spec/support/html_spec_helper.rb
@@ -411,7 +413,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
411
413
  version: '0'
412
414
  requirements: []
413
415
  rubyforge_project:
414
- rubygems_version: 2.4.3
416
+ rubygems_version: 2.4.6
415
417
  signing_key:
416
418
  specification_version: 4
417
419
  summary: A gem for turning URLs into previews.
@@ -462,6 +464,7 @@ test_files:
462
464
  - spec/lib/onebox/layout_spec.rb
463
465
  - spec/lib/onebox/matcher_spec.rb
464
466
  - spec/lib/onebox/preview_spec.rb
467
+ - spec/lib/onebox/status_check_spec.rb
465
468
  - spec/lib/onebox_spec.rb
466
469
  - spec/spec_helper.rb
467
470
  - spec/support/html_spec_helper.rb