ruby-oembed 0.8.1 → 0.8.3
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.
- data/.yardopts +4 -0
- data/CHANGELOG.rdoc +13 -1
- data/Gemfile +9 -4
- data/Gemfile.lock +15 -22
- data/README.rdoc +20 -4
- data/Rakefile +1 -4
- data/lib/oembed/formatter.rb +18 -13
- data/lib/oembed/formatter/base.rb +108 -0
- data/lib/oembed/formatter/json.rb +14 -37
- data/lib/oembed/formatter/json/backends/activesupportjson.rb +8 -8
- data/lib/oembed/formatter/json/backends/jsongem.rb +8 -8
- data/lib/oembed/formatter/json/backends/yaml.rb +11 -11
- data/lib/oembed/formatter/xml.rb +20 -44
- data/lib/oembed/formatter/xml/backends/rexml.rb +10 -10
- data/lib/oembed/formatter/xml/backends/xmlsimple.rb +10 -10
- data/lib/oembed/providers.rb +36 -4
- data/lib/oembed/providers/embedly_urls.yml +58 -10
- data/lib/oembed/version.rb +1 -1
- data/ruby-oembed.gemspec +58 -62
- data/spec/formatter/ducktype_backend_spec.rb +94 -0
- data/spec/formatter/json/.DS_Store +0 -0
- data/spec/formatter/json/jsongem_backend_spec.rb +24 -0
- data/spec/formatter/json/yaml_backend_spec.rb +24 -0
- data/spec/formatter/xml/rexml_backend_spec.rb +24 -0
- data/spec/formatter/xml/xmlsimple_backend_spec.rb +24 -0
- data/spec/spec_helper.rb +28 -0
- metadata +68 -25
- data/.gitignore +0 -5
data/.yardopts
ADDED
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
= CHANGELOG
|
2
2
|
|
3
|
+
== 0.8.3 - 26 June 2011
|
4
|
+
|
5
|
+
* Fixing a circular dependency introduced during my recent Jeweler upgrade. (Marcos Wright Kuhns)
|
6
|
+
|
7
|
+
== 0.8.2 - 25 June 2011
|
8
|
+
|
9
|
+
* Added built-in providers for Instagram, Slideshare and Yfrog
|
10
|
+
* Improved support (and error detection) for custom OEmbed::Formatter backends. (Marcos Wright Kuhns)
|
11
|
+
* DRYed up OEmbed::Formatter::JSON and XML methods into OEmbed::Formatter::Base (Marcos Wright Kuhns)
|
12
|
+
* More consistently raise an OEmbed::Parse error if there is any sort of problem parsing the server response, whether it's an expected error type or not. (Marcos Wright Kuhns)
|
13
|
+
* Added in-code comments about the oohEmbed service becoming part of Embed.ly
|
14
|
+
|
3
15
|
== 0.8.1 - 27 February 2011
|
4
16
|
|
5
17
|
* Removed all dependencies on external gems. XML is parsed using REXML and JSON can be parsed using YAML thanks to the convert_json_to_yaml method borrowed from Rails! (Marcos Wright Kuhns)
|
@@ -17,7 +29,7 @@
|
|
17
29
|
* Provider#url and Provider#name will be removed at some point in the future.
|
18
30
|
* All direct raw calls will be made private at some point in the future (i.e. Provider#raw, Providers#raw, and ProviderDiscovery#raw)
|
19
31
|
|
20
|
-
== 0.8.0 -
|
32
|
+
== 0.8.0 - Not Publicly Released
|
21
33
|
|
22
34
|
* Added OEmbed::Formatter Backends, to remove the dependency on the json gem and make adding support for other parsing libraries easier. This also fixes GitHub Issue =1. (Marcos Wright Kuhns)
|
23
35
|
* Catch invalid endpoint URLs on OEmbed::Provider instantiation. (Marcos Wright Kuhns)
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,31 +1,23 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
ruby-oembed (0.8.0)
|
5
|
-
|
6
1
|
GEM
|
7
2
|
remote: http://rubygems.org/
|
8
3
|
specs:
|
9
4
|
diff-lcs (1.1.2)
|
10
|
-
gemcutter (0.6.1)
|
11
5
|
git (1.2.5)
|
12
|
-
jeweler (1.
|
13
|
-
|
6
|
+
jeweler (1.6.2)
|
7
|
+
bundler (~> 1.0)
|
14
8
|
git (>= 1.2.5)
|
15
|
-
|
16
|
-
json (1.5.
|
17
|
-
|
18
|
-
rspec (2.
|
19
|
-
rspec-core (~> 2.
|
20
|
-
rspec-expectations (~> 2.
|
21
|
-
rspec-mocks (~> 2.
|
22
|
-
rspec-core (2.
|
23
|
-
rspec-expectations (2.
|
9
|
+
rake
|
10
|
+
json (1.5.3)
|
11
|
+
rake (0.9.2)
|
12
|
+
rspec (2.6.0)
|
13
|
+
rspec-core (~> 2.6.0)
|
14
|
+
rspec-expectations (~> 2.6.0)
|
15
|
+
rspec-mocks (~> 2.6.0)
|
16
|
+
rspec-core (2.6.4)
|
17
|
+
rspec-expectations (2.6.0)
|
24
18
|
diff-lcs (~> 1.1.2)
|
25
|
-
rspec-mocks (2.
|
26
|
-
|
27
|
-
json_pure (>= 1.1.7)
|
28
|
-
xml-simple (1.0.14)
|
19
|
+
rspec-mocks (2.6.0)
|
20
|
+
xml-simple (1.1.0)
|
29
21
|
|
30
22
|
PLATFORMS
|
31
23
|
ruby
|
@@ -33,5 +25,6 @@ PLATFORMS
|
|
33
25
|
DEPENDENCIES
|
34
26
|
jeweler
|
35
27
|
json
|
28
|
+
rake
|
36
29
|
rspec (>= 2.0)
|
37
|
-
|
30
|
+
xml-simple
|
data/README.rdoc
CHANGED
@@ -43,7 +43,7 @@ Last but not least, ruby-oembed supports both {oohEmbed}[http://oohembed.com] an
|
|
43
43
|
|
44
44
|
== Formatters
|
45
45
|
|
46
|
-
This library works wonderfully on
|
46
|
+
This library works wonderfully on its own, but can get a speed boost by using 3rd party libraries to parse oEmbed data. To use a 3rd party Formatter, just be sure to require the library _before_ ruby-oembed.
|
47
47
|
|
48
48
|
require 'json'
|
49
49
|
require 'xmlsimple'
|
@@ -59,7 +59,7 @@ The following, optional, backends are currently supported:
|
|
59
59
|
|
60
60
|
= Lend a Hand
|
61
61
|
|
62
|
-
Code for the ruby-oembed library is {hosted on GitHub}[
|
62
|
+
Code for the ruby-oembed library is {hosted on GitHub}[https://github.com/judofyr/ruby-oembed].
|
63
63
|
|
64
64
|
# Get the code.
|
65
65
|
git clone git://github.com/judofyr/ruby-oembed.git
|
@@ -70,9 +70,25 @@ Code for the ruby-oembed library is {hosted on GitHub}[http://github.com/judofyr
|
|
70
70
|
# Run the tests.
|
71
71
|
rake specs
|
72
72
|
|
73
|
-
If you encounter any bug, feel free to {create an Issue}[
|
73
|
+
If you encounter any bug, feel free to {create an Issue}[https://github.com/judofyr/ruby-oembed/issues].
|
74
74
|
|
75
|
-
|
75
|
+
We gladly accept pull requests! Just {fork}[http://help.github.com/forking/] the library and commit your changes along with relevant tests. Once you're happy with the changes, {send a pull request}[http://help.github.com/pull-requests/].
|
76
|
+
|
77
|
+
We do our best to {keep our tests green}[http://travis-ci.org/metavida/ruby-oembed] https://secure.travis-ci.org/metavida/ruby-oembed.png
|
78
|
+
|
79
|
+
= Contributors
|
80
|
+
|
81
|
+
Thanks to the following people for their contributions to this gem, both large and small:
|
82
|
+
|
83
|
+
* {Aris Bartee}[https://github.com/arisbartee]
|
84
|
+
* {Todd Fisher}[https://github.com/taf2]
|
85
|
+
* {Hans de Graff}[https://github.com/graaff]
|
86
|
+
* {Magnus Holm}[https://github.com/judofyr] (original author of this library)
|
87
|
+
* {Alex Kessinger}[https://github.com/voidfiles]
|
88
|
+
* {Ryan Richards}[https://github.com/rrichards]
|
89
|
+
* {Colin Shea}[https://github.com/evaryont]
|
90
|
+
* {Kyle Slattery}[https://github.com/kyleslattery]
|
91
|
+
* {Marcos Wright-Kuhns}[https://github.com/metavida] (current maintainer)
|
76
92
|
|
77
93
|
= License
|
78
94
|
|
data/Rakefile
CHANGED
@@ -14,9 +14,6 @@ begin
|
|
14
14
|
gemspec.license = "MIT"
|
15
15
|
gemspec.email = "arisbartee@gmail.com"
|
16
16
|
gemspec.authors = ["Magnus Holm","Alex Kessinger","Aris Bartee","Marcos Wright Kuhns"]
|
17
|
-
gemspec.add_development_dependency("json")
|
18
|
-
gemspec.add_development_dependency("xml-simple")
|
19
|
-
gemspec.add_development_dependency("rspec", ">=2.0")
|
20
17
|
|
21
18
|
gemspec.rdoc_options = %W(
|
22
19
|
--main README.rdoc
|
@@ -26,7 +23,7 @@ begin
|
|
26
23
|
CHANGELOG.rdoc
|
27
24
|
)
|
28
25
|
end
|
29
|
-
Jeweler::
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
30
27
|
rescue LoadError
|
31
28
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
32
29
|
end
|
data/lib/oembed/formatter.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'oembed/formatter/base'
|
1
2
|
require 'oembed/formatter/json'
|
2
3
|
require 'oembed/formatter/xml'
|
3
4
|
|
@@ -37,19 +38,23 @@ module OEmbed
|
|
37
38
|
def decode(format, value)
|
38
39
|
supported?(format)
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
41
|
+
begin
|
42
|
+
case format.to_s
|
43
|
+
when 'json'
|
44
|
+
begin
|
45
|
+
JSON.decode(value)
|
46
|
+
rescue JSON.backend.parse_error
|
47
|
+
raise OEmbed::ParseError, $!.message
|
48
|
+
end
|
49
|
+
when 'xml'
|
50
|
+
begin
|
51
|
+
XML.decode(value)
|
52
|
+
rescue XML.backend.parse_error
|
53
|
+
raise OEmbed::ParseError, $!.message
|
54
|
+
end
|
52
55
|
end
|
56
|
+
rescue
|
57
|
+
raise OEmbed::ParseError, "#{$!.class}: #{$!.message}"
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
@@ -91,7 +96,7 @@ module OEmbed
|
|
91
96
|
!actual.detect { |key, value| value.to_s != expected[key].to_s }
|
92
97
|
end
|
93
98
|
|
94
|
-
end
|
99
|
+
end # self
|
95
100
|
|
96
101
|
end
|
97
102
|
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module OEmbed
|
2
|
+
module Formatter
|
3
|
+
# These are methods that are shared by the OEmbed::Formatter sub-classes
|
4
|
+
# (i.e. OEmbed::Formatter:JSON and OEmbed::Formatter::XML).
|
5
|
+
module Base
|
6
|
+
|
7
|
+
# Returns true if there is a valid backend. Otherwise, raises OEmbed::FormatNotSupported
|
8
|
+
def supported?
|
9
|
+
!!backend
|
10
|
+
end
|
11
|
+
|
12
|
+
# Parses a String or IO and convert it into an Object
|
13
|
+
def decode(value)
|
14
|
+
backend.decode(value)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Given either a String (the name of the backend to use) or an Object (which
|
18
|
+
# must respond to the decode method), sets the current backend. Raises a LoadError
|
19
|
+
# if the given backend cannot be loaded (e.g. an invalid String name, or the
|
20
|
+
# decode method doesn't work properly).
|
21
|
+
# OEmbed::Formatter::XML.backend = 'REXML'
|
22
|
+
# OEmbed::Formatter::JSON.backend = MyCustomJsonDecoder.new
|
23
|
+
def backend=(new_backend)
|
24
|
+
new_backend_obj = case new_backend
|
25
|
+
when String
|
26
|
+
already_required = false
|
27
|
+
begin
|
28
|
+
already_required = self::Backends.const_defined?(new_backend, false)
|
29
|
+
rescue ArgumentError # we're dealing with ruby < 1.9 where const_defined? only takes 1 argument, but behaves the way we want it to.
|
30
|
+
already_required = self::Backends.const_defined?(new_backend)
|
31
|
+
rescue NameError # no backends have been loaded yet
|
32
|
+
already_required = false
|
33
|
+
end
|
34
|
+
|
35
|
+
require "oembed/formatter/#{backend_path}/#{new_backend.downcase}" unless already_required
|
36
|
+
self::Backends.const_get(new_backend)
|
37
|
+
else
|
38
|
+
new_backend
|
39
|
+
end
|
40
|
+
|
41
|
+
test_backend(new_backend_obj)
|
42
|
+
|
43
|
+
@backend = new_backend_obj
|
44
|
+
|
45
|
+
rescue
|
46
|
+
raise LoadError, "There was an error setting the backend: #{new_backend.inspect} - #{$!.message}"
|
47
|
+
end
|
48
|
+
|
49
|
+
# Perform a set of operations using a backend other than the current one.
|
50
|
+
# OEmbed::Formatter::XML.with_backend('XmlSimple') do
|
51
|
+
# OEmbed::Formatter::XML.decode(xml_value)
|
52
|
+
# end
|
53
|
+
def with_backend(new_backend)
|
54
|
+
old_backend, self.backend = backend, new_backend
|
55
|
+
yield
|
56
|
+
ensure
|
57
|
+
self.backend = old_backend
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# Makes sure the given backend can correctly parse values using the decode
|
63
|
+
# method.
|
64
|
+
def test_backend(new_backend)
|
65
|
+
raise LoadError, "The given backend must respond to the decode method: #{new_backend.inspect}" unless new_backend.respond_to?(:decode)
|
66
|
+
|
67
|
+
expected = {
|
68
|
+
"version"=>1.0,
|
69
|
+
"string"=>"test",
|
70
|
+
"int"=>42,
|
71
|
+
"html"=>"<i>Cool's</i>\n the \"word\"!",
|
72
|
+
}
|
73
|
+
|
74
|
+
actual = new_backend.decode(test_value)
|
75
|
+
|
76
|
+
# For the test to be true the actual output Hash should have the
|
77
|
+
# exact same list of keys _and_ the values should be the same
|
78
|
+
# if we ignoring typecasting.
|
79
|
+
if(
|
80
|
+
actual.keys.sort != expected.keys.sort ||
|
81
|
+
actual.detect { |key, value| value.to_s != expected[key].to_s }
|
82
|
+
)
|
83
|
+
msg = new_backend.decode_fail_msg rescue nil
|
84
|
+
msg ||= "The given backend failed to decode the test string correctly"
|
85
|
+
raise LoadError, "#{msg}: #{new_backend.inspect}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Must return a String representing the sub-directory where in-library
|
90
|
+
# backend rb files live (e.g. 'json/backends')
|
91
|
+
def backend_path
|
92
|
+
raise "This method must be defined by a format-specific OEmbed::Formatter sub-class."
|
93
|
+
end
|
94
|
+
|
95
|
+
# Must return a String that when parsed by a backend returns the following ruby Hash
|
96
|
+
# {
|
97
|
+
# "version"=>1.0,
|
98
|
+
# "string"=>"test",
|
99
|
+
# "int"=>42,
|
100
|
+
# "html"=>"<i>Cool's</i>\n the \"word\"!",
|
101
|
+
# }
|
102
|
+
def test_value
|
103
|
+
raise "This method must be defined by a format-specific OEmbed::Formatter sub-class."
|
104
|
+
end
|
105
|
+
|
106
|
+
end # SharedMethods
|
107
|
+
end
|
108
|
+
end
|
@@ -6,16 +6,7 @@ module OEmbed
|
|
6
6
|
DECODERS = %w(ActiveSupportJSON JSONGem Yaml)
|
7
7
|
|
8
8
|
class << self
|
9
|
-
|
10
|
-
# Returns true if there is a valid JSON backend. Otherwise, raises OEmbed::FormatNotSupported
|
11
|
-
def supported?
|
12
|
-
!!backend
|
13
|
-
end
|
14
|
-
|
15
|
-
# Parses a JSON string or IO and convert it into an object
|
16
|
-
def decode(json)
|
17
|
-
backend.decode(json)
|
18
|
-
end
|
9
|
+
include ::OEmbed::Formatter::Base
|
19
10
|
|
20
11
|
# Returns the current JSON backend.
|
21
12
|
def backend
|
@@ -24,32 +15,6 @@ module OEmbed
|
|
24
15
|
@backend
|
25
16
|
end
|
26
17
|
|
27
|
-
def backend=(name)
|
28
|
-
if name.is_a?(Module)
|
29
|
-
@backend = name
|
30
|
-
else
|
31
|
-
already_required = false
|
32
|
-
begin
|
33
|
-
already_required = OEmbed::Formatter::JSON::Backends.const_defined?(name, false)
|
34
|
-
rescue ArgumentError # we're dealing with ruby < 1.9 where const_defined? only takes 1 argument, but behaves the way we want it to.
|
35
|
-
already_required = OEmbed::Formatter::JSON::Backends.const_defined?(name)
|
36
|
-
rescue NameError # no backends have been loaded yet
|
37
|
-
already_required = false
|
38
|
-
end
|
39
|
-
|
40
|
-
require "oembed/formatter/json/backends/#{name.to_s.downcase}" unless already_required
|
41
|
-
@backend = OEmbed::Formatter::JSON::Backends::const_get(name)
|
42
|
-
end
|
43
|
-
@parse_error = @backend::ParseError
|
44
|
-
end
|
45
|
-
|
46
|
-
def with_backend(name)
|
47
|
-
old_backend, self.backend = backend, name
|
48
|
-
yield
|
49
|
-
ensure
|
50
|
-
self.backend = old_backend
|
51
|
-
end
|
52
|
-
|
53
18
|
def set_default_backend
|
54
19
|
DECODERS.find do |name|
|
55
20
|
begin
|
@@ -62,7 +27,19 @@ module OEmbed
|
|
62
27
|
end
|
63
28
|
end
|
64
29
|
|
65
|
-
|
30
|
+
private
|
31
|
+
|
32
|
+
def backend_path
|
33
|
+
'json/backends'
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_value
|
37
|
+
<<-JSON
|
38
|
+
{"version":"1.0", "string":"test", "int":42,"html":"<i>Cool's</i>\\n the \\"word\\"\\u0021"}
|
39
|
+
JSON
|
40
|
+
end
|
41
|
+
|
42
|
+
end # self
|
66
43
|
|
67
44
|
end # JSON
|
68
45
|
end
|
@@ -6,23 +6,23 @@ module OEmbed
|
|
6
6
|
module JSON
|
7
7
|
module Backends
|
8
8
|
module ActiveSupportJSON
|
9
|
-
ParseError = ::ActiveSupport::JSON.parse_error
|
10
9
|
extend self
|
11
10
|
|
12
11
|
# Parses a JSON string or IO and convert it into an object.
|
13
12
|
def decode(json)
|
14
13
|
::ActiveSupport::JSON.decode(json)
|
15
14
|
end
|
15
|
+
|
16
|
+
def decode_fail_msg
|
17
|
+
"The version of ActiveSupport::JSON you have installed isn't parsing JSON like ruby-oembed expected."
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse_error
|
21
|
+
::ActiveSupport::JSON.parse_error
|
22
|
+
end
|
16
23
|
|
17
24
|
end
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
22
|
-
|
23
|
-
# Only allow this backend if it parses JSON strings the way we expect it to
|
24
|
-
begin
|
25
|
-
raise unless OEmbed::Formatter.test_backend(OEmbed::Formatter::JSON::Backends::ActiveSupportJSON)
|
26
|
-
rescue
|
27
|
-
raise LoadError, "The version of ActiveSupport::JSON you have installed isn't parsing JSON like ruby-oembed expected."
|
28
|
-
end
|
@@ -6,7 +6,6 @@ module OEmbed
|
|
6
6
|
module JSON
|
7
7
|
module Backends
|
8
8
|
module JSONGem
|
9
|
-
ParseError = ::JSON::ParserError
|
10
9
|
extend self
|
11
10
|
|
12
11
|
# Parses a JSON string or IO and convert it into an object.
|
@@ -16,16 +15,17 @@ module OEmbed
|
|
16
15
|
end
|
17
16
|
::JSON.parse(json)
|
18
17
|
end
|
18
|
+
|
19
|
+
def decode_fail_msg
|
20
|
+
"The version of the json library you have installed isn't parsing JSON like ruby-oembed expected."
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_error
|
24
|
+
::JSON::ParserError
|
25
|
+
end
|
19
26
|
|
20
27
|
end
|
21
28
|
end
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
25
|
-
|
26
|
-
# Only allow this backend if it parses JSON strings the way we expect it to
|
27
|
-
begin
|
28
|
-
raise unless OEmbed::Formatter.test_backend(OEmbed::Formatter::JSON::Backends::JSONGem)
|
29
|
-
rescue
|
30
|
-
raise LoadError, "The version of the json library you have installed isn't parsing JSON like ruby-oembed expected."
|
31
|
-
end
|