Skip to content

Commit

Permalink
Added options for customizing the widget
Browse files Browse the repository at this point in the history
submitted wrong url to soundcloud
catch empty responses from soundcloud eg. service is down
  • Loading branch information
Samuel Goebert committed May 14, 2012
1 parent 971c8bd commit 49570b9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/auto_html/filters/soundcloud.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
require 'uri'
require 'net/http'

AutoHtml.add_filter(:soundcloud).with({}) do |text, options|
text.gsub(/(https?):\/\/(www.)?soundcloud\.com\/.*/) do
AutoHtml.add_filter(:soundcloud).with(:maxwidth => '100%', :maxheight => '166', :auto_play => false, :show_comments => true) do |text, options|
text.gsub(/^(https?):\/\/(www.)?soundcloud\.com\/.*/) do |match|
uri = URI("http://soundcloud.com/oembed")
uri.query = URI.encode_www_form({:format => 'json', :url => text})
response = JSON.parse(Net::HTTP.get(uri))
response["html"]
params = {:format => 'json', :url => match}
params = params.merge options
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get(uri)

if !response.blank?
JSON.parse(response)["html"]
else
match
end
end
end

0 comments on commit 49570b9

Please sign in to comment.