three_sixty 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,110 @@
1
+ module Sorenson
2
+ module ThreeSixty
3
+ class Uploader < Base
4
+
5
+ # Attributes
6
+ attr_accessor :account, :application, :pathToAsset, :pathToShortPreview, :pathToMainThumbnail, :pathToSummaryThumbnails, :displayName, :description, :frameRate, :width, :height, :audioDataRate, :videoDataRate, :audioBitRateMode, :videoBitRateMode, :videoDuration, :presetXML, :fileType, :filter, :audioCodec, :videoCodec, :authorName, :sourceFileName, :sourceFileType, :sourceAudioCodec, :sourceVideoCodec, :sourceFrameRate, :sourceWidth, :sourceHeight, :sourceAudioDataRate, :sourceAudioBitRateMode, :sourceVideoDataRate, :sourceVideoBitRateMode
7
+
8
+ # Class Methods
9
+
10
+ # Instance Methods
11
+ def initialize(account, options = {})
12
+ self.account = account
13
+ defaults = {
14
+ 'application' => 'Unknown',
15
+ 'frameRate' => '1:1',
16
+ 'width' => 320,
17
+ 'height' => 240,
18
+ 'audioDataRate' => '19000',
19
+ 'videoDataRate' => '23222',
20
+ 'audioBitRateMode' => 'VBR_STEREO',
21
+ 'videoBitRateMode' => 'VBR_TWO_PASS',
22
+ 'videoDuration' => 0,
23
+ 'fileType' => 'Flash',
24
+ 'audioCodec' => 'unknown',
25
+ 'videoCodec' => 'unknown',
26
+ 'authorName' => 'unknown',
27
+ 'sourceFileName' => 'unknown',
28
+ 'sourceAudioCodec' => 'unknown',
29
+ 'sourceVideoCodec' => 'unknown',
30
+ 'sourceFrameRate' => '1:1',
31
+ 'sourceWidth' => 0,
32
+ 'sourceHeight' => 0,
33
+ 'sourceAudioBitRateMode' => 'unknown',
34
+ 'sourceVideoDataRate' => '23222',
35
+ 'sourceVideoBitRateMode' => 'unknown'
36
+ }
37
+
38
+ attributes = defaults.merge(options)
39
+
40
+ attributes.each do |k,v|
41
+ method = "#{k}=".to_sym
42
+ self.send(method, v) if self.respond_to?(method)
43
+ end
44
+ end
45
+
46
+ def getMD5Hash
47
+ md5 = Digest::MD5.new
48
+
49
+ return false unless File.exist?(pathToAsset)
50
+
51
+ length = File.size(pathToAsset)
52
+ fp = File.open(pathToAsset)
53
+
54
+ totalRead = 0
55
+ numRead = 0
56
+
57
+ numSamples = 100
58
+ sampleSize = 1024
59
+ bytes = 1024
60
+
61
+ puts length
62
+ puts numSamples * sampleSize
63
+ #
64
+ # if (length <= numSamples * sampleSize)
65
+ # while (totalRead < length)
66
+ # totalRead += bytes
67
+ # data = fp.read(bytes)
68
+ # md5.update(data);
69
+ # end
70
+ # else
71
+ # skipBlockSize = length / numSamples - sampleSize
72
+ #
73
+ # long skipBlockSize = length / numSamples - sampleSize;
74
+ #
75
+ # while (length - totalRead > sampleSize + skipBlockSize)
76
+ # {
77
+ # numRead = 0;
78
+ #
79
+ # while (numRead < sampleSize)
80
+ # {
81
+ # numRead = is.read(bytes, 0, Math.min(bytes.length, sampleSize - numRead));
82
+ # md5.update(bytes, 0, numRead);
83
+ # totalRead += numRead;
84
+ # }
85
+ #
86
+ # is.skip(skipBlockSize);
87
+ # totalRead += skipBlockSize;
88
+ # }
89
+ #
90
+ #
91
+ # end
92
+
93
+ md5.hexdigest
94
+ end
95
+
96
+ def uploadAsset
97
+ # url = URI.parse('http://www.example.com/upload')
98
+ # File.open("./image.jpg") do |jpg|
99
+ # req = Net::HTTP::Post::Multipart.new url.path,
100
+ # "file" => UploadIO.new(jpg, "image/jpeg", "image.jpg")
101
+ # res = Net::HTTP.start(url.host, url.port) do |http|
102
+ # http.request(req)
103
+ # end
104
+ # end
105
+ #
106
+ end
107
+
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ #require 'net/http/post/multipart'
3
+ require 'rest_client'
4
+ require 'json'
5
+ require 'digest/sha1'
6
+
7
+ require(File.join(File.dirname(__FILE__), 'threesixty', 'base'))
8
+ require(File.join(File.dirname(__FILE__), 'threesixty', 'account'))
9
+ require(File.join(File.dirname(__FILE__), 'threesixty', 'subaccount'))
10
+ require(File.join(File.dirname(__FILE__), 'threesixty', 'account_summary'))
11
+ require(File.join(File.dirname(__FILE__), 'threesixty', 'asset'))
12
+ require(File.join(File.dirname(__FILE__), 'threesixty', 'asset_metrics'))
13
+ require(File.join(File.dirname(__FILE__), 'threesixty', 'rate_plan'))
14
+ require(File.join(File.dirname(__FILE__), 'threesixty', 'format_constraint'))
15
+ require(File.join(File.dirname(__FILE__), 'threesixty', 'uploader'))
@@ -0,0 +1,308 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ module Sorenson
4
+ module ThreeSixty
5
+ describe Account, "._login" do
6
+ it 'should post_to the url given to it' do
7
+ Account.should_receive(:post_to).with('http://example.com').and_return({'account' => {}})
8
+ Account.should_receive(:new).with('account' => {})
9
+ Account._login('http://example.com')
10
+ end
11
+ end
12
+
13
+ describe Account, '.login' do
14
+
15
+ before do
16
+ Account.stub!(:_login).and_return(Account.new({}))
17
+ end
18
+
19
+ it 'should return an account object' do
20
+ Account.login('test', 'secret').class.should == Account
21
+ end
22
+
23
+ it 'should access /api/loginApi?username=#{username}&password=#{password}' do
24
+ Account.should_receive(:_login).with('/api/loginApi?username=test&password=secret')
25
+ Account.login('test', 'secret')
26
+ end
27
+
28
+ end
29
+
30
+ describe Account, '.loginWithAccountId' do
31
+
32
+ before do
33
+ Account.stub!(:_login).and_return(mock_account)
34
+ end
35
+
36
+ it 'should return an account object' do
37
+ Account.loginWithAccountId('test', 'account_id').class.should == Account
38
+ end
39
+
40
+ it 'should access /api/loginApi?accountId=#{accountId}&password=#{password}' do
41
+ Account.should_receive(:_login).with('/api/loginApi?accountId=account_id&sessionId=session_id')
42
+ Account.loginWithAccountId('account_id', 'session_id')
43
+ end
44
+
45
+ end
46
+
47
+ describe Account, '#initialize' do
48
+ before do
49
+ data = {
50
+ 'sessionId' => 'session_id',
51
+ 'token' => 'a_token',
52
+ 'gotoJuiceURL' => 'http://juice.example.com/',
53
+ 'account' => {
54
+ 'username' => 'test',
55
+ 'status' => 'Live',
56
+ 'id' => 'my_id',
57
+ 'ratePlanExpirationDate' => '2012-01-01',
58
+ 'dateLastModified' => '2009-04-01',
59
+ 'sorensonId' => 'my_sorenson_id',
60
+ 'lastLoginTime' => '2009-04-13',
61
+ 'dateRetrieved' => '2009-04-15',
62
+ 'ratePlan' => 'a rate plan'
63
+ }
64
+ }
65
+ @account = mock_account(data)
66
+ end
67
+
68
+ it 'should set sessionId' do
69
+ @account.sessionId.should == 'session_id'
70
+ end
71
+
72
+ it 'should set token' do
73
+ @account.token.should == 'a_token'
74
+ end
75
+
76
+ # depricated
77
+ it 'should set gotoJuiceURL' do
78
+ @account.gotoJuiceURL.should == 'http://juice.example.com/'
79
+ end
80
+
81
+ it 'should set goto360URL' do
82
+ @account.goto360URL.should == 'http://juice.example.com/'
83
+ end
84
+
85
+ it 'should set username' do
86
+ @account.username.should == 'test'
87
+ end
88
+
89
+ it 'should set status' do
90
+ @account.status.should == 'Live'
91
+ end
92
+
93
+ it 'should set id' do
94
+ @account.id.should == 'my_id'
95
+ end
96
+
97
+ it 'should set customerId' do
98
+ @account.customerId.should == 'my_id'
99
+ end
100
+
101
+ it 'should set ratePlanExpirationDate' do
102
+ @account.ratePlanExpirationDate.should == '2012-01-01'
103
+ end
104
+
105
+ it 'should set dateLastModified' do
106
+ @account.dateLastModified.should == '2009-04-01'
107
+ end
108
+
109
+ it 'should set sorensonId' do
110
+ @account.sorensonId.should == 'my_sorenson_id'
111
+ end
112
+
113
+ it 'should set lastLoginTime' do
114
+ @account.lastLoginTime.should == '2009-04-13'
115
+ end
116
+
117
+ it 'should set dateRetrieved' do
118
+ @account.dateRetrieved.should == '2009-04-15'
119
+ end
120
+
121
+ it 'should set ratePlan' do
122
+ @account.ratePlan.should == 'a rate plan'
123
+ end
124
+
125
+ end
126
+
127
+ describe Account, '.doesAccountExist' do
128
+
129
+ it 'should return true if accountExists is true' do
130
+ Account.should_receive(:post_to).and_return({'accountExists' => true})
131
+ Account.doesAccountExist('reallyavalidusername').should be_true
132
+ end
133
+
134
+ it 'should return false if accountExists is false' do
135
+ Account.should_receive(:post_to).and_return({'accountExists' => false})
136
+ Account.doesAccountExist('acompletelyfakeusername').should be_false
137
+ end
138
+
139
+ end
140
+
141
+ describe Account, '.exists?' do
142
+
143
+ it 'should call doesAccountExist' do
144
+ Account.should_receive(:doesAccountExist).with('reallyavalidusername').and_return(true)
145
+ Account.exists?('reallyavalidusername').should be_true
146
+ end
147
+
148
+ end
149
+
150
+ describe Account, '.activate!' do
151
+
152
+ it 'should call activateAccount' do
153
+ Account.should_receive(:activateAccount).with('reallyavalidusername').and_return(true)
154
+ Account.activate!('reallyavalidusername').should be_true
155
+ end
156
+
157
+ end
158
+
159
+ describe Account, '.deactivate!' do
160
+
161
+ it 'should call deactivateAccount' do
162
+ Account.should_receive(:deactivateAccount).with('reallyavalidusername').and_return(true)
163
+ Account.deactivate!('reallyavalidusername').should be_true
164
+ end
165
+
166
+ end
167
+
168
+ describe Account, ".activateAccount" do
169
+
170
+ it 'should activate the account' do
171
+ username = 'test'
172
+ Account.should_receive(:post_to).with("/api/activateAccount?username=#{username}&vToken=#{Base.token_for(username)}").and_return({'success' => true})
173
+ Account.activateAccount(username).should be_true
174
+ end
175
+
176
+ end
177
+
178
+ describe Account, ".deactivateAccount" do
179
+
180
+ it 'should deactivate the account' do
181
+ username = 'test'
182
+
183
+ Account.should_receive(:post_to).with("/api/deactivateAccount?username=#{username}&vToken=#{Base.token_for(username)}").and_return({'success' => true})
184
+ Account.deactivateAccount(username).should be_true
185
+ end
186
+ end
187
+
188
+ describe Account, ".createAccount" do
189
+
190
+ before do
191
+ @username = 'test'
192
+ @password = 'secret'
193
+ @ratePlanId = 'rate_plan_id'
194
+ @url = "/api/createAccount?vToken=#{Base.token_for(@username)}&username=#{@username}&password=#{@password}&ratePlanId=#{@ratePlanId}"
195
+ Account.stub!(:post_to).with(@url).and_return({'success' => true})
196
+ end
197
+
198
+ it 'should create an account and return true' do
199
+ Account.should_receive(:updatePasswordHack).with(@username, @password).and_return(true)
200
+ Account.createAccount(@username, @password, @ratePlanId).should be_true
201
+ end
202
+
203
+ it 'should create an account, activate, and login if activate is true' do
204
+ Account.should_receive(:activate!).with(@username).and_return(true)
205
+ Account.should_receive(:login).with(@username, @password).and_return('a fake account')
206
+ Account.should_receive(:updatePasswordHack).with(@username, @password).and_return(true)
207
+ Account.createAccount(@username, @password, @ratePlanId, true).should == 'a fake account'
208
+ end
209
+ end
210
+
211
+ describe Account, '.updatePasswordHack' do
212
+
213
+ it 'should change the current accounts password' do
214
+ username = 'auser'
215
+ password = 'newsecret'
216
+ Account.should_receive(:post_to).with("/api/updatePassword?username=#{username}&password=#{password}&sessionId=blah").and_return({'success' => true})
217
+ Account.updatePasswordHack(username, password).should be_true
218
+ end
219
+
220
+ end
221
+
222
+
223
+ describe Account, '#updatePassword' do
224
+
225
+ it 'should change the current accounts password' do
226
+ account = mock_account
227
+ password = 'newsecret'
228
+ account.should_receive(:post_to).with("/api/updatePassword?username=#{account.username}&password=#{password}&sessionId=#{account.sessionId}").and_return({'success' => true})
229
+ account.updatePassword(password).should be_true
230
+ end
231
+
232
+ end
233
+
234
+ describe Account, '#updateUsername' do
235
+
236
+ it 'should change the current accounts username' do
237
+ account = mock_account
238
+ newUsername = 'aNewUsername'
239
+ account.should_receive(:post_to).with("/api/updateUsername?username=#{account.username}&newUsername=#{newUsername}&sessionId=#{account.sessionId}").and_return({'success' => true})
240
+ account.updateUsername(newUsername).should be_true
241
+ end
242
+
243
+ end
244
+
245
+ describe Account, '#getAssets' do
246
+
247
+ it 'should fetch a given range of assets into an array' do
248
+ account = mock_account
249
+ Asset.should_receive(:find).with(account, 0, 5).and_return(['foo'])
250
+ account.getAssets(0, 5).should include('foo')
251
+ end
252
+
253
+ end
254
+
255
+ describe Account, '#getAssetCount' do
256
+
257
+ it 'should return the total asset count' do
258
+ account = mock_account
259
+ account.should_receive(:post_to).with("/api/getMediaListSummary?accountId=#{account.id}&sessionId=#{account.sessionId}").and_return({'totalMediaCount' => 42})
260
+ account.getAssetCount.should == 42
261
+
262
+ end
263
+
264
+ end
265
+
266
+ describe Account, '#getTotalStorageUsed' do
267
+
268
+ it 'should return the total storage used' do
269
+ Account.stub!(:getAssetCount).and_return(10)
270
+ account = mock_account
271
+ account.should_receive(:post_to).with("/api/getTotalStorageUsed?accountId=#{account.id}&sessionId=#{account.sessionId}").and_return({'storageUsed' => 6404172638.0})
272
+ account.getTotalStorageUsed.should == 6404172638.0
273
+
274
+ end
275
+
276
+ end
277
+
278
+ describe Account, '#getStorageUsed' do
279
+
280
+ it 'should return the total storage used' do
281
+ account = mock_account
282
+
283
+ startDate = '2009-04-12'
284
+ endDate = '2009-04-15'
285
+ account.should_receive(:post_to).with("/api/getStorageUsed?accountId=#{account.id}&startDate=#{startDate}&endDate=#{endDate}&sessionId=#{account.sessionId}").and_return({'storageUsed' => 4172638.0})
286
+ account.getStorageUsed(startDate, endDate).should == 4172638.0
287
+
288
+ end
289
+
290
+ end
291
+
292
+ describe Account, '#getAssetMetrics' do
293
+
294
+ it 'should return an AssetMetrics object' do
295
+ account = mock_account
296
+
297
+ startDate = '2009-04-01'
298
+ endDate = '2009-04-15'
299
+
300
+ AssetMetrics.should_receive(:find).with(account, startDate, endDate).and_return(['foo'])
301
+
302
+ account.getAssetMetrics(startDate, endDate).should include('foo')
303
+ end
304
+
305
+ end
306
+
307
+ end
308
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ module Sorenson
4
+ module ThreeSixty
5
+ describe AccountSummary, '#initialize' do
6
+ before do
7
+ data = {
8
+ 'username' => 'test',
9
+ 'status' => 'Live',
10
+ 'id' => 'my_id',
11
+ 'ratePlanExpirationDate' => '2012-01-01',
12
+ 'chosenRatePlan' => 'a cool rate plan',
13
+ 'lastLoginTime' => '2009-04-13',
14
+ }
15
+ @account_summary = AccountSummary.new(data)
16
+ end
17
+
18
+ it 'should set username' do
19
+ @account_summary.username.should == 'test'
20
+ end
21
+
22
+ it 'should set status' do
23
+ @account_summary.status.should == 'Live'
24
+ end
25
+
26
+ it 'should set id' do
27
+ @account_summary.id.should == 'my_id'
28
+ end
29
+
30
+ it 'should set ratePlanExpirationDate' do
31
+ @account_summary.ratePlanExpirationDate.should == '2012-01-01'
32
+ end
33
+
34
+ it 'should set lastLoginTime' do
35
+ @account_summary.lastLoginTime.should == '2009-04-13'
36
+ end
37
+
38
+ it 'should set chosenRatePlan' do
39
+ @account_summary.chosenRatePlan.should == 'a cool rate plan'
40
+ end
41
+
42
+ end
43
+
44
+
45
+ describe AccountSummary, '.getAccountSummaries' do
46
+
47
+ it 'should fetch all accounts' do
48
+ AccountSummary.should_receive(:post_to).with("/api/getAllAccounts").and_return('accounts' => [{'id' => '42', 'username' => 'fake username'}, {'id' => '24', 'username' => 'another fake username'}])
49
+ results = AccountSummary.getAccountSummaries
50
+ results.first.id.should == '42'
51
+ results[1].username.should == 'another fake username'
52
+ results.length.should == 2
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ module Sorenson
4
+ module ThreeSixty
5
+ describe AssetMetrics, '#initialize' do
6
+
7
+ before do
8
+ data = {
9
+ 'playTotal' => 40,
10
+ 'filePlayData' => ['test'],
11
+ 'playData' => [{'eventDay' => '2009-04-01', 'plays' => 40}]
12
+ }
13
+
14
+ @asset_metrics = AssetMetrics.new(data)
15
+ end
16
+
17
+ it 'should set playTotal' do
18
+ @asset_metrics.playTotal.should == 40
19
+ end
20
+
21
+ it 'should set filePlayData' do
22
+ @asset_metrics.filePlayData.should == ['test']
23
+ end
24
+
25
+ it 'should set playData' do
26
+ @asset_metrics.playData.should include('2009-04-01')
27
+ end
28
+
29
+ end
30
+ end
31
+ end