<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/oembed/formatters.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,21 +1,9 @@
 $:.unshift File.dirname(__FILE__)
 
-%w(json/ext json).each do |lib|
-  begin
-    require lib
-    break
-  rescue LoadError
-  end
-end
-
-begin
-  require 'xmlsimple'
-rescue LoadError
-end
-
 require 'net/http'
 
 require 'oembed/errors'
+require 'oembed/formatters'
 require 'oembed/provider'
 require 'oembed/providers'
 require 'oembed/response'</diff>
      <filename>lib/oembed.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,34 +2,11 @@ module OEmbed
   class Provider
     attr_accessor :format, :name, :url, :urls, :endpoint
     
-    def initialize(endpoint, format = nil)
+    def initialize(endpoint, format = OEmbed::Formatters::DEFAULT)
       @endpoint = endpoint
       @urls = []
       # Try to use the best available format
-      available_formats = [
-        [:json, lambda {
-          begin
-            JSON.respond_to?(:load)
-          rescue NameError
-            false
-          end
-        }],
-        [:xml, lambda {
-          begin
-            XmlSimple.respond_to?(:xml_in)
-          rescue NameError
-            false
-          end
-        }],
-      ]
-      if format &amp;&amp; to_try = available_formats.assoc(format)
-        available_formats.delete(to_try)
-        @format = format if to_try[1].call
-      end
-      available_formats.each do |format, to_try|
-        break unless @format.nil?
-        @format = format if to_try.call
-      end
+      @format = OEmbed::Formatters.verify?(format)
     end
     
     def &lt;&lt;(url)</diff>
      <filename>lib/oembed/provider.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,19 +4,8 @@ module OEmbed
     attr_reader :fields, :provider, :format
     
     def self.create_for(raw, provider, format = :json)
-      begin
-        fields = case format
-        when :json
-          JSON.load(raw)
-        when :xml
-          XmlSimple.xml_in(raw, {'ForceArray'=&gt;false})
-        else
-          raise OEmbed::FormatNotSupported, format.inspect
-        end
-      rescue NameError
-        raise OEmbed::FormatNotSupported, format.inspect
-      end
-
+      fields = OEmbed::Formatters.convert(format, raw)
+      
       resp_type = case fields['type']
         when 'photo' : OEmbed::Response::Photo
         when 'video' : OEmbed::Response::Video</diff>
      <filename>lib/oembed/response.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,6 +4,7 @@ describe OEmbed::Provider do
   include OEmbedSpecHelper
   
   before(:all) do
+    @default = OEmbed::Formatters::DEFAULT
     @flickr = OEmbed::Provider.new(&quot;http://www.flickr.com/services/oembed/&quot;)
     @qik = OEmbed::Provider.new(&quot;http://qik.com/api/oembed.{format}&quot;, :xml)
     @viddler = OEmbed::Provider.new(&quot;http://lab.viddler.com/services/oembed/&quot;, :json)
@@ -14,8 +15,8 @@ describe OEmbed::Provider do
     @viddler &lt;&lt; &quot;http://*.viddler.com/*&quot;
   end
   
-  it &quot;should default to json&quot; do
-    @flickr.format.should == :json
+  it &quot;should by default use OEmbed::Formatters::DEFAULT&quot; do
+    @flickr.format.should == @default
   end
   
   it &quot;should allow xml&quot; do
@@ -27,8 +28,8 @@ describe OEmbed::Provider do
   end
   
   it &quot;should not allow random formats&quot; do
-    @hulu = OEmbed::Provider.new(&quot;http://www.hulu.com/api/oembed.{format}&quot;, :yml)
-    @hulu.format.should == :json
+    proc { OEmbed::Provider.new(&quot;http://www.hulu.com/api/oembed.{format}&quot;, :yml) }.
+    should raise_error(OEmbed::FormatNotSupported)
   end
   
   it &quot;should add URL schemes&quot; do
@@ -151,8 +152,8 @@ describe OEmbed::Provider do
     
     it &quot;should send the provider's format if none is specified&quot; do
       @flickr.should_receive(:raw).
-        with(url(:flickr), :format=&gt;:json).
-        and_return(valid_response(:json))
+        with(url(:flickr), :format =&gt; @default).
+        and_return(valid_response(@default))
       @flickr.get(url(:flickr))
       
       @qik.should_receive(:raw).
@@ -167,7 +168,7 @@ describe OEmbed::Provider do
     end
   
     it &quot;should return OEmbed::Response&quot; do
-      @flickr.stub!(:raw).and_return(valid_response(:json))
+      @flickr.stub!(:raw).and_return(valid_response(@default))
       @flickr.get(url(:flickr)).is_a?(OEmbed::Response).should be_true
     end
   end</diff>
      <filename>spec/provider_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ec9607d4c5908c8dbebff49cad2d0824c8d0ef80</id>
    </parent>
  </parents>
  <author>
    <name>Magnus Holm</name>
    <email>judofyr@gmail.com</email>
  </author>
  <url>http://github.com/judofyr/ruby-oembed/commit/4db06591d2743c774b5f3f427947a5a9a99cb222</url>
  <id>4db06591d2743c774b5f3f427947a5a9a99cb222</id>
  <committed-date>2009-01-30T12:10:20-08:00</committed-date>
  <authored-date>2009-01-30T12:10:20-08:00</authored-date>
  <message>Adding OEmbed::Formatters</message>
  <tree>ddace3038e937ba675e0e7a8d8c8585231274999</tree>
  <committer>
    <name>Magnus Holm</name>
    <email>judofyr@gmail.com</email>
  </committer>
</commit>
