Skip to content

Commit

Permalink
cool
Browse files Browse the repository at this point in the history
  • Loading branch information
voidfiles committed May 12, 2010
1 parent 0639432 commit 324039b
Show file tree
Hide file tree
Showing 7 changed files with 753 additions and 82 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Changed From The Original
=========================
This is defenitly the "embedly" fork. I replaced everything I could from oohembed.com with embedly. oohembed.com has been running into rate issued with google app engine, so I am just trying to relive the pressure.

All the supported embedly urls are built from the embeddly json file of simple regexps, which can be found at [http://api.embed.ly/static/data/embedly_regex.json](http://api.embed.ly/static/data/embedly_regex.json)

Adding a folder for testing all the possible urls. I am not sure what the best way to do this is, if some one who is more familiar with ruby can explain a better way of doing that I would be much appreciated.

I also included a url file, provided by embedlly as well, so that the library can check for urls that work or not.

There should probably two types of url checks, one for wellformedness, that doesn't make an HTTP call, and then one to see if the actual url works.





54 changes: 38 additions & 16 deletions idea.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "rubygems"
require "lib/oembed"
# Adding providers:
# The second argument defines the default format
flickr = OEmbed::Provider.new("http://www.flickr.com/services/oembed/", :xml)
Expand All @@ -11,27 +13,47 @@
qik = OEmbed::Provider.new("http://qik.com/api/oembed.{format}")
qik << "http://qik.com/*"

# Get a raw XML-file from Flickr
flickr.raw("http://flickr.com/photos/my_user/1231231312")
# Get a raw XML-file from Flickrr
flickr.raw("http://www.flickr.com/photos/varius/4537325286/")

# Get a raw JSON-file from Flickr
flickr.raw("http://flickr.com/photos/my_user/1231231312", :format => :json)
flickr.raw("http://www.flickr.com/photos/varius/4537325286/", :format => :json)


OEmbed::Providers.register_fallback(OEmbed::ProviderDiscovery, OEmbed::Providers::Embedly, OEmbed::Providers::OohEmbed)
#Testing embedly

# Register both providers
OEmbed::Providers.register(flickr, qik)
OEmbed::Providers.register_all()

# Get a raw XML-file from whichever provider matches
OEmbed::Providers.raw("http://qik.com/video/1", :format => :xml)
res = OEmbed::Providers.raw("http://www.escapistmagazine.com/videos/view/apocalypse-lane/1687-Episode-47-Dirty-Rotten-Cyborgs", :format => :xml)
puts res

res = OEmbed::Providers.raw("http://www.ustream.tv/recorded/6724045/highlight/72611#utm_campaign=fhighlights&utm_source=2&utm_medium=music", :format => :json)
puts res

res = OEmbed::Providers.raw("http://www.thedailyshow.com/collection/271554/steve-carell-s-best-daily-show-returns/269838", :format => :json)
puts res


begin
res = OEmbed::Providers.raw("http://www.example.com", :format => :json)
rescue OEmbed::NotFound
puts "not a supported url"
end


# Returns a OEmbed::Response using XmlSimple library to parse the response
res = flickr.get("http://flickr.com/photos/my_user/1231231312")
res = flickr.get("http://www.flickr.com/photos/varius/4537325286/", :format => :xml)
# Returns a OEmbed::Response using the JSON library to parse the response
res = flickr.get("http://flickr.com/photos/my_user/1231231312", :format => :json)

res.is_a?(OEmbed::Response) # => true
res.type # => "photo"
res.version # => "1.0"
res.html # => "<img src='http://farm1.static.flickr.com/2312/3123123_123123.jpg' />"
res.author_name # => "my_user"
res.author_url # => "http://flickr.com/photos/my_user"
res.provider.url # => "http://flickr.com/"
res.provider.name # => "Flickr"
res = flickr.get("http://www.flickr.com/photos/varius/4537325286/", :format => :json)

puts res.is_a?(OEmbed::Response) # => true
puts res.type # => "photo"
puts res.version # => "1.0"
puts res.html # => "<img src='http://farm1.static.flickr.com/2312/3123123_123123.jpg' />"
puts res.author_name # => "my_user"
puts res.author_url # => "http://flickr.com/photos/my_user"
puts res.provider.url # => "http://flickr.com/"
puts res.provider.name # => "Flickr"
31 changes: 31 additions & 0 deletions integration_test/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'rubygems'
require File.dirname(__FILE__) + '/../lib/oembed'
OEmbed::Providers.register_all()
OEmbed::Providers.register_fallback(OEmbed::ProviderDiscovery, OEmbed::Providers::Embedly, OEmbed::Providers::OohEmbed)


passed = "passed"
passed = "failed"
File.open("test_urls.csv", "r") do |infile|
while (line = infile.gets)
begin
res = OEmbed::Providers.raw(line, :format => :json)
passed = "passed"
rescue OEmbed::NotFound => e
if e.message == "OEmbed::NotFound"
puts "not a supported url: " + line
else
puts e.message
end
passed = "failed"
rescue OEmbed::UnknownResponse => e
puts "got a bad network response" + e.message
passed = "failed"
rescue Timeout::Error
puts "timeout error"
passed = "failed"
end

puts passed + ": " + line
end
end
Loading

0 comments on commit 324039b

Please sign in to comment.