heywatch 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/heywatch'
3
+
4
+ VIDEO_URL = 'http://www.youtube.com/watch?v=eBYLyt9Ptrs'
5
+
6
+ def discover_and_download_video(url)
7
+ Discover.create(:url => url, :download => true, :automatic_encode => false) {|percent, total, received| puts "#{percent}%" }
8
+ end
@@ -0,0 +1,149 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require File.dirname(__FILE__) + '/../lib/heywatch'
3
+ include HeyWatch
4
+
5
+
6
+ class TestHeywatch < Test::Unit::TestCase
7
+ def setup
8
+ Base::establish_connection! :login => '', :password => ''
9
+ end
10
+
11
+ # Authentification
12
+
13
+ def test_should_be_authorized
14
+ assert_kind_of Account, Account.find
15
+ end
16
+
17
+ def test_should_raise_if_not_authorized
18
+ assert_raise(NotAuthorized) { Auth::create 'fakelogin', 'fakepasswd' }
19
+ end
20
+
21
+ def test_should_raise_if_not_logged_in
22
+ Base::disconnect!
23
+ assert_raise(NotAuthorized) { Format.find(:first) }
24
+ end
25
+
26
+ # Finding
27
+
28
+ def test_should_return_the_first_format
29
+ assert_kind_of Format, Format.find(:first)
30
+ end
31
+
32
+ def test_should_return_format_with_id
33
+ id = Format.find(:first).id
34
+ assert_kind_of Format, Format.find(id)
35
+ end
36
+
37
+ def test_should_return_all_formats
38
+ formats = Format.find(:all)
39
+ assert_kind_of Array, formats
40
+ assert formats.size > 0
41
+ end
42
+
43
+ def test_should_return_just_three_formats
44
+ formats = Format.find(:all, :limit => 3)
45
+ assert formats.size == 3
46
+ end
47
+
48
+ def test_should_return_all_ipod_formats
49
+ formats = Format.find(:all, :conditions => {:name => /ipod/i})
50
+ formats.each do |f|
51
+ assert f.name =~ /ipod/i
52
+ end
53
+ end
54
+
55
+ def test_should_return_all_formats_using_xvid_codec
56
+ formats = Format.find(:all, :conditions => {:video_codec => 'xvid'})
57
+ formats.each do |f|
58
+ assert f.video_codec == 'xvid'
59
+ end
60
+ end
61
+
62
+ def test_should_return_all_formats_having_width_less_than_176
63
+ formats = Format.find(:all, :conditions => {:width => '< 176'})
64
+ formats.each do |f|
65
+ assert f.width < 176
66
+ end
67
+ end
68
+
69
+ def test_should_find_by_name
70
+ assert_equal 'Mobile 3GP', Format.find_by_name('Mobile 3GP').name
71
+ end
72
+
73
+ def test_should_find_all_by_video_codec
74
+ formats = Format.find_all_by_video_codec('xvid')
75
+ assert_kind_of Array, formats
76
+ formats.each do |f|
77
+ assert f.video_codec =='xvid'
78
+ end
79
+ end
80
+
81
+ def test_should_raise_if_not_found
82
+ assert_raise(ResourceNotFound) { Format.find(99999999) }
83
+ end
84
+
85
+ # Discover
86
+
87
+ def test_should_create_discover
88
+ discover = Discover.create :url => VIDEO_URL
89
+ assert_kind_of Discover, discover
90
+ end
91
+
92
+ def test_should_create_discover_and_go_until_raw_video
93
+ raw_video = discover_and_download_video VIDEO_URL
94
+ assert_kind_of Video, raw_video
95
+ end
96
+
97
+ def test_should_raise_because_invalid_url
98
+ assert_raise(RequestError) { Discover.create :url => 'invalid_url' }
99
+ end
100
+
101
+ def test_should_raise_because_no_video_found
102
+ assert_raise(VideoNotFound) { discover_and_download_video 'http://google.com' }
103
+ end
104
+
105
+ # Job
106
+
107
+ # Each of these tests consume 1 credit.
108
+
109
+ #def test_should_create_job
110
+ # raw_video = discover_and_download_video VIDEO_URL
111
+ # job = Job.create :video_id => raw_video.id, :format_id => Format.find_by_name('Mobile 3GP').id
112
+ # assert_kind_of Job, job
113
+ #end
114
+
115
+ #def test_should_create_job_and_go_until_encoded_video
116
+ # raw_video = discover_and_download_video VIDEO_URL
117
+ # encoded_video = Job.create(:video_id => raw_video.id, :format_id => Format.find_by_name('Mobile 3GP').id) do |percent|
118
+ # puts "#{percent}%"
119
+ # end
120
+ # assert_kind_of EncodedVideo, encoded_video
121
+ #end
122
+
123
+ def test_should_raise_if_format_doesnt_exist
124
+ raw_video = discover_and_download_video VIDEO_URL
125
+ assert_raise(RequestError) { Job.create :video_id => raw_video.id, :format_id => 80000 }
126
+ end
127
+
128
+ def test_should_raise_if_video_doesnt_exist
129
+ assert_raise(RequestError) { Job.create :video_id => 150, :format_id => 2 }
130
+ end
131
+
132
+ # Update and Delete
133
+
134
+ def test_should_update_the_title
135
+ raw_video = discover_and_download_video VIDEO_URL
136
+ raw_video.update_attributes :title => 'mytitle'
137
+ assert_equal 'mytitle', Video.find(raw_video.id).title
138
+ end
139
+
140
+ def test_should_delete_the_video
141
+ raw_video = discover_and_download_video VIDEO_URL
142
+ assert raw_video.destroy
143
+ end
144
+
145
+ def test_should_raise_if_video_doesnt_exist
146
+ assert_raise(ResourceNotFound) { Video.destroy(99999999999) }
147
+ assert_raise(ResourceNotFound) { Video.update(99999999999, :title => 'mytitle') }
148
+ end
149
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: heywatch
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-04-19 00:00:00 +02:00
8
+ summary: Ruby Library for HeyWatch service (http://heywatch.com).
9
+ require_paths:
10
+ - lib
11
+ email: bruno.celeste@heywatch.com
12
+ homepage: http://heywatch.rubyforge.org
13
+ rubyforge_project: heywatch
14
+ description: Ruby Library for HeyWatch service (http://heywatch.com).
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Bruno Celeste
31
+ files:
32
+ - Manifest.txt
33
+ - README.txt
34
+ - Rakefile
35
+ - lib/heywatch.rb
36
+ - lib/heywatch/video.rb
37
+ - lib/heywatch/version.rb
38
+ - lib/heywatch/job.rb
39
+ - lib/heywatch/ext.rb
40
+ - lib/heywatch/encoded_video.rb
41
+ - lib/heywatch/download.rb
42
+ - lib/heywatch/discover.rb
43
+ - lib/heywatch/browser.rb
44
+ - lib/heywatch/base.rb
45
+ - lib/heywatch/auth.rb
46
+ - lib/heywatch/account.rb
47
+ - setup.rb
48
+ - test/test_helper.rb
49
+ - test/test_heywatch.rb
50
+ test_files:
51
+ - test/test_helper.rb
52
+ - test/test_heywatch.rb
53
+ rdoc_options:
54
+ - --quiet
55
+ - --title
56
+ - heywatch documentation
57
+ - --opname
58
+ - index.html
59
+ - --line-numbers
60
+ - --main
61
+ - README.txt
62
+ - --inline-source
63
+ extra_rdoc_files:
64
+ - README.txt
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ requirements: []
70
+
71
+ dependencies:
72
+ - !ruby/object:Gem::Dependency
73
+ name: xml-simple
74
+ version_requirement:
75
+ version_requirements: !ruby/object:Gem::Version::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.0.0
80
+ version: