three_sixty 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,197 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ module Sorenson
4
+ module ThreeSixty
5
+ describe Asset, '#initialize' do
6
+ before do
7
+ data = {
8
+ 'presetXml' => 'some xml data',
9
+ 'encodeDate' => '2009-04-09',
10
+ 'frameRate' => '300',
11
+ 'height' => '450',
12
+ 'dateLastModified' => '2009-04-10',
13
+ 'videoBitrateMode' => 'mode',
14
+ 'mediaType' => 'video',
15
+ 'id' => 'my_asset_id',
16
+ 'accountId' => 'account_id',
17
+ 'numberOfViews' => '50',
18
+ 'application' => 'an application',
19
+ 'audioCodec' => 'audio_codec',
20
+ 'permalinkLocation' => 'http://example.com/test',
21
+ 'status' => 'Live',
22
+ 'description' => 'some text',
23
+ 'videoDuration' => '3000',
24
+ 'abstractFileId' => 'abstract_id',
25
+ 'versionId' => 'versionId',
26
+ 'dateRetrieved' => '2009-04-15',
27
+ 'audioDataRate' => '400',
28
+ 'audioBitrateMode' => 'some_bitrate_mode',
29
+ 'videoCodec' => 'video_codec',
30
+ 'displayName' => 'a descriptive name',
31
+ 'name' => 'file.flv',
32
+ 'videoDataRate' => '4000',
33
+ 'authorId' => 'author_id',
34
+ 'width' => '430',
35
+ 'fileSize' => '401203',
36
+ 'thumbnail' => {'httpLocation' => 'http://somewhere.com/thumbnail'},
37
+ 'filters' => [{'filterDescription' => 'a filter description'}]
38
+ }
39
+ @asset = mock_asset(data)
40
+ end
41
+
42
+ it 'should set presetXml' do
43
+ @asset.presetXml.should == 'some xml data'
44
+ end
45
+
46
+ it 'should set encodeDate' do
47
+ @asset.encodeDate.should == '2009-04-09'
48
+ end
49
+
50
+ it 'should set frameRate' do
51
+ @asset.frameRate.should == '300'
52
+ end
53
+
54
+ it 'should set height' do
55
+ @asset.height.should == '450'
56
+ end
57
+
58
+ it 'should set dateLastModified' do
59
+ @asset.dateLastModified.should == '2009-04-10'
60
+ end
61
+
62
+ it 'should set videoBitrateMode' do
63
+ @asset.videoBitrateMode.should == 'mode'
64
+ end
65
+
66
+ it 'should set mediaType' do
67
+ @asset.mediaType.should == 'video'
68
+ end
69
+
70
+ it 'should set id' do
71
+ @asset.id.should == 'my_asset_id'
72
+ end
73
+
74
+ it 'should set accountId' do
75
+ @asset.accountId.should == 'account_id'
76
+ end
77
+
78
+ it 'should set numberOfViews' do
79
+ @asset.numberOfViews.should == '50'
80
+ end
81
+
82
+ it 'should set application' do
83
+ @asset.application.should == 'an application'
84
+ end
85
+
86
+ it 'should set audioCodec' do
87
+ @asset.audioCodec.should == 'audio_codec'
88
+ end
89
+
90
+ it 'should set permalinkLocation' do
91
+ @asset.permalinkLocation.should == 'http://example.com/test'
92
+ end
93
+
94
+ it 'should set status' do
95
+ @asset.status.should == 'Live'
96
+ end
97
+
98
+ it 'should set description' do
99
+ @asset.description.should == 'some text'
100
+ end
101
+
102
+ it 'should set videoDuration' do
103
+ @asset.videoDuration.should == '3000'
104
+ end
105
+
106
+ it 'should set abstractFileId' do
107
+ @asset.abstractFileId.should == 'abstract_id'
108
+ end
109
+
110
+ it 'should set versionId' do
111
+ @asset.versionId.should == 'versionId'
112
+ end
113
+
114
+ it 'should set dateRetrieved' do
115
+ @asset.dateRetrieved.should == '2009-04-15'
116
+ end
117
+
118
+ it 'should set audioDataRate' do
119
+ @asset.audioDataRate.should == '400'
120
+ end
121
+
122
+ it 'should set audioBitrateMode' do
123
+ @asset.audioBitrateMode.should == 'some_bitrate_mode'
124
+ end
125
+
126
+ it 'should set videoCodec' do
127
+ @asset.videoCodec.should == 'video_codec'
128
+ end
129
+
130
+ it 'should set displayName' do
131
+ @asset.displayName.should == 'a descriptive name'
132
+ end
133
+
134
+ it 'should set name' do
135
+ @asset.name.should == 'file.flv'
136
+ end
137
+
138
+ it 'should set videoDataRate' do
139
+ @asset.videoDataRate.should == '4000'
140
+ end
141
+
142
+ it 'should set authorId' do
143
+ @asset.authorId.should == 'author_id'
144
+ end
145
+
146
+ it 'should set width' do
147
+ @asset.width.should == '430'
148
+ end
149
+
150
+ it 'should set fileSize' do
151
+ @asset.fileSize.should == '401203'
152
+ end
153
+
154
+ it 'should set thumbnail' do
155
+ @asset.thumbnailImageUrl.should == 'http://somewhere.com/thumbnail'
156
+ end
157
+
158
+ end
159
+
160
+ describe Asset, '.find' do
161
+
162
+ before do
163
+ @account = mock_account
164
+ @mock_asset = mock('Account')
165
+ Asset.stub!(:new).with(@account, {'height' => '400'}).and_return(@mock_asset)
166
+ end
167
+
168
+ it 'should fetch the assets for an account' do
169
+ Asset.should_receive(:post_to).with("/api/getMediaList?offset=&quantity=&accountId=#{@account.id}&sessionId=#{@account.sessionId}&status=Live&sort=uploadDate").and_return({'mediaList' => [{'height' => '400'}]})
170
+ Asset.find(@account).should include(@mock_asset)
171
+ end
172
+
173
+ it 'should fetch the assets for an account with an offset' do Asset.should_receive(:post_to).with("/api/getMediaList?offset=5&quantity=&accountId=#{@account.id}&sessionId=#{@account.sessionId}&status=Live&sort=uploadDate").and_return({'mediaList' => [{'height' => '400'}]})
174
+ Asset.find(@account, 5).should include(@mock_asset)
175
+ end
176
+
177
+ it 'should fetch the assets for an account with an offset and a quantity' do
178
+ Asset.should_receive(:post_to).with("/api/getMediaList?offset=5&quantity=10&accountId=#{@account.id}&sessionId=#{@account.sessionId}&status=Live&sort=uploadDate").and_return({'mediaList' => [{'height' => '400'}]})
179
+ Asset.find(@account, 5, 10).should include(@mock_asset)
180
+ end
181
+ end
182
+
183
+ describe Asset, '#get_embed_codes' do
184
+
185
+ it 'should return a list of embed codes' do
186
+ asset = mock_asset
187
+ asset.should_receive(:post_to).with("/api/getAllEmbedcodes?vguid=#{asset.id}&sessionId=#{asset.account.sessionId}").and_return({'embedList' => ['<object width="450" height="320">']})
188
+
189
+ asset.send(:get_embed_codes)
190
+ asset.embedList.should include('450x320 - Widescreen')
191
+ end
192
+
193
+
194
+ end
195
+
196
+ end
197
+ end
data/spec/base_spec.rb ADDED
@@ -0,0 +1,90 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ module Sorenson
4
+ module ThreeSixty
5
+ describe Base, '.post_to' do
6
+ before do
7
+ @url = '/apiTest'
8
+ @json = '{"json": "data"}'
9
+ Base.stub!(:host).and_return('sometest.com')
10
+ Base.stub!(:protocol).and_return('http://')
11
+ @host = 'http://sometest.com'
12
+ RestClient.stub!(:post).with(@host + @url, {}).and_return(@json)
13
+ end
14
+
15
+ it 'should post to a url using RestClient' do
16
+ RestClient.should_receive(:post).with(@host + @url, {}).and_return(@json)
17
+ Base.post_to(@url)
18
+ end
19
+
20
+ it 'should raise an InvalidServerResponse' do
21
+ RestClient.should_receive(:post).with(@host + @url, {}).and_return('bogus data')
22
+ lambda { Base.post_to(@url) }.should raise_error(InvalidServerResponse)
23
+ end
24
+
25
+ it 'should parse JSON and return a hash' do
26
+ Base.post_to(@url).should == {'json' => 'data'}
27
+ end
28
+
29
+ end
30
+
31
+ describe Base, '.protocol' do
32
+
33
+ it 'should return http:// if @@use_ssl is set to false' do
34
+ Base.use_ssl = false
35
+ Base.protocol.should == 'http://'
36
+ end
37
+
38
+ it 'should return http:// if @@use_ssl is set to true' do
39
+ Base.use_ssl = true
40
+ Base.protocol.should == 'https://'
41
+ end
42
+
43
+ end
44
+
45
+ describe Base, '.use_ssl?' do
46
+
47
+ it 'should return false if @@use_ssl is set to false' do
48
+ Base.use_ssl = false
49
+ Base.use_ssl?.should be_false
50
+ end
51
+
52
+ it 'should return true if @@use_ssl is set to true' do
53
+ Base.use_ssl = true
54
+ Base.use_ssl?.should be_true
55
+ end
56
+
57
+
58
+ end
59
+
60
+ describe Base, ".host" do
61
+
62
+ before do
63
+ @filename = '/var/tmp/360host'
64
+ end
65
+
66
+ it 'should return 360.sorensonmedia.com if no override file exists' do
67
+ File.should_receive(:exist?).with(@filename).and_return(false)
68
+ Base.host.should == '360.sorensonmedia.com'
69
+ end
70
+
71
+ it 'should fetch the url of the environment set in the override file if it exists' do
72
+ File.should_receive(:exist?).with(@filename).and_return(true)
73
+ File.should_receive(:read).with(@filename).and_return("test\nbogus data")
74
+ RestClient.should_receive(:get).with("http://www.sorensonmedia.com/internal/apis/360Env.php?env=test").and_return("test.example.com\n")
75
+ Base.host.should == 'test.example.com'
76
+ end
77
+
78
+ end
79
+
80
+ describe Base, ".token_for" do
81
+
82
+ it 'should create a SHA1 hash based on the username and a salt string' do
83
+ username = 'ausernamestring'
84
+ token = Digest::SHA1.hexdigest(Base::TOKEN_SALT + username)
85
+ Base.token_for(username).should == token
86
+ end
87
+
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,134 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ module Sorenson
4
+ module ThreeSixty
5
+
6
+ describe FormatConstraint, '#initialize' do
7
+
8
+ before do
9
+ data = {
10
+ 'id' => 'my_id',
11
+ 'name' => 'a name',
12
+ 'displayName' => 'some format',
13
+ 'defaultVideoDuration' => 1.2,
14
+ 'maxVideoDuration' => 10,
15
+ 'defaultFrameRate' => 400,
16
+ 'maxFrameRate' => 1000,
17
+ 'maxWidth' => 1200,
18
+ 'defaultWidth' => 50,
19
+ 'ratePlanId' => 'base plan',
20
+ 'maxHeight' => 400,
21
+ 'defaultHeight' => 250,
22
+ 'defaultAudioDataRate' => 120,
23
+ 'maxAudioDataRate' => 250,
24
+ 'dateRetrieved' => '2009-04-15',
25
+ 'defaultVideoDataRate' => 30,
26
+ 'maxVideoDataRate' => 1200,
27
+ 'thumbnailGenerationMethod' => 'thumbnail generation method',
28
+ 'defaultAudioCodec' => 'audio codec',
29
+ 'defaultVideoCodec' => 'video codec',
30
+ 'audioBitRateMode' => 'a bit rate mode',
31
+ 'videoBitRateMode' => 'v bit rate mode',
32
+ 'mediaType' => 'media type'
33
+ }
34
+
35
+ @rate_plan = RatePlan.new({})
36
+ @format_contraint = FormatConstraint.new(@rate_plan, data)
37
+ end
38
+
39
+ it 'should set ratePlan' do
40
+ @format_contraint.ratePlan.should == @rate_plan
41
+ end
42
+
43
+ it 'should set name' do
44
+ @format_contraint.name.should == 'a name'
45
+ end
46
+
47
+ it 'should set displayName' do
48
+ @format_contraint.displayName.should == 'some format'
49
+ end
50
+
51
+ it 'should set defaultVideoDuration' do
52
+ @format_contraint.defaultVideoDuration.should == 1.2
53
+ end
54
+
55
+ it 'should set maxVideoDuration' do
56
+ @format_contraint.maxVideoDuration.should == 10
57
+ end
58
+
59
+ it 'should set defaultFrameRate' do
60
+ @format_contraint.defaultFrameRate.should == 400
61
+ end
62
+
63
+ it 'should set maxFrameRate' do
64
+ @format_contraint.maxFrameRate.should == 1000
65
+ end
66
+
67
+ it 'should set maxWidth' do
68
+ @format_contraint.maxWidth.should == 1200
69
+ end
70
+
71
+ it 'should set defaultWidth' do
72
+ @format_contraint.defaultWidth.should == 50
73
+ end
74
+
75
+ it 'should set ratePlanId' do
76
+ @format_contraint.ratePlanId.should == 'base plan'
77
+ end
78
+
79
+ it 'should set maxHeight' do
80
+ @format_contraint.maxHeight.should == 400
81
+ end
82
+
83
+ it 'should set defaultHeight' do
84
+ @format_contraint.defaultHeight.should == 250
85
+ end
86
+
87
+ it 'should set defaultAudioDataRate' do
88
+ @format_contraint.defaultAudioDataRate.should == 120
89
+ end
90
+
91
+ it 'should set maxAudioDataRate' do
92
+ @format_contraint.maxAudioDataRate.should == 250
93
+ end
94
+
95
+ it 'should set dateRetrieved' do
96
+ @format_contraint.dateRetrieved.should == '2009-04-15'
97
+ end
98
+
99
+ it 'should set defaultVideoDataRate' do
100
+ @format_contraint.defaultVideoDataRate.should == 30
101
+ end
102
+
103
+ it 'should set maxVideoDataRate' do
104
+ @format_contraint.maxVideoDataRate.should == 1200
105
+ end
106
+
107
+ it 'should set thumbnailGenerationMethod' do
108
+ @format_contraint.thumbnailGenerationMethod.should == 'thumbnail generation method'
109
+ end
110
+
111
+ it 'should set defaultAudioCodec' do
112
+ @format_contraint.defaultAudioCodec.should == 'audio codec'
113
+ end
114
+
115
+ it 'should set defaultVideoCodec' do
116
+ @format_contraint.defaultVideoCodec.should == 'video codec'
117
+ end
118
+
119
+ it 'should set audioBitRateMode' do
120
+ @format_contraint.audioBitRateMode.should == 'a bit rate mode'
121
+ end
122
+
123
+ it 'should set videoBitRateMode' do
124
+ @format_contraint.videoBitRateMode.should == 'v bit rate mode'
125
+ end
126
+
127
+ it 'should set mediaType' do
128
+ @format_contraint.mediaType.should == 'media type'
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+ end
@@ -0,0 +1,148 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ module Sorenson
4
+ module ThreeSixty
5
+ describe RatePlan, '.getBaseRatePlans' do
6
+
7
+ it 'should fetch the public rate plans from the server and return an array of rate plans' do
8
+ RatePlan.should_receive(:post_to).with('/api/getBaseRatePlans').and_return('baseRatePlans' => [{'id' => '42', 'displayName' => 'fake rate plan'}, {'id' => '24', 'displayName' => 'another fake rate plan'}])
9
+ results = RatePlan.getBaseRatePlans
10
+ results.first.id.should == '42'
11
+ results[1].displayName.should == 'another fake rate plan'
12
+ results.length.should == 2
13
+ end
14
+
15
+ end
16
+
17
+ describe RatePlan, '.getAllRatePlans' do
18
+
19
+ it 'should fetch all the rate plans from the server and return an array of rate plans' do
20
+ RatePlan.should_receive(:post_to).with("/api/getAllRatePlans").and_return('allRatePlans' => [{'id' => '42', 'displayName' => 'fake rate plan'}, {'id' => '24', 'displayName' => 'another fake rate plan'}])
21
+ results = RatePlan.getAllRatePlans
22
+ results.first.id.should == '42'
23
+ results[1].displayName.should == 'another fake rate plan'
24
+ results.length.should == 2
25
+ end
26
+
27
+ end
28
+
29
+
30
+ describe RatePlan, '.getRatePlan' do
31
+
32
+ it 'should fetch all the rate plans from the server and return an array of rate plans' do
33
+ id = 'rate_plan_id'
34
+ RatePlan.should_receive(:post_to).with("/api/getRatePlan?ratePlanId=#{id}").and_return('ratePlanData' => {'id' => '42', 'displayName' => 'fake rate plan'})
35
+ results = RatePlan.getRatePlan(id)
36
+ results.id.should == '42'
37
+ results.displayName.should == 'fake rate plan'
38
+ end
39
+
40
+ end
41
+
42
+ describe RatePlan, '#initialize' do
43
+ before do
44
+ data = {
45
+ 'id' => 'my_id',
46
+ 'displayName' => 'some rate plan',
47
+ 'ratePlanType' => 'rate plan type',
48
+ 'maxThumbnailsPerVideo' => 10,
49
+ 'setupCost' => 400,
50
+ 'monthlyCost' => 100,
51
+ 'annualCost' => 1200,
52
+ 'allowedStreams' => 50,
53
+ 'basePlan' => 'base plan',
54
+ 'dateLastModified' => '2009-04-10',
55
+ 'dateRetrieved' => '2009-04-15',
56
+ 'streamingOverageAllowed' => false,
57
+ 'storageOverageAllowed' => true,
58
+ 'allowedStreamingMBytes' => 5000,
59
+ 'allowedStorageMBytes' => 1240000,
60
+ 'allowedSourceMediaTypes' => ['media', 'type'],
61
+ 'allowedOutputMediaTypes' => ['output', 'types'],
62
+ 'formatConstraints' => ['a fake format constraint'],
63
+ 'sorensonSku' => 'a sku'
64
+ }
65
+
66
+ FormatConstraint.stub!(:new).and_return('a fake format constraint')
67
+ @rate_plan = RatePlan.new(data)
68
+ end
69
+
70
+ it 'should set id' do
71
+ @rate_plan.id.should == 'my_id'
72
+ end
73
+
74
+ it 'should set displayName' do
75
+ @rate_plan.displayName.should == 'some rate plan'
76
+ end
77
+
78
+ it 'should set ratePlanType' do
79
+ @rate_plan.ratePlanType.should == 'rate plan type'
80
+ end
81
+
82
+ it 'should set maxThumbnailsPerVideo' do
83
+ @rate_plan.maxThumbnailsPerVideo.should == 10
84
+ end
85
+
86
+ it 'should set setupCost' do
87
+ @rate_plan.setupCost.should == 400
88
+ end
89
+
90
+ it 'should set monthlyCost' do
91
+ @rate_plan.monthlyCost.should == 100
92
+ end
93
+
94
+ it 'should set annualCost' do
95
+ @rate_plan.annualCost.should == 1200
96
+ end
97
+
98
+ it 'should set allowedStreams' do
99
+ @rate_plan.allowedStreams.should == 50
100
+ end
101
+
102
+ it 'should set basePlan' do
103
+ @rate_plan.basePlan.should == 'base plan'
104
+ end
105
+
106
+ it 'should set dateLastModified' do
107
+ @rate_plan.dateLastModified.should == '2009-04-10'
108
+ end
109
+
110
+ it 'should set dateRetrieved' do
111
+ @rate_plan.dateRetrieved.should == '2009-04-15'
112
+ end
113
+
114
+ it 'should set streamingOverageAllowed' do
115
+ @rate_plan.streamingOverageAllowed.should be_false
116
+ end
117
+
118
+ it 'should set storageOverageAllowed' do
119
+ @rate_plan.storageOverageAllowed.should be_true
120
+ end
121
+
122
+ it 'should set allowedStreamingMBytes' do
123
+ @rate_plan.allowedStreamingMBytes.should == 5000
124
+ end
125
+
126
+ it 'should set allowedStorageMBytes' do
127
+ @rate_plan.allowedStorageMBytes.should == 1240000
128
+ end
129
+
130
+ it 'should set allowedSourceMediaTypes' do
131
+ @rate_plan.allowedSourceMediaTypes.should include('media', 'type')
132
+ end
133
+
134
+ it 'should set allowedOutputMediaTypes' do
135
+ @rate_plan.allowedOutputMediaTypes.should include('output', 'types')
136
+ end
137
+
138
+ it 'should set sorensonSku' do
139
+ @rate_plan.sorensonSku.should == 'a sku'
140
+ end
141
+
142
+ it 'should create an array of formatConstraints' do
143
+ @rate_plan.formatConstraints.should include('a fake format constraint')
144
+ end
145
+
146
+ end
147
+ end
148
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,22 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'lib/sorenson/threesixty'
11
+
12
+ def mock_account(options = {})
13
+ Sorenson::ThreeSixty::Account.stub!(:post_to).with("/api/getMediaListSummary?accountId=my_id&sessionId=session_id").and_return({'totalMediaCount' => 10})
14
+ Sorenson::ThreeSixty::RatePlan.stub!(:new).with('a rate plan').and_return('a rate plan')
15
+ Sorenson::ThreeSixty::Account.new({'sessionId' => 'session_id', 'account' => {'id' => 'my_id'}}.merge(options))
16
+ end
17
+
18
+ def mock_asset(options = {})
19
+ account = mock_account
20
+ Sorenson::ThreeSixty::Asset.stub!(:post_to).with("/api/getAllEmbedcodes?vguid=my_asset_id&sessionId=#{account.sessionId}").and_return({'embedList' => []})
21
+ Sorenson::ThreeSixty::Asset.new(account, {'id' => 'my_asset_id'}.merge(options))
22
+ end