ruby-oembed 0.14.0 → 0.16.1

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -2
  3. data/CHANGELOG.rdoc +25 -2
  4. data/README.md +5 -7
  5. data/lib/oembed/provider.rb +54 -5
  6. data/lib/oembed/providers/builtin_providers.rb +292 -0
  7. data/lib/oembed/providers/facebook_post.rb +27 -17
  8. data/lib/oembed/providers/facebook_video.rb +22 -10
  9. data/lib/oembed/providers/instagram.rb +37 -20
  10. data/lib/oembed/providers/tiktok.rb +13 -0
  11. data/lib/oembed/providers.rb +39 -300
  12. data/lib/oembed/version.rb +2 -2
  13. data/lib/oembed.rb +1 -0
  14. data/ruby-oembed.gemspec +1 -2
  15. metadata +9 -53
  16. data/integration_test/test.rb +0 -31
  17. data/integration_test/test_urls.csv +0 -502
  18. data/spec/cassettes/OEmbed_Provider.yml +0 -987
  19. data/spec/cassettes/OEmbed_ProviderDiscovery.yml +0 -27184
  20. data/spec/cassettes/OEmbed_Providers_Slideshare.yml +0 -1433
  21. data/spec/cassettes/OEmbed_Providers_Twitter.yml +0 -612
  22. data/spec/formatter/ducktype_backend_spec.rb +0 -94
  23. data/spec/formatter/json/.DS_Store +0 -0
  24. data/spec/formatter/json/jsongem_backend_spec.rb +0 -71
  25. data/spec/formatter/json/yaml_backend_spec.rb +0 -55
  26. data/spec/formatter/xml/nokogiri_backend_spec.rb +0 -59
  27. data/spec/formatter/xml/rexml_backend_spec.rb +0 -55
  28. data/spec/formatter/xml/xmlsimple_backend_spec.rb +0 -59
  29. data/spec/formatter_spec.rb +0 -37
  30. data/spec/provider_discovery_spec.rb +0 -141
  31. data/spec/provider_spec.rb +0 -366
  32. data/spec/providers/facebook_spec.rb +0 -50
  33. data/spec/providers/slideshare_spec.rb +0 -42
  34. data/spec/providers/twitter_spec.rb +0 -44
  35. data/spec/providers_spec.rb +0 -306
  36. data/spec/response_spec.rb +0 -230
  37. data/spec/spec_helper.rb +0 -111
  38. data/spec/spec_helper_examples.yml +0 -27
  39. data/spec/support/shared_examples_for_providers.rb +0 -39
Binary file
@@ -1,71 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require 'json'
3
-
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)
9
-
10
- expect {
11
- OEmbed::Formatter::JSON.backend = 'JSONGem'
12
- }.to raise_error(LoadError)
13
- end
14
- end
15
-
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)
19
-
20
- expect {
21
- OEmbed::Formatter::JSON.backend = 'JSONGem'
22
- }.to_not raise_error
23
- end
24
- end
25
- end
26
-
27
- describe "OEmbed::Formatter::JSON::Backends::JSONGem" do
28
- include OEmbedSpecHelper
29
-
30
- it "should support JSON" do
31
- expect {
32
- OEmbed::Formatter.supported?(:json)
33
- }.to_not raise_error
34
- end
35
-
36
- it "should be using the JSONGem backend" do
37
- expect(OEmbed::Formatter::JSON.backend).to eq(OEmbed::Formatter::JSON::Backends::JSONGem)
38
- end
39
-
40
- it "should decode a JSON String" do
41
- decoded = OEmbed::Formatter.decode(:json, valid_response(:json))
42
- # We need to compare keys & values separately because we don't expect all
43
- # non-string values to be recognized correctly.
44
- expect(decoded.keys).to eq(valid_response(:object).keys)
45
- expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
46
- end
47
-
48
- it "should raise an OEmbed::ParseError when decoding an invalid JSON String" do
49
- expect {
50
- decode = OEmbed::Formatter.decode(:json, invalid_response('unclosed_container', :json))
51
- }.to raise_error(OEmbed::ParseError)
52
- expect {
53
- decode = OEmbed::Formatter.decode(:json, invalid_response('unclosed_tag', :json))
54
- }.to raise_error(OEmbed::ParseError)
55
- expect {
56
- decode = OEmbed::Formatter.decode(:json, invalid_response('invalid_syntax', :json))
57
- }.to raise_error(OEmbed::ParseError)
58
- end
59
-
60
- it "should raise an OEmbed::ParseError when decoding fails with an unexpected error" do
61
- error_to_raise = ArgumentError
62
- expect(OEmbed::Formatter::JSON.backend.parse_error).to_not be_kind_of(error_to_raise)
63
-
64
- expect(::JSON).to receive(:parse).
65
- and_throw(error_to_raise.new("unknown error"))
66
-
67
- expect {
68
- decode = OEmbed::Formatter.decode(:json, valid_response(:json))
69
- }.to raise_error(OEmbed::ParseError)
70
- end
71
- end
@@ -1,55 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "OEmbed::Formatter::JSON::Backends::Yaml" do
4
- include OEmbedSpecHelper
5
-
6
- before(:all) do
7
- expect {
8
- OEmbed::Formatter::JSON.backend = 'Yaml'
9
- }.to_not raise_error
10
-
11
- expect(!!defined?(YAML)).to eq(true)
12
- end
13
-
14
- it "should support JSON" do
15
- expect {
16
- OEmbed::Formatter.supported?(:json)
17
- }.to_not raise_error
18
- end
19
-
20
- it "should be using the Yaml backend" do
21
- expect(OEmbed::Formatter::JSON.backend).to eq(OEmbed::Formatter::JSON::Backends::Yaml)
22
- end
23
-
24
- it "should decode a JSON String" do
25
- decoded = OEmbed::Formatter.decode(:json, valid_response(:json))
26
- # We need to compare keys & values separately because we don't expect all
27
- # non-string values to be recognized correctly.
28
- expect(decoded.keys).to eq(valid_response(:object).keys)
29
- expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
30
- end
31
-
32
- it "should raise an OEmbed::ParseError when decoding an invalid JSON String" do
33
- expect {
34
- decode = OEmbed::Formatter.decode(:json, invalid_response('unclosed_container', :json))
35
- }.to raise_error(OEmbed::ParseError)
36
- expect {
37
- decode = OEmbed::Formatter.decode(:json, invalid_response('unclosed_tag', :json))
38
- }.to raise_error(OEmbed::ParseError)
39
- expect {
40
- decode = OEmbed::Formatter.decode(:json, invalid_response('invalid_syntax', :json))
41
- }.to raise_error(OEmbed::ParseError)
42
- end
43
-
44
- it "should raise an OEmbed::ParseError when decoding fails with an unexpected error" do
45
- error_to_raise = ArgumentError
46
- expect(OEmbed::Formatter::JSON.backend.parse_error).to_not be_kind_of(error_to_raise)
47
-
48
- expect(OEmbed::Formatter::JSON.backend).to receive(:convert_json_to_yaml).
49
- and_throw(error_to_raise.new("unknown error"))
50
-
51
- expect {
52
- decode = OEmbed::Formatter.decode(:json, valid_response(:json))
53
- }.to raise_error(OEmbed::ParseError)
54
- end
55
- end
@@ -1,59 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "OEmbed::Formatter::XML::Backends::Nokogiri" do
4
- include OEmbedSpecHelper
5
-
6
- before(:all) do
7
- expect {
8
- OEmbed::Formatter::XML.backend = 'Nokogiri'
9
- }.to raise_error(LoadError)
10
-
11
- require 'nokogiri'
12
-
13
- expect {
14
- OEmbed::Formatter::XML.backend = 'Nokogiri'
15
- }.to_not raise_error
16
- end
17
-
18
- it "should support XML" do
19
- expect {
20
- OEmbed::Formatter.supported?(:xml)
21
- }.to_not raise_error
22
- end
23
-
24
- it "should be using the Nokogiri backend" do
25
- expect(OEmbed::Formatter::XML.backend).to eq(OEmbed::Formatter::XML::Backends::Nokogiri)
26
- end
27
-
28
- it "should decode an XML String" do
29
- decoded = OEmbed::Formatter.decode(:xml, valid_response(:xml))
30
- # We need to compare keys & values separately because we don't expect all
31
- # non-string values to be recognized correctly.
32
- expect(decoded.keys).to eq(valid_response(:object).keys)
33
- expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
34
- end
35
-
36
- it "should raise an OEmbed::ParseError when decoding an invalid XML String" do
37
- expect {
38
- decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_container', :xml))
39
- }.to raise_error(OEmbed::ParseError)
40
- expect {
41
- decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_tag', :xml))
42
- }.to raise_error(OEmbed::ParseError)
43
- expect {
44
- decode = OEmbed::Formatter.decode(:xml, invalid_response('invalid_syntax', :xml))
45
- }.to raise_error(OEmbed::ParseError)
46
- end
47
-
48
- it "should raise an OEmbed::ParseError when decoding fails with an unexpected error" do
49
- error_to_raise = ArgumentError
50
- expect(OEmbed::Formatter::XML.backend.parse_error).to_not be_kind_of(error_to_raise)
51
-
52
- expect(::Nokogiri::XML::Document).to receive(:parse).
53
- and_raise(error_to_raise.new("unknown error"))
54
-
55
- expect {
56
- decode = OEmbed::Formatter.decode(:xml, valid_response(:xml))
57
- }.to raise_error(OEmbed::ParseError)
58
- end
59
- end
@@ -1,55 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "OEmbed::Formatter::XML::Backends::REXML" do
4
- include OEmbedSpecHelper
5
-
6
- before(:all) do
7
- expect {
8
- OEmbed::Formatter::XML.backend = 'REXML'
9
- }.to_not raise_error
10
-
11
- expect((!!defined?(REXML))).to eq(true)
12
- end
13
-
14
- it "should support XML" do
15
- expect {
16
- OEmbed::Formatter.supported?(:xml)
17
- }.to_not raise_error
18
- end
19
-
20
- it "should be using the XmlSimple backend" do
21
- expect(OEmbed::Formatter::XML.backend).to eq(OEmbed::Formatter::XML::Backends::REXML)
22
- end
23
-
24
- it "should decode an XML String" do
25
- decoded = OEmbed::Formatter.decode(:xml, valid_response(:xml))
26
- # We need to compare keys & values separately because we don't expect all
27
- # non-string values to be recognized correctly.
28
- expect(decoded.keys).to eq(valid_response(:object).keys)
29
- expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
30
- end
31
-
32
- it "should raise an OEmbed::ParseError when decoding an invalid XML String" do
33
- expect {
34
- decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_container', :xml))
35
- }.to raise_error(OEmbed::ParseError)
36
- expect {
37
- decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_tag', :xml))
38
- }.to raise_error(OEmbed::ParseError)
39
- expect {
40
- decode = OEmbed::Formatter.decode(:xml, invalid_response('invalid_syntax', :xml))
41
- }.to raise_error(OEmbed::ParseError)
42
- end
43
-
44
- it "should raise an OEmbed::ParseError when decoding fails with an unexpected error" do
45
- error_to_raise = ArgumentError
46
- expect(OEmbed::Formatter::XML.backend.parse_error).to_not be_kind_of(error_to_raise)
47
-
48
- expect(::REXML::Document).to receive(:new).
49
- and_raise(error_to_raise.new("unknown error"))
50
-
51
- expect {
52
- decode = OEmbed::Formatter.decode(:xml, valid_response(:xml))
53
- }.to raise_error(OEmbed::ParseError)
54
- end
55
- end
@@ -1,59 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "OEmbed::Formatter::XML::Backends::XmlSimple" do
4
- include OEmbedSpecHelper
5
-
6
- before(:all) do
7
- expect {
8
- OEmbed::Formatter::XML.backend = 'XmlSimple'
9
- }.to raise_error(LoadError)
10
-
11
- require 'xmlsimple'
12
-
13
- expect {
14
- OEmbed::Formatter::XML.backend = 'XmlSimple'
15
- }.to_not raise_error
16
- end
17
-
18
- it "should support XML" do
19
- expect {
20
- OEmbed::Formatter.supported?(:xml)
21
- }.to_not raise_error
22
- end
23
-
24
- it "should be using the XmlSimple backend" do
25
- expect(OEmbed::Formatter::XML.backend).to eq(OEmbed::Formatter::XML::Backends::XmlSimple)
26
- end
27
-
28
- it "should decode an XML String" do
29
- decoded = OEmbed::Formatter.decode(:xml, valid_response(:xml))
30
- # We need to compare keys & values separately because we don't expect all
31
- # non-string values to be recognized correctly.
32
- expect(decoded.keys).to eq(valid_response(:object).keys)
33
- expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
34
- end
35
-
36
- it "should raise an OEmbed::ParseError when decoding an invalid XML String" do
37
- expect {
38
- decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_container', :xml))
39
- }.to raise_error(OEmbed::ParseError)
40
- expect {
41
- decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_tag', :xml))
42
- }.to raise_error(OEmbed::ParseError)
43
- expect {
44
- decode = OEmbed::Formatter.decode(:xml, invalid_response('invalid_syntax', :xml))
45
- }.to raise_error(OEmbed::ParseError)
46
- end
47
-
48
- it "should raise an OEmbed::ParseError when decoding fails with an unexpected error" do
49
- error_to_raise = ArgumentError
50
- expect(OEmbed::Formatter::XML.backend.parse_error).to_not be_kind_of(error_to_raise)
51
-
52
- expect(::XmlSimple).to receive(:xml_in).
53
- and_raise(error_to_raise.new("unknown error"))
54
-
55
- expect {
56
- decode = OEmbed::Formatter.decode(:xml, valid_response(:xml))
57
- }.to raise_error(OEmbed::ParseError)
58
- end
59
- end
@@ -1,37 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe OEmbed::Formatter do
4
- include OEmbedSpecHelper
5
-
6
- it "should support JSON" do
7
- expect {
8
- OEmbed::Formatter.supported?(:json)
9
- }.to_not raise_error
10
- end
11
-
12
- it "should default to JSON" do
13
- expect(OEmbed::Formatter.default).to eq('json')
14
- end
15
-
16
- it "should decode a JSON String" do
17
- decoded = OEmbed::Formatter.decode(:json, valid_response(:json))
18
- # We need to compare keys & values separately because we don't expect all
19
- # non-string values to be recognized correctly.
20
- expect(decoded.keys).to eq(valid_response(:object).keys)
21
- expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
22
- end
23
-
24
- it "should support XML" do
25
- expect {
26
- OEmbed::Formatter.supported?(:xml)
27
- }.to_not raise_error
28
- end
29
-
30
- it "should decode an XML String" do
31
- decoded = OEmbed::Formatter.decode(:xml, valid_response(:xml))
32
- # We need to compare keys & values separately because we don't expect all
33
- # non-string values to be recognized correctly.
34
- expect(decoded.keys).to eq(valid_response(:object).keys)
35
- expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
36
- end
37
- end
@@ -1,141 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
- require 'json'
3
-
4
- describe OEmbed::ProviderDiscovery do
5
- before(:all) do
6
- OEmbed::Formatter::JSON.backend = 'JSONGem'
7
- VCR.insert_cassette('OEmbed_ProviderDiscovery')
8
- end
9
- after(:all) do
10
- VCR.eject_cassette
11
- end
12
-
13
- include OEmbedSpecHelper
14
-
15
- {
16
- # 'name' => [
17
- # 'given_page_url',
18
- # 'expected_endpoint' || {:json=>'expected_json_endpoint', :xml=>'expected_xml_endpoint},
19
- # :expected_format,
20
- # ]
21
- 'youtube' => [
22
- 'http://www.youtube.com/watch?v=u6XAPnuFjJc',
23
- {:json=>'http://www.youtube.com/oembed', :xml=>'http://www.youtube.com/oembed'},
24
- :json,
25
- ],
26
- 'vimeo' => [
27
- 'https://vimeo.com/27953845',
28
- {:json=>'https://vimeo.com/api/oembed.json', :xml=>'https://vimeo.com/api/oembed.xml'},
29
- :json,
30
- ],
31
- 'facebook-photo' => [
32
- 'https://www.facebook.com/Federer/photos/pb.64760994940.-2207520000.1456668968./10153235368269941/?type=3&theater',
33
- 'https://www.facebook.com/plugins/post/oembed.json/',
34
- :json,
35
- ],
36
- 'tumblr' => [
37
- 'http://kittehkats.tumblr.com/post/140525169406/katydid-and-the-egg-happy-forest-family',
38
- 'https://www.tumblr.com/oembed/1.0',
39
- :json
40
- ],
41
- # TODO: Enhance ProviderDiscovery to support arbitrary query parameters. See https://github.com/ruby-oembed/ruby-oembed/issues/15
42
- #'wordpress' => [
43
- # 'http://sweetandweak.wordpress.com/2011/09/23/nothing-starts-the-morning-like-a-good-dose-of-panic/',
44
- # {:json=>'https://public-api.wordpress.com/oembed/1.0/', :xml=>'https://public-api.wordpress.com/oembed/1.0/'},
45
- # :json,
46
- #],
47
- }.each do |context, urls|
48
-
49
- given_url, expected_endpoints, expected_format = urls
50
- expected_endpoints = {expected_format=>expected_endpoints} unless expected_endpoints.is_a?(Hash)
51
-
52
- context "given a #{context} url" do
53
-
54
- shared_examples "a discover_provider call" do |endpoint, format|
55
- describe ".discover_provider" do
56
- it "should return the correct Class" do
57
- expect(provider).to be_instance_of(OEmbed::Provider)
58
- end
59
-
60
- it "should detect the correct URL" do
61
- expect(provider.endpoint).to eq(endpoint)
62
- end
63
-
64
- it "should return the correct format" do
65
- expect(provider.format).to eq(format)
66
- end
67
- end
68
-
69
- describe ".get" do
70
- it "should return the correct Class" do
71
- expect(response).to be_kind_of(OEmbed::Response)
72
- end
73
-
74
- it "should return the correct format" do
75
- expect(response.format).to eq(format.to_s)
76
- end
77
-
78
- it "should return the correct data" do
79
- expect(response.type).to_not be_empty
80
-
81
- case response.type
82
- when 'video', 'rich'
83
- expect(response.html).to_not be_empty
84
- expect(response.width).to_not be_nil
85
- expect(response.height).to_not be_nil
86
- when 'photo'
87
- expect(response.url).to_not be_empty
88
- expect(response.width).to_not be_nil
89
- expect(response.height).to_not be_nil
90
- end
91
- end
92
- end # get
93
- end
94
-
95
- context "with no format specified" do
96
- let(:provider) { OEmbed::ProviderDiscovery.discover_provider(given_url) }
97
- let(:response) { OEmbed::ProviderDiscovery.get(given_url) }
98
- include_examples "a discover_provider call", expected_endpoints[expected_format], expected_format
99
- end
100
-
101
- if expected_endpoints.include?(:json)
102
- context "with json format specified" do
103
- let(:provider) { OEmbed::ProviderDiscovery.discover_provider(given_url, :format=>:json) }
104
- let(:response) { OEmbed::ProviderDiscovery.get(given_url, :format=>:json) }
105
- include_examples "a discover_provider call", expected_endpoints[:json], :json
106
- end
107
- end
108
-
109
- if expected_endpoints.include?(:xml)
110
- context "with json format specified" do
111
- let(:provider) { OEmbed::ProviderDiscovery.discover_provider(given_url, :format=>:xml) }
112
- let(:response) { OEmbed::ProviderDiscovery.get(given_url, :format=>:xml) }
113
- include_examples "a discover_provider call", expected_endpoints[:xml], :xml
114
- end
115
- end
116
- end
117
-
118
- end # each service
119
-
120
- context "when returning 404" do
121
- let(:url) { 'https://www.youtube.com/watch?v=123123123' }
122
-
123
- it "raises OEmbed::NotFound" do
124
- expect{ OEmbed::ProviderDiscovery.discover_provider(url) }.to raise_error(OEmbed::NotFound)
125
- end
126
- end
127
-
128
- context "when returning 301" do
129
- let(:url) { 'http://www.youtube.com/watch?v=dFs9WO2B8uI' }
130
-
131
- it "does redirect http to https" do
132
- expect{ OEmbed::ProviderDiscovery.discover_provider(url) }.not_to raise_error
133
- end
134
- end
135
-
136
- it "does passes the timeout option to Net::Http" do
137
- expect_any_instance_of(Net::HTTP).to receive(:open_timeout=).with(5)
138
- expect_any_instance_of(Net::HTTP).to receive(:read_timeout=).with(5)
139
- OEmbed::ProviderDiscovery.discover_provider('https://www.youtube.com/watch?v=dFs9WO2B8uI', :timeout => 5)
140
- end
141
- end