Skip to content

Commit

Permalink
adding 11870.com service and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mamuso committed Jan 3, 2009
1 parent 67af5a0 commit b6422da
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions init.rb
Expand Up @@ -13,3 +13,4 @@
require 'vg_blip'
require 'vg_mtvmusic'
require 'vg_myspace'
require 'vg_11870'
47 changes: 47 additions & 0 deletions lib/vg_11870.rb
@@ -0,0 +1,47 @@
# ----------------------------------------------
# Class for 11870 (11870.com)
# http://11870.com/pro/chic-basic-born/media/b606abfe
# ----------------------------------------------


class Vg11870

def initialize(url=nil, options={})
@url = url
@page = Hpricot(open(url))
@flashvars = get_hash(@page.to_s.split("var flashvars = {")[1].split("};")[0]).delete_if {|key, value| key == "displaywidth" }
@flashvars['logo'] = "http://11870.com#{@flashvars['logo']}" unless @flashvars['logo'].blank?
end

def title
CGI::unescapeHTML @page.search("//h1[@class='fn name']/a").first.inner_html
end

def thumbnail
@flashvars['image']
end

def embed_url
"http://11870.com/multimedia/flvplayer.swf?#{@flashvars.to_query}"
end

def embed_html(width=425, height=344, options={})
"<object width='#{width}' height='#{height}' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'> <param name='movie' value='#{embed_url}' /> <param name='quality' value='high' /><embed src='#{embed_url}' width='#{width}' height='#{height}' quality='high' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'/></object>"
end

def flv
@flashvars['file']
end

protected

def get_hash(string)
hash = Hash.new
string.split(",").each do |elemement|
pieces = elemement.split(': "')
hash[pieces[0]] = "#{pieces[1]}".gsub('"', '').to_s
end
hash.delete_if { |key, value| value.nil? }
end

end
23 changes: 22 additions & 1 deletion test/acts_as_unvlogable_test.rb
Expand Up @@ -19,6 +19,7 @@
require 'vg_blip'
require 'vg_mtvmusic'
require 'vg_myspace'
require 'vg_11870'


class ActsAsUnvlogableTest < Test::Unit::TestCase
Expand Down Expand Up @@ -230,7 +231,7 @@ class ActsAsUnvlogableTest < Test::Unit::TestCase


# ----------------------------------------------------------
# Testing mtvmusic.com
# Testing vids.myspace.com
# ----------------------------------------------------------
context "with an vids.myspace.com video url" do
setup do
Expand All @@ -249,6 +250,26 @@ class ActsAsUnvlogableTest < Test::Unit::TestCase
end


# ----------------------------------------------------------
# Testing 11870.com
# ----------------------------------------------------------
context "with an 11870.com video url" do
setup do
@videotron = UnvlogIt.new("http://11870.com/pro/chic-basic-born/media/b606abfe") # => rocabilis
end
should "initialize a Vg11870 instance" do
assert_equal Vg11870, @videotron.instance_values['object'].class
assert_equal "http://11870.com/pro/chic-basic-born/media/b606abfe", @videotron.instance_values['object'].instance_values['url']
assert_not_nil @videotron.instance_values['object'].instance_values['page']
assert_not_nil @videotron.instance_values['object'].instance_values['flashvars']
end

should "return the video properties" do
check_video_attributes({:title => "Chic & Basic Born"})
end
end


protected

def check_video_attributes(options={})
Expand Down

0 comments on commit b6422da

Please sign in to comment.