brightcove-api 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/test/helper.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
-
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- require 'brightcove-api'
7
-
8
- class Test::Unit::TestCase
9
- end
@@ -1,173 +0,0 @@
1
- require 'helper'
2
- require 'fakeweb'
3
- require 'mocha'
4
-
5
- class TestBrightcoveApi < Test::Unit::TestCase
6
- def setup
7
- FakeWeb.allow_net_connect = false
8
- end
9
-
10
- def teardown
11
- FakeWeb.allow_net_connect = true
12
- end
13
-
14
- def test_api_version
15
- assert_equal '1.0.11', Brightcove::API::VERSION
16
- end
17
-
18
- def test_can_set_read_api_url
19
- brightcove = Brightcove::API.new('apikeytoken')
20
-
21
- assert_equal Brightcove::API::READ_API_URL, brightcove.read_api_url
22
-
23
- brightcove.read_api_url = 'http://some.api.com'
24
-
25
- assert_equal 'http://some.api.com', brightcove.read_api_url
26
- end
27
-
28
- def test_can_set_write_api_url
29
- brightcove = Brightcove::API.new('apikeytoken')
30
-
31
- assert_equal Brightcove::API::WRITE_API_URL, brightcove.write_api_url
32
-
33
- brightcove.write_api_url = 'http://some.api.com'
34
-
35
- assert_equal 'http://some.api.com', brightcove.write_api_url
36
- end
37
-
38
- def test_can_set_token
39
- brightcove = Brightcove::API.new('apikeytoken')
40
-
41
- assert_equal 'apikeytoken', brightcove.token
42
- end
43
-
44
- def test_can_set_http_headers
45
- brightcove = Brightcove::API.new('apikeytoken')
46
- brightcove.expects(:headers).at_least_once
47
-
48
- brightcove.set_http_headers({'Accept' => 'application/json'})
49
- end
50
-
51
- def test_can_set_timeout
52
- brightcove = Brightcove::API.new('apikeytoken')
53
- brightcove.expects(:default_timeout).at_least_once
54
-
55
- brightcove.set_timeout(5)
56
- end
57
-
58
- def test_find_all_videos
59
- FakeWeb.register_uri(:get,
60
- 'http://api.brightcove.com/services/library?page_size=5&token=0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.&command=find_all_videos',
61
- :body => File.join(File.dirname(__FILE__), 'fakeweb', 'find_all_videos_response.json'),
62
- :content_type => "application/json")
63
-
64
- brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
65
- brightcove_response = brightcove.get('find_all_videos', {:page_size => 5})
66
-
67
- assert_equal 5, brightcove_response['items'].size
68
- assert_equal 0, brightcove_response['page_number']
69
- end
70
-
71
- def test_find_all_videos_mrss
72
- FakeWeb.register_uri(:get,
73
- 'http://api.brightcove.com/services/library?command=find_all_videos&format=xml&output=mrss&token=0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.',
74
- :body => File.join(File.dirname(__FILE__), 'fakeweb', 'find_all_videos_response.xml'),
75
- :content_type => "application/xml")
76
-
77
- brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
78
- brightcove_response = brightcove.get('find_all_videos', {:output => 'mrss'})
79
-
80
- assert_equal 85, brightcove_response['rss']['channel']['item'].size
81
- end
82
-
83
- def test_search_with_array_params
84
- brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
85
- brightcove.class.expects(:get).with(anything, has_entry(:query => {
86
- :any => ['tag:foo', 'tag:bar'],
87
- :command => 'search_videos',
88
- :token => '0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.'
89
- }))
90
- brightcove_response = brightcove.get('search_videos', { :any => [ "tag:foo", "tag:bar" ] })
91
- end
92
-
93
- def test_search_with_string_params
94
- brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
95
- brightcove.class.expects(:get).with(anything, has_entry(:query => {
96
- 'any' => ['tag:bar', 'tag:foo'],
97
- :command => 'search_videos',
98
- :token => '0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.'
99
- }))
100
- brightcove_response = brightcove.get('search_videos', 'any=tag:bar&any=tag:foo' )
101
- end
102
-
103
- def test_more_complicated_query
104
- brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
105
- brightcove.class.expects(:get).with(anything, has_entry(:query => {
106
- :any => ['tag:foo', 'tag:bar'],
107
- :all => "search_text:foo",
108
- :command => 'search_videos',
109
- :token => '0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.'
110
- }))
111
- brightcove_response = brightcove.get('search_videos', { :any => [ "tag:foo", "tag:bar" ], :all => "search_text:foo" })
112
- end
113
-
114
- def test_brightcove_example_query
115
- FakeWeb.register_uri(:get,
116
- 'http://api.brightcove.com/services/library?all=chicago&all=football&all=tag%3Afree&any=tag%3Acolor&any=tag%3Atechnicolor&command=search_videos&token=0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.',
117
- :body => File.join(File.dirname(__FILE__), 'fakeweb', 'find_all_videos_response.json'),
118
- :content_type => "application/json")
119
-
120
- brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
121
- brightcove_response = brightcove.get('search_videos', {
122
- :any => [ "tag:color", "tag:technicolor" ],
123
- :all => ["football", "chicago", "tag:free"]
124
- })
125
-
126
- assert_equal 5, brightcove_response['items'].size
127
- end
128
-
129
- def test_delete_video
130
- FakeWeb.register_uri(:post,
131
- 'http://api.brightcove.com/services/post',
132
- :body => File.join(File.dirname(__FILE__), 'fakeweb', 'delete_video_response.json'),
133
- :content_type => "application/json")
134
-
135
- brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
136
- brightcove_response = brightcove.post('delete_video', {:video_id => '595153261337'})
137
-
138
- assert brightcove_response.has_key?('result')
139
- assert_equal brightcove_response['error'], nil
140
- end
141
-
142
- def test_create_video_using_post_file
143
- FakeWeb.register_uri(:post,
144
- 'http://api.brightcove.com/services/post',
145
- :body => File.join(File.dirname(__FILE__), 'fakeweb', 'create_video_response.json'),
146
- :content_type => "application/json")
147
-
148
- brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
149
- brightcove_response = brightcove.post_file('create_video',
150
- File.join(File.dirname(__FILE__), 'fakeweb', 'movie.mov'),
151
- :video => {:shortDescription => "Short Description", :name => "Video"})
152
-
153
- assert brightcove_response.has_key?('result')
154
- assert_equal '653155417001', brightcove_response['result'].to_s
155
- assert_equal brightcove_response['error'], nil
156
- end
157
-
158
- def test_create_video_using_post_file_streaming
159
- FakeWeb.register_uri(:post,
160
- 'http://api.brightcove.com/services/post',
161
- :body => File.join(File.dirname(__FILE__), 'fakeweb', 'create_video_response.json'),
162
- :content_type => "application/json")
163
-
164
- brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
165
- brightcove_response = brightcove.post_file_streaming('create_video',
166
- File.join(File.dirname(__FILE__), 'fakeweb', 'movie.mov'), 'video/quicktime',
167
- :video => {:shortDescription => "Short Description", :name => "Video"})
168
-
169
- assert brightcove_response.has_key?('result')
170
- assert_equal '653155417001', brightcove_response['result'].to_s
171
- assert_equal brightcove_response['error'], nil
172
- end
173
- end