-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added options for customizing the widget
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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |