Skip to content
This repository
Browse code

Added Soundcloud filter + tests

  • Loading branch information...
commit a9830db9ce36ac36869ec82186f28b108d817e6a 1 parent c870965
authored May 14, 2012
3  CHANGELOG.md
Source Rendered
... ...
@@ -1,3 +1,6 @@
  1
+## unreleased
  2
+* Added Soundcloud filter
  3
+
1 4
 ## 1.5.3, released 2012-05-08
2 5
 * Fixed Mongoid support
3 6
 
11  lib/auto_html/filters/soundcloud.rb
... ...
@@ -0,0 +1,11 @@
  1
+require 'uri'
  2
+require 'net/http'
  3
+
  4
+AutoHtml.add_filter(:soundcloud).with({}) do |text, options|
  5
+  text.gsub(/(https?):\/\/(www.)?soundcloud\.com\/.*/) do
  6
+    uri = URI("http://soundcloud.com/oembed")
  7
+    uri.query = URI.encode_www_form({:format => 'json', :url => text})
  8
+    response = JSON.parse(Net::HTTP.get(uri))
  9
+    response["html"]
  10
+  end
  11
+end
19  test/unit/filters/soundcloud_test.rb
... ...
@@ -0,0 +1,19 @@
  1
+require File.expand_path('../../unit_test_helper', __FILE__)
  2
+require 'debugger'
  3
+class SoundcloudTest < Test::Unit::TestCase
  4
+
  5
+  def test_transform_url_with_www
  6
+    result = auto_html('http://www.soundcloud.com/forss/flickermood') { soundcloud }
  7
+    assert_equal '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F293&show_artwork=true"></iframe>', result
  8
+  end
  9
+
  10
+  def test_transform_url_without_www
  11
+    result = auto_html('http://soundcloud.com/forss/flickermood') { soundcloud }
  12
+    assert_equal '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F293&show_artwork=true"></iframe>', result
  13
+  end
  14
+
  15
+  def test_transform_url_with_ssl
  16
+    result = auto_html('https://soundcloud.com/forss/flickermood') { soundcloud }
  17
+    assert_equal '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F293&show_artwork=true"></iframe>', result
  18
+  end
  19
+end

0 notes on commit a9830db

Please sign in to comment.
Something went wrong with that request. Please try again.