ruby-oembed 0.7.6 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +4 -1
  2. data/CHANGELOG.rdoc +49 -0
  3. data/Gemfile.lock +13 -8
  4. data/README.rdoc +79 -0
  5. data/Rakefile +21 -6
  6. data/lib/oembed/errors.rb +23 -4
  7. data/lib/oembed/formatter/json/backends/activesupportjson.rb +28 -0
  8. data/lib/oembed/formatter/json/backends/jsongem.rb +31 -0
  9. data/lib/oembed/formatter/json/backends/yaml.rb +85 -0
  10. data/lib/oembed/formatter/json.rb +69 -0
  11. data/lib/oembed/formatter/xml/backends/rexml.rb +44 -0
  12. data/lib/oembed/formatter/xml/backends/xmlsimple.rb +39 -0
  13. data/lib/oembed/formatter/xml.rb +76 -0
  14. data/lib/oembed/formatter.rb +97 -0
  15. data/lib/oembed/provider.rb +102 -38
  16. data/lib/oembed/provider_discovery.rb +19 -7
  17. data/lib/oembed/providers/embedly_urls.yml +487 -0
  18. data/lib/oembed/providers/oohembed_urls.yml +17 -0
  19. data/lib/oembed/providers.rb +68 -11
  20. data/lib/oembed/response/link.rb +14 -0
  21. data/lib/oembed/response/photo.rb +12 -0
  22. data/lib/oembed/response/rich.rb +11 -0
  23. data/lib/oembed/response/video.rb +10 -0
  24. data/lib/oembed/response.rb +58 -10
  25. data/lib/oembed/version.rb +18 -0
  26. data/lib/oembed.rb +2 -1
  27. data/lib/tasks/oembed.rake +45 -0
  28. data/lib/tasks/rspec.rake +5 -0
  29. data/ruby-oembed.gemspec +38 -17
  30. data/spec/formatter/json/.DS_Store +0 -0
  31. data/spec/formatter/json/jsongem_backend_spec.rb +34 -0
  32. data/spec/formatter/json/yaml_backend_spec.rb +30 -0
  33. data/spec/formatter/xml/rexml_backend_spec.rb +30 -0
  34. data/spec/formatter/xml/xmlsimple_backend_spec.rb +34 -0
  35. data/spec/formatter_spec.rb +35 -0
  36. data/spec/provider_spec.rb +189 -24
  37. data/spec/providers_spec.rb +20 -1
  38. data/spec/response_spec.rb +129 -48
  39. data/spec/spec_helper.rb +5 -6
  40. metadata +45 -38
  41. data/CHANGELOG.md +0 -29
  42. data/README.md +0 -50
  43. data/VERSION +0 -1
  44. data/lib/oembed/embedly_urls.json +0 -227
  45. data/lib/oembed/formatters.rb +0 -40
  46. data/rails/init.rb +0 -3
@@ -1,16 +1,23 @@
1
1
  require 'rubygems'
2
- require 'json'
2
+ require 'yaml'
3
3
 
4
4
  module OEmbed
5
+ # Allows OEmbed to perform tasks across several, registered, Providers
6
+ # at once.
5
7
  class Providers
6
8
  class << self
7
9
  @@urls = {}
8
10
  @@fallback = []
9
11
 
12
+ # A Hash of all url schemes, where the keys represent schemes supported by
13
+ # all registered Provider instances and values are an Array of Providers
14
+ # that support that scheme.
10
15
  def urls
11
16
  @@urls
12
17
  end
13
18
 
19
+ # Given one ore more Provider instances, register their url schemes for
20
+ # future get calls.
14
21
  def register(*providers)
15
22
  providers.each do |provider|
16
23
  provider.urls.each do |url|
@@ -20,6 +27,8 @@ module OEmbed
20
27
  end
21
28
  end
22
29
 
30
+ # Given one ore more Provider instances, un-register their url schemes.
31
+ # Future get calls will not use these Providers.
23
32
  def unregister(*providers)
24
33
  providers.each do |provider|
25
34
  provider.urls.each do |url|
@@ -31,11 +40,25 @@ module OEmbed
31
40
  end
32
41
  end
33
42
 
43
+ # Register a standard set of common Provider instances, including:
44
+ # * Flickr
45
+ # * Hulu
46
+ # * Qik
47
+ # * Revision3
48
+ # * Viddler
49
+ # * Vimeo
50
+ # * Youtube
34
51
  def register_all
35
- register(Youtube, Flickr, Viddler, Qik, Pownce, Revision3, Hulu, Vimeo)
52
+ register(Youtube, Flickr, Viddler, Qik, Revision3, Hulu, Vimeo)
36
53
  end
37
54
 
38
- # Takes an array of OEmbed::Provider instances or OEmbed::ProviderDiscovery
55
+ # Unregister all currently-registered Provider instances.
56
+ def unregister_all
57
+ @@urls = {}
58
+ @@fallback = []
59
+ end
60
+
61
+ # Takes an array of Provider instances or ProviderDiscovery
39
62
  # Use this method to register fallback providers.
40
63
  # When the raw or get methods are called, if the URL doesn't match
41
64
  # any of the registerd url patters the fallback providers
@@ -47,16 +70,19 @@ module OEmbed
47
70
  @@fallback += providers
48
71
  end
49
72
 
50
- # Returns an array of all registerd fallback providers
73
+ # Returns an array of all registerd fallback Provider instances.
51
74
  def fallback
52
75
  @@fallback
53
76
  end
54
77
 
78
+ # Returns a Provider instance who's url scheme matches the given url.
55
79
  def find(url)
56
80
  providers = @@urls[@@urls.keys.detect { |u| u =~ url }]
57
81
  Array(providers).first || nil
58
82
  end
59
83
 
84
+ # Finds the appropriate Provider for this url and return the raw response.
85
+ # @deprecated *Note*: This method will be made private in the future.
60
86
  def raw(url, options = {})
61
87
  provider = find(url)
62
88
  if provider
@@ -69,6 +95,8 @@ module OEmbed
69
95
  end
70
96
  end
71
97
 
98
+ # Finds the appropriate Provider for this url and returns an OEmbed::Response,
99
+ # using Provider#get.
72
100
  def get(url, options = {})
73
101
  provider = find(url)
74
102
  if provider
@@ -83,38 +111,49 @@ module OEmbed
83
111
  end
84
112
 
85
113
  # Custom providers:
114
+
115
+ # Provider for youtube.com
86
116
  Youtube = OEmbed::Provider.new("http://www.youtube.com/oembed")
87
117
  Youtube << "http://*.youtube.com/*"
88
118
  Youtube << "http://*.youtu.be/*"
89
119
 
120
+ # Provider for flickr.com
90
121
  Flickr = OEmbed::Provider.new("http://www.flickr.com/services/oembed/")
91
122
  Flickr << "http://*.flickr.com/*"
92
123
 
124
+ # Provider for viddler.com
93
125
  Viddler = OEmbed::Provider.new("http://lab.viddler.com/services/oembed/")
94
126
  Viddler << "http://*.viddler.com/*"
95
127
 
128
+ # Provider for qik.com
96
129
  Qik = OEmbed::Provider.new("http://qik.com/api/oembed.{format}")
97
130
  Qik << "http://qik.com/*"
98
131
  Qik << "http://qik.com/video/*"
99
132
 
133
+ # Provider for revision3.com
100
134
  Revision3 = OEmbed::Provider.new("http://revision3.com/api/oembed/")
101
135
  Revision3 << "http://*.revision3.com/*"
102
136
 
137
+ # Provider for hulu.com
103
138
  Hulu = OEmbed::Provider.new("http://www.hulu.com/api/oembed.{format}")
104
139
  Hulu << "http://www.hulu.com/watch/*"
105
140
 
141
+ # Provider for vimeo.com
106
142
  Vimeo = OEmbed::Provider.new("http://www.vimeo.com/api/oembed.{format}")
107
143
  Vimeo << "http://*.vimeo.com/*"
108
144
  Vimeo << "http://*.vimeo.com/groups/*/videos/*"
109
145
 
110
- Pownce = OEmbed::Provider.new("http://api.pownce.com/2.1/oembed.{format}")
111
- Pownce << "http://*.pownce.com/*"
146
+ # pownce.com closed in 2008
147
+ #Pownce = OEmbed::Provider.new("http://api.pownce.com/2.1/oembed.{format}")
148
+ #Pownce << "http://*.pownce.com/*"
112
149
 
113
- # A general end point, which then calls other APIs and returns OEmbed info
150
+ # Provider for oohembed.com, which is a provider agregator. See
151
+ # OEmbed::Provders::OohEmbed.urls for a full list of supported url schemas.
114
152
  OohEmbed = OEmbed::Provider.new("http://oohembed.com/oohembed/", :json)
115
153
  OohEmbed << "http://*.5min.com/Video/*" # micro-video host
116
154
  OohEmbed << %r{http://(.*?).amazon.(com|co.uk|de|ca|jp)/(.*?)/(gp/product|o/ASIN|obidos/ASIN|dp)/(.*?)} # Online product shopping
117
155
  OohEmbed << "http://*.blip.tv/*"
156
+ OohEmbed << "http://*.clikthrough.com/theater/video/*"
118
157
  OohEmbed << "http://*.collegehumor.com/video:*" # Comedic & original videos
119
158
  OohEmbed << "http://*.thedailyshow.com/video/*" # Syndicated show
120
159
  OohEmbed << "http://*.dailymotion.com/*"
@@ -123,9 +162,12 @@ module OEmbed
123
162
  OohEmbed << "http://*.funnyordie.com/videos/*" # Comedy video host
124
163
  OohEmbed << "http://video.google.com/videoplay?*" # Video hosting
125
164
  OohEmbed << "http://www.hulu.com/watch/*"
165
+ OohEmbed << "http://*.kinomap.com/*"
126
166
  OohEmbed << "http://*.livejournal.com/"
127
167
  OohEmbed << "http://*.metacafe.com/watch/*" # Video host
128
168
  OohEmbed << "http://*.nfb.ca/film/*"
169
+ OohEmbed << "http://*.photobucket.com/albums/*"
170
+ OohEmbed << "http://*.photobucket.com/groups/*"
129
171
  OohEmbed << "http://*.phodroid.com/*/*/*" # Photo host
130
172
  OohEmbed << "http://qik.com/*"
131
173
  OohEmbed << "http://*.revision3.com/*"
@@ -142,35 +184,50 @@ module OEmbed
142
184
  OohEmbed << %r{http://yfrog.(com|ru|com.tr|it|fr|co.il|co.uk|com.pl|pl|eu|us)/(.*?)} # image & video hosting
143
185
  OohEmbed << "http://*.youtube.com/watch*"
144
186
 
145
- # A general end point, which then calls other APIs and returns OEmbed info
187
+ # Provider for embedly.com, which is a provider agregator. See
188
+ # OEmbed::Provders::OohEmbed.urls for a full list of supported url schemas.
146
189
  Embedly = OEmbed::Provider.new("http://api.embed.ly/v1/api/oembed")
147
- # An up-to-date version of this json file is available here: (http://api.embed.ly/static/data/embedly_regex.json
148
- JSON.parse(File.open(File.dirname(__FILE__) + "/embedly_urls.json", "r").read).each do |url|
190
+ # Add all known URL regexps for Embedly. To update this list run `rake oembed:update_embedly`
191
+ YAML.load_file(File.join(File.dirname(__FILE__), "/providers/embedly_urls.yml")).each do |url|
149
192
  Embedly << url
150
193
  end
151
194
 
195
+ # Provider for polleverywhere.com
152
196
  PollEverywhere = OEmbed::Provider.new("http://www.polleverywhere.com/services/oembed/")
153
197
  PollEverywhere << "http://www.polleverywhere.com/polls/*"
154
198
  PollEverywhere << "http://www.polleverywhere.com/multiple_choice_polls/*"
155
199
  PollEverywhere << "http://www.polleverywhere.com/free_text_polls/*"
156
200
 
201
+ # Provider for my.opera.com
157
202
  MyOpera = OEmbed::Provider.new("http://my.opera.com/service/oembed", :json)
158
203
  MyOpera << "http://my.opera.com/*"
159
204
 
205
+ # Provider for clearspring.com
160
206
  ClearspringWidgets = OEmbed::Provider.new("http://widgets.clearspring.com/widget/v1/oembed/")
161
207
  ClearspringWidgets << "http://www.clearspring.com/widgets/*"
162
208
 
209
+ # Provider for nfb.ca
163
210
  NFBCanada = OEmbed::Provider.new("http://www.nfb.ca/remote/services/oembed/")
164
211
  NFBCanada << "http://*.nfb.ca/film/*"
165
212
 
213
+ # Provider for scribd.com
166
214
  Scribd = OEmbed::Provider.new("http://www.scribd.com/services/oembed")
167
215
  Scribd << "http://*.scribd.com/*"
168
216
 
217
+ # Provider for movieclips.com
169
218
  MovieClips = OEmbed::Provider.new("http://movieclips.com/services/oembed/")
170
219
  MovieClips << "http://movieclips.com/watch/*/*/"
171
220
 
221
+ # Provider for 23hq.com
172
222
  TwentyThree = OEmbed::Provider.new("http://www.23hq.com/23/oembed")
173
223
  TwentyThree << "http://www.23hq.com/*"
174
-
224
+
225
+ # Provider for clikthrough.com
226
+ #Clickthrough = OEmbed::Provider.new("http://www.clikthrough.com/services/oembed/")
227
+ #Clickthrough << "http://*.clikthrough.com/theater/video/*"
228
+ #
229
+ ## Provider for kinomap.com
230
+ #Kinomap = OEmbed::Provider.new("http://www.kinomap.com/oembed")
231
+ #Kinomap << "http://www.kinomap.com/*"
175
232
  end
176
233
  end
@@ -1,6 +1,20 @@
1
1
  module OEmbed
2
2
  class Response
3
+ # A fairly generic type of Response where the url of the resource is
4
+ # the original request_url.
3
5
  class Link < self
6
+
7
+ # Returns the request_url
8
+ def url
9
+ request_url
10
+ end
11
+
12
+ private
13
+
14
+ # See {section 2.3.4.1 of the oEmbed spec}[http://oembed.com/#section2.3]
15
+ def must_override
16
+ super
17
+ end
4
18
  end
5
19
  end
6
20
  end
@@ -1,9 +1,21 @@
1
1
  module OEmbed
2
2
  class Response
3
+ # A Response used for representing static photos.
3
4
  class Photo < self
5
+ # Returns an <img> tag pointing at the appropraite URL.
4
6
  def html
5
7
  "<img src='" + self.url + "' />"
6
8
  end
9
+
10
+ private
11
+
12
+ # See {section 2.3.4.1 of the oEmbed spec}[http://oembed.com/#section2.3]
13
+ def must_override
14
+ %w{
15
+ url width height
16
+ } + super
17
+ end
18
+
7
19
  end
8
20
  end
9
21
  end
@@ -1,6 +1,17 @@
1
1
  module OEmbed
2
2
  class Response
3
+ # A Response used for representing rich HTML content that does not fall under
4
+ # one of the other Response categories.
3
5
  class Rich < self
6
+
7
+ private
8
+
9
+ # See {section 2.3.4.1 of the oEmbed spec}[http://oembed.com/#section2.3]
10
+ def must_override
11
+ %w{
12
+ html width height
13
+ } + super
14
+ end
4
15
  end
5
16
  end
6
17
  end
@@ -1,6 +1,16 @@
1
1
  module OEmbed
2
2
  class Response
3
+ # A Response used for representing playable videos.
3
4
  class Video < self
5
+
6
+ private
7
+
8
+ # See {section 2.3.4.1 of the oEmbed spec}[http://oembed.com/#section2.3]
9
+ def must_override
10
+ %w{
11
+ html width height
12
+ } + super
13
+ end
4
14
  end
5
15
  end
6
16
  end
@@ -1,10 +1,30 @@
1
1
  module OEmbed
2
+ # Contains oEmbed data about a URL, as returned by an OEmbed::Provider. The data
3
+ # stored in Response instances can be accessed by either using the field method
4
+ # _or_ by using the appropriate automatically-defined helper method.
5
+ #
6
+ # For example:
7
+ # @response.type #=> 'rich'
8
+ # @response.field('width') #=> '500'
9
+ # @response.width #=> '500'
2
10
  class Response
3
- METHODS = [:define_methods!, :provider, :field, :fields]
4
- attr_reader :fields, :provider, :format, :url
11
+ # An Hash of data (probably from a Provider) just as it was parsed.
12
+ attr_reader :fields
13
+
14
+ # The Provider instance that generated this Response
15
+ attr_reader :provider
16
+
17
+ # The URL that was sent to the provider, that this Response contains data about.
18
+ attr_reader :request_url
19
+
20
+ # The name of the format used get this data from the Provider (e.g. 'json').
21
+ attr_reader :format
5
22
 
6
- def self.create_for(raw, provider, url, format = :json)
7
- fields = OEmbed::Formatters.convert(format, raw)
23
+ # Create a new Response instance of the correct type given raw
24
+ # which is data from the provider, about the url, in the given
25
+ # format that needs to be decoded.
26
+ def self.create_for(raw, provider, url, format)
27
+ fields = OEmbed::Formatter.decode(format, raw)
8
28
 
9
29
  resp_type = case fields['type']
10
30
  when 'photo' then OEmbed::Response::Photo
@@ -14,44 +34,72 @@ module OEmbed
14
34
  else self
15
35
  end
16
36
 
17
- resp_type.new(fields, provider, url)
37
+ resp_type.new(fields, provider, url, format)
18
38
  end
19
39
 
20
- def initialize(fields, provider, url = nil)
40
+ def initialize(fields, provider, url=nil, format=nil)
21
41
  @fields = fields
22
42
  @provider = provider
43
+ @request_url = url
44
+ @format = format
23
45
  define_methods!
24
46
  end
25
47
 
26
- def field(m)
27
- @fields[m.to_s]
48
+ # The String value associated with this key. While you can use helper methods
49
+ # like Response#version, the field method is helpful if the Provider returns
50
+ # non-standard values that conflict with Ruby methods.
51
+ #
52
+ # For example, if the Provider returns a "clone" value of "true":
53
+ # # The following calls the Object#clone method
54
+ # @response.clone #=> #<OEmbed::Response:...
55
+ #
56
+ # # The following returns the value given by the Provider
57
+ # @response.field(:clone) #=> 'true'
58
+ def field(key)
59
+ @fields[key.to_s].to_s
28
60
  end
29
61
 
62
+ # Returns true if this is an oEmbed video response.
30
63
  def video?
31
64
  is_a?(OEmbed::Response::Video)
32
65
  end
33
66
 
67
+ # Returns true if this is an oEmbed photo response.
34
68
  def photo?
35
69
  is_a?(OEmbed::Response::Photo)
36
70
  end
37
71
 
72
+ # Returns true if this is an oEmbed link response.
38
73
  def link?
39
74
  is_a?(OEmbed::Response::Link)
40
75
  end
41
76
 
77
+ # Returns true if this is an oEmbed rich response.
42
78
  def rich?
43
79
  is_a?(OEmbed::Response::Rich)
44
80
  end
45
81
 
46
82
  private
47
83
 
84
+ # An Array of helper methods names define_methods! must be able to override
85
+ # when is's called. In general, define_methods! tries its best _not_ to override
86
+ # existing methods, so this Array is important if some other library has
87
+ # defined a method that uses an oEmbed name. For example: Object#version
88
+ def must_override
89
+ %w{
90
+ type version
91
+ title author_name author_url provider_name provider_url
92
+ cache_age thumbnail_url thumbnail_width thumbnail_height
93
+ }
94
+ end
95
+
48
96
  def define_methods!
49
97
  @fields.keys.each do |key|
50
- next if METHODS.include?(key.to_sym) || key[0,2]=="__" || key[-1]==??
98
+ next if self.respond_to?(key) && !must_override.include?(key.to_s)
51
99
  class << self
52
100
  self
53
101
  end.send(:define_method, key) do
54
- @fields[key]
102
+ field(key)
55
103
  end
56
104
  end
57
105
  end
@@ -0,0 +1,18 @@
1
+ module OEmbed
2
+ class Version
3
+ MAJOR = 0
4
+ MINOR = 8
5
+ PATCH = 1
6
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
+
8
+ class << self
9
+ # A String representing the current version of the OEmbed gem.
10
+ def inspect
11
+ STRING
12
+ end
13
+ alias_method :to_s, :inspect
14
+ end
15
+ end
16
+
17
+ VERSION = Version::STRING
18
+ end
data/lib/oembed.rb CHANGED
@@ -2,8 +2,9 @@ $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  require 'net/http'
4
4
 
5
+ require 'oembed/version'
5
6
  require 'oembed/errors'
6
- require 'oembed/formatters'
7
+ require 'oembed/formatter'
7
8
  require 'oembed/provider'
8
9
  require 'oembed/provider_discovery'
9
10
  require 'oembed/providers'
@@ -0,0 +1,45 @@
1
+ begin
2
+ require 'json'
3
+ require 'open-uri'
4
+
5
+ namespace :oembed do
6
+ desc "Update the embedly_urls.yml file using the services api."
7
+ task :update_embedly do
8
+ # Details at http://api.embed.ly/docs/service
9
+ json_uri = URI.parse("http://api.embed.ly/1/services")
10
+ yaml_path = File.join(File.dirname(__FILE__), "../oembed/providers/embedly_urls.yml")
11
+
12
+ services = JSON.parse(json_uri.read)
13
+
14
+ url_regexps = []
15
+ services.each do |service|
16
+ url_regexps += service['regex']
17
+ end
18
+ url_regexps.sort!
19
+
20
+ YAML.dump(url_regexps, File.open(yaml_path, 'w'))
21
+ end
22
+
23
+ # Note: At the moment the list of enpoints in the oohembed-provided JSON file
24
+ # do NOT match the full listing on their website. Until we sort that out, we'll
25
+ # continue to use the manually entered list of oohembed URLs
26
+ desc "Update the list of URLs supported by oohembed via their API"
27
+ task :update_oohembed do
28
+ # Details in the Q & A section of http://oohembed.com/
29
+ json_uri = URI.parse("http://oohembed.com/static/endpoints.json")
30
+ yaml_path = File.join(File.dirname(__FILE__), "../oembed/providers/oohembed_urls.yml")
31
+
32
+ services = JSON.parse(json_uri.read)
33
+
34
+ url_regexps = []
35
+ services.each do |service|
36
+ url_regexps << service['url']
37
+ end
38
+ url_regexps.sort!
39
+
40
+ YAML.dump(url_regexps, File.open(yaml_path, 'w'))
41
+ end
42
+ end
43
+ rescue LoadError
44
+ puts "The oembed rake tasks require JSON. Install it with: gem install json"
45
+ end
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:specs)
4
+
5
+ task :default => :specs
data/ruby-oembed.gemspec CHANGED
@@ -5,55 +5,76 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-oembed}
8
- s.version = "0.7.6"
8
+ s.version = "0.8.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Magnus Holm", "Alex Kessinger", "Aris Bartee", "Marcos Wright Kuhns"]
12
- s.date = %q{2010-10-14}
13
- s.description = %q{An oEmbed client written in Ruby, letting you easily get embeddable HTML representations of a supported web pages, based on their URLs. See http://oembed.com for more about the protocol.}
12
+ s.date = %q{2011-02-27}
13
+ s.description = %q{An oEmbed consumer library written in Ruby, letting you easily get embeddable HTML representations of supported web pages, based on their URLs. See http://oembed.com for more information about the protocol.}
14
14
  s.email = %q{arisbartee@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.md"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".gitignore",
21
21
  ".rvmrc",
22
- "CHANGELOG.md",
22
+ "CHANGELOG.rdoc",
23
23
  "Gemfile",
24
24
  "Gemfile.lock",
25
25
  "LICENSE",
26
- "README.md",
26
+ "README.rdoc",
27
27
  "Rakefile",
28
- "VERSION",
29
28
  "integration_test/test.rb",
30
29
  "integration_test/test_urls.csv",
31
30
  "lib/oembed.rb",
32
- "lib/oembed/embedly_urls.json",
33
31
  "lib/oembed/errors.rb",
34
- "lib/oembed/formatters.rb",
32
+ "lib/oembed/formatter.rb",
33
+ "lib/oembed/formatter/json.rb",
34
+ "lib/oembed/formatter/json/backends/activesupportjson.rb",
35
+ "lib/oembed/formatter/json/backends/jsongem.rb",
36
+ "lib/oembed/formatter/json/backends/yaml.rb",
37
+ "lib/oembed/formatter/xml.rb",
38
+ "lib/oembed/formatter/xml/backends/rexml.rb",
39
+ "lib/oembed/formatter/xml/backends/xmlsimple.rb",
35
40
  "lib/oembed/provider.rb",
36
41
  "lib/oembed/provider_discovery.rb",
37
42
  "lib/oembed/providers.rb",
43
+ "lib/oembed/providers/embedly_urls.yml",
44
+ "lib/oembed/providers/oohembed_urls.yml",
38
45
  "lib/oembed/response.rb",
39
46
  "lib/oembed/response/link.rb",
40
47
  "lib/oembed/response/photo.rb",
41
48
  "lib/oembed/response/rich.rb",
42
49
  "lib/oembed/response/video.rb",
43
- "rails/init.rb",
50
+ "lib/oembed/version.rb",
51
+ "lib/tasks/oembed.rake",
52
+ "lib/tasks/rspec.rake",
44
53
  "ruby-oembed.gemspec",
54
+ "spec/formatter/json/.DS_Store",
55
+ "spec/formatter/json/jsongem_backend_spec.rb",
56
+ "spec/formatter/json/yaml_backend_spec.rb",
57
+ "spec/formatter/xml/rexml_backend_spec.rb",
58
+ "spec/formatter/xml/xmlsimple_backend_spec.rb",
59
+ "spec/formatter_spec.rb",
45
60
  "spec/provider_spec.rb",
46
61
  "spec/providers_spec.rb",
47
62
  "spec/response_spec.rb",
48
63
  "spec/spec_helper.rb"
49
64
  ]
50
65
  s.homepage = %q{http://github.com/judofyr/ruby-oembed}
51
- s.rdoc_options = ["--charset=UTF-8"]
66
+ s.licenses = ["MIT"]
67
+ s.rdoc_options = ["--main", "README.rdoc", "--title", "ruby-oembed-0.8.1", "--inline-source", "--exclude", "tasks", "CHANGELOG.rdoc"]
52
68
  s.require_paths = ["lib"]
53
69
  s.rubygems_version = %q{1.3.7}
54
70
  s.summary = %q{oEmbed for Ruby}
55
71
  s.test_files = [
56
- "spec/provider_spec.rb",
72
+ "spec/formatter/json/jsongem_backend_spec.rb",
73
+ "spec/formatter/json/yaml_backend_spec.rb",
74
+ "spec/formatter/xml/rexml_backend_spec.rb",
75
+ "spec/formatter/xml/xmlsimple_backend_spec.rb",
76
+ "spec/formatter_spec.rb",
77
+ "spec/provider_spec.rb",
57
78
  "spec/providers_spec.rb",
58
79
  "spec/response_spec.rb",
59
80
  "spec/spec_helper.rb"
@@ -64,18 +85,18 @@ Gem::Specification.new do |s|
64
85
  s.specification_version = 3
65
86
 
66
87
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
67
- s.add_runtime_dependency(%q<json>, [">= 0"])
68
- s.add_runtime_dependency(%q<xml-simple>, [">= 0"])
69
- s.add_development_dependency(%q<rspec>, [">= 0"])
88
+ s.add_development_dependency(%q<json>, [">= 0"])
89
+ s.add_development_dependency(%q<xml-simple>, [">= 0"])
90
+ s.add_development_dependency(%q<rspec>, [">= 2.0"])
70
91
  else
71
92
  s.add_dependency(%q<json>, [">= 0"])
72
93
  s.add_dependency(%q<xml-simple>, [">= 0"])
73
- s.add_dependency(%q<rspec>, [">= 0"])
94
+ s.add_dependency(%q<rspec>, [">= 2.0"])
74
95
  end
75
96
  else
76
97
  s.add_dependency(%q<json>, [">= 0"])
77
98
  s.add_dependency(%q<xml-simple>, [">= 0"])
78
- s.add_dependency(%q<rspec>, [">= 0"])
99
+ s.add_dependency(%q<rspec>, [">= 2.0"])
79
100
  end
80
101
  end
81
102
 
Binary file
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe "OEmbed::Formatter::JSON::Backends::JSONGem" do
4
+ include OEmbedSpecHelper
5
+
6
+ before(:all) do
7
+ lambda {
8
+ OEmbed::Formatter::JSON.backend = 'JSONGem'
9
+ }.should raise_error(LoadError)
10
+
11
+ require 'json'
12
+
13
+ lambda {
14
+ OEmbed::Formatter::JSON.backend = 'JSONGem'
15
+ }.should_not raise_error
16
+ end
17
+
18
+ it "should support JSON" do
19
+ proc { OEmbed::Formatter.supported?(:json) }.
20
+ should_not raise_error(OEmbed::FormatNotSupported)
21
+ end
22
+
23
+ it "should be using the JSONGem backend" do
24
+ OEmbed::Formatter::JSON.backend.should == OEmbed::Formatter::JSON::Backends::JSONGem
25
+ end
26
+
27
+ it "should decode a JSON String" do
28
+ decoded = OEmbed::Formatter.decode(:json, valid_response(:json))
29
+ # We need to compare keys & values separately because we don't expect all
30
+ # non-string values to be recognized correctly.
31
+ decoded.keys.should == valid_response(:object).keys
32
+ decoded.values.map{|v|v.to_s}.should == valid_response(:object).values.map{|v|v.to_s}
33
+ end
34
+ end
@@ -0,0 +1,30 @@
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
+ lambda {
8
+ OEmbed::Formatter::JSON.backend = 'Yaml'
9
+ }.should_not raise_error
10
+
11
+ (!!defined?(YAML)).should == true
12
+ end
13
+
14
+ it "should support JSON" do
15
+ proc { OEmbed::Formatter.supported?(:json) }.
16
+ should_not raise_error(OEmbed::FormatNotSupported)
17
+ end
18
+
19
+ it "should be using the Yaml backend" do
20
+ OEmbed::Formatter::JSON.backend.should == OEmbed::Formatter::JSON::Backends::Yaml
21
+ end
22
+
23
+ it "should decode a JSON String" do
24
+ decoded = OEmbed::Formatter.decode(:json, valid_response(:json))
25
+ # We need to compare keys & values separately because we don't expect all
26
+ # non-string values to be recognized correctly.
27
+ decoded.keys.should == valid_response(:object).keys
28
+ decoded.values.map{|v|v.to_s}.should == valid_response(:object).values.map{|v|v.to_s}
29
+ end
30
+ end