ruby-oembed 0.9.0 → 0.10.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/.travis.yml +5 -3
- data/CHANGELOG.rdoc +7 -0
- data/Gemfile +6 -0
- data/Guardfile +35 -0
- data/README.rdoc +3 -1
- data/lib/oembed/formatter/base.rb +27 -24
- data/lib/oembed/formatter/json/backends/jsongem.rb +4 -4
- data/lib/oembed/http_helper.rb +2 -0
- data/lib/oembed/provider_discovery.rb +4 -4
- data/lib/oembed/providers/embedly_urls.yml +26 -17
- data/lib/oembed/providers.rb +25 -0
- data/lib/oembed/version.rb +1 -1
- data/spec/cassettes/OEmbed_ProviderDiscovery.yml +21625 -0
- data/spec/formatter/json/jsongem_backend_spec.rb +22 -10
- data/spec/provider_discovery_spec.rb +81 -65
- metadata +3 -2
@@ -1,19 +1,31 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
require 'json'
|
2
3
|
|
3
|
-
describe "
|
4
|
-
|
4
|
+
describe "Setting JSON.backend = 'JSONGem'" do
|
5
|
+
context "without the JSON object defined" do
|
6
|
+
it "should fail" do
|
7
|
+
expect(OEmbed::Formatter::JSON).to receive(:already_loaded?).with('JSONGem').and_return(false)
|
8
|
+
expect(Object).to receive(:const_defined?).with('JSON').and_return(false)
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
expect {
|
11
|
+
OEmbed::Formatter::JSON.backend = 'JSONGem'
|
12
|
+
}.to raise_error(LoadError)
|
13
|
+
end
|
14
|
+
end
|
10
15
|
|
11
|
-
|
16
|
+
context "with the JSON object loaded" do
|
17
|
+
it "should work" do
|
18
|
+
expect(OEmbed::Formatter::JSON).to receive(:already_loaded?).with('JSONGem').and_return(false)
|
12
19
|
|
13
|
-
|
14
|
-
|
15
|
-
|
20
|
+
expect {
|
21
|
+
OEmbed::Formatter::JSON.backend = 'JSONGem'
|
22
|
+
}.to_not raise_error
|
23
|
+
end
|
16
24
|
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "OEmbed::Formatter::JSON::Backends::JSONGem" do
|
28
|
+
include OEmbedSpecHelper
|
17
29
|
|
18
30
|
it "should support JSON" do
|
19
31
|
expect {
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require 'json'
|
2
3
|
require 'vcr'
|
3
4
|
|
4
5
|
VCR.config do |c|
|
@@ -9,6 +10,7 @@ end
|
|
9
10
|
|
10
11
|
describe OEmbed::ProviderDiscovery do
|
11
12
|
before(:all) do
|
13
|
+
OEmbed::Formatter::JSON.backend = 'JSONGem'
|
12
14
|
VCR.insert_cassette('OEmbed_ProviderDiscovery')
|
13
15
|
end
|
14
16
|
after(:all) do
|
@@ -18,97 +20,111 @@ describe OEmbed::ProviderDiscovery do
|
|
18
20
|
include OEmbedSpecHelper
|
19
21
|
|
20
22
|
{
|
23
|
+
# 'name' => [
|
24
|
+
# 'given_page_url',
|
25
|
+
# 'expected_endpoint' || {:json=>'expected_json_endpoint', :xml=>'expected_xml_endpoint},
|
26
|
+
# :expected_format,
|
27
|
+
# ]
|
21
28
|
'youtube' => [
|
22
29
|
'http://www.youtube.com/watch?v=u6XAPnuFjJc',
|
23
|
-
'http://www.youtube.com/oembed',
|
30
|
+
{:json=>'http://www.youtube.com/oembed', :xml=>'http://www.youtube.com/oembed'},
|
24
31
|
:json,
|
25
32
|
],
|
26
33
|
'vimeo' => [
|
27
34
|
'http://vimeo.com/27953845',
|
28
|
-
{:json=>'http://vimeo.com/api/oembed.json'
|
35
|
+
{:json=>'http://vimeo.com/api/oembed.json', :xml=>'http://vimeo.com/api/oembed.xml'},
|
29
36
|
:json,
|
30
37
|
],
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
38
|
+
'facebook-photo' => [
|
39
|
+
'https://www.facebook.com/Federer/photos/pb.64760994940.-2207520000.1456668968./10153235368269941/?type=3&theater',
|
40
|
+
'https://www.facebook.com/plugins/post/oembed.json/',
|
41
|
+
:json,
|
42
|
+
],
|
43
|
+
'tumblr' => [
|
44
|
+
'http://kittehkats.tumblr.com/post/140525169406/katydid-and-the-egg-happy-forest-family',
|
45
|
+
'https://www.tumblr.com/oembed/1.0',
|
46
|
+
:json
|
47
|
+
],
|
48
|
+
'noteflight' => [
|
49
|
+
'http://www.noteflight.com/scores/view/09665392c94475f65dfaf5f30aadb6ed0921939d',
|
50
|
+
{:json=>'http://www.noteflight.com/services/oembed', :xml=>'http://www.noteflight.com/services/oembed'},
|
51
|
+
:json,
|
52
|
+
],
|
53
|
+
# TODO: Enhance ProviderDiscovery to support arbitrary query parameters. See https://github.com/judofyr/ruby-oembed/issues/15
|
36
54
|
#'wordpress' => [
|
37
55
|
# 'http://sweetandweak.wordpress.com/2011/09/23/nothing-starts-the-morning-like-a-good-dose-of-panic/',
|
38
|
-
# '
|
56
|
+
# {:json=>'https://public-api.wordpress.com/oembed/1.0/', :xml=>'https://public-api.wordpress.com/oembed/1.0/'},
|
39
57
|
# :json,
|
40
58
|
#],
|
41
59
|
}.each do |context, urls|
|
42
60
|
|
43
|
-
given_url,
|
44
|
-
|
45
|
-
context "with #{context} url" do
|
61
|
+
given_url, expected_endpoints, expected_format = urls
|
62
|
+
expected_endpoints = {expected_format=>expected_endpoints} unless expected_endpoints.is_a?(Hash)
|
46
63
|
|
47
|
-
|
64
|
+
context "given a #{context} url" do
|
48
65
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
it "should return the correct Class" do
|
56
|
-
expect(@provider_default).to be_instance_of(OEmbed::Provider)
|
57
|
-
expect(@provider_json).to be_instance_of(OEmbed::Provider)
|
58
|
-
expect(@provider_xml).to be_instance_of(OEmbed::Provider)
|
59
|
-
end
|
66
|
+
shared_examples "a discover_provider call" do |endpoint, format|
|
67
|
+
describe ".discover_provider" do
|
68
|
+
it "should return the correct Class" do
|
69
|
+
expect(provider).to be_instance_of(OEmbed::Provider)
|
70
|
+
end
|
60
71
|
|
61
|
-
|
62
|
-
|
63
|
-
expect(@provider_json.endpoint).to eq(expected_endpoint[expected_format])
|
64
|
-
expect(@provider_json.endpoint).to eq(expected_endpoint[:json])
|
65
|
-
expect(@provider_xml.endpoint).to eq(expected_endpoint[:xml])
|
66
|
-
else
|
67
|
-
expect(@provider_default.endpoint).to eq(expected_endpoint)
|
68
|
-
expect(@provider_json.endpoint).to eq(expected_endpoint)
|
69
|
-
expect(@provider_xml.endpoint).to eq(expected_endpoint)
|
72
|
+
it "should detect the correct URL" do
|
73
|
+
expect(provider.endpoint).to eq(endpoint)
|
70
74
|
end
|
71
|
-
end
|
72
75
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
expect(@provider_xml.format).to eq(:xml)
|
76
|
+
it "should return the correct format" do
|
77
|
+
expect(provider.format).to eq(format)
|
78
|
+
end
|
77
79
|
end
|
78
|
-
end # discover_provider
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
@response_json = OEmbed::ProviderDiscovery.get(given_url, :format=>:json)
|
85
|
-
@response_xml = OEmbed::ProviderDiscovery.get(given_url, :format=>:xml)
|
86
|
-
end
|
81
|
+
describe ".get" do
|
82
|
+
it "should return the correct Class" do
|
83
|
+
expect(response).to be_kind_of(OEmbed::Response)
|
84
|
+
end
|
87
85
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
expect(@response_xml).to be_kind_of(OEmbed::Response)
|
92
|
-
end
|
86
|
+
it "should return the correct format" do
|
87
|
+
expect(response.format).to eq(format.to_s)
|
88
|
+
end
|
93
89
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
90
|
+
it "should return the correct data" do
|
91
|
+
expect(response.type).to_not be_empty
|
92
|
+
|
93
|
+
case response.type
|
94
|
+
when 'video', 'rich'
|
95
|
+
expect(response.html).to_not be_empty
|
96
|
+
expect(response.width).to_not be_nil
|
97
|
+
expect(response.height).to_not be_nil
|
98
|
+
when 'photo'
|
99
|
+
expect(response.url).to_not be_empty
|
100
|
+
expect(response.width).to_not be_nil
|
101
|
+
expect(response.height).to_not be_nil
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end # get
|
105
|
+
end
|
106
|
+
|
107
|
+
context "with no format specified" do
|
108
|
+
let(:provider) { OEmbed::ProviderDiscovery.discover_provider(given_url) }
|
109
|
+
let(:response) { OEmbed::ProviderDiscovery.get(given_url) }
|
110
|
+
include_examples "a discover_provider call", expected_endpoints[expected_format], expected_format
|
111
|
+
end
|
112
|
+
|
113
|
+
if expected_endpoints.include?(:json)
|
114
|
+
context "with json format specified" do
|
115
|
+
let(:provider) { OEmbed::ProviderDiscovery.discover_provider(given_url, :format=>:json) }
|
116
|
+
let(:response) { OEmbed::ProviderDiscovery.get(given_url, :format=>:json) }
|
117
|
+
include_examples "a discover_provider call", expected_endpoints[:json], :json
|
98
118
|
end
|
119
|
+
end
|
99
120
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
# Technically, the following values _could_ be blank, but for the
|
106
|
-
# examples urls we're using we expect them not to be.
|
107
|
-
expect(@response_default.title).to_not be_nil
|
108
|
-
expect(@response_json.title).to_not be_nil
|
109
|
-
expect(@response_xml.title).to_not be_nil
|
121
|
+
if expected_endpoints.include?(:xml)
|
122
|
+
context "with json format specified" do
|
123
|
+
let(:provider) { OEmbed::ProviderDiscovery.discover_provider(given_url, :format=>:xml) }
|
124
|
+
let(:response) { OEmbed::ProviderDiscovery.get(given_url, :format=>:xml) }
|
125
|
+
include_examples "a discover_provider call", expected_endpoints[:xml], :xml
|
110
126
|
end
|
111
|
-
end
|
127
|
+
end
|
112
128
|
end
|
113
129
|
|
114
130
|
end # each service
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-oembed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Holm
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- ".yardopts"
|
128
128
|
- CHANGELOG.rdoc
|
129
129
|
- Gemfile
|
130
|
+
- Guardfile
|
130
131
|
- LICENSE
|
131
132
|
- README.rdoc
|
132
133
|
- Rakefile
|
@@ -184,7 +185,7 @@ rdoc_options:
|
|
184
185
|
- "--main"
|
185
186
|
- README.rdoc
|
186
187
|
- "--title"
|
187
|
-
- ruby-oembed-0.
|
188
|
+
- ruby-oembed-0.10.0
|
188
189
|
- "--inline-source"
|
189
190
|
- "--exclude"
|
190
191
|
- tasks
|