ku6vms_sdk 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/grand_cloud/object_ext.rb +6 -0
- data/lib/grand_cloud/version.rb +1 -1
- data/lib/grand_cloud/video.rb +27 -4
- data/lib/grandcloud.rb +1 -0
- data/spec/grand_cloud/video_spec.rb +24 -0
- metadata +3 -2
data/lib/grand_cloud/version.rb
CHANGED
data/lib/grand_cloud/video.rb
CHANGED
@@ -32,14 +32,24 @@ module GrandCloud
|
|
32
32
|
creation.callback { block.call(JSON.parse(creation.response)) }
|
33
33
|
|
34
34
|
creation.errback do
|
35
|
-
GrandCloud.logger.error(
|
35
|
+
GrandCloud.logger.error("Error is: #{creation.error}, requesting error...")
|
36
|
+
block.call(nil)
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
39
40
|
# upload is an async method
|
40
|
-
|
41
|
+
# you should pass an original_filename on options when you uploading a temp file
|
42
|
+
def upload title, file, options={}, pass_encoding=false, &block
|
43
|
+
return EM.stop if ((file.class == Tempfile) && (!options[:original_filename])) || !block_given?
|
44
|
+
|
41
45
|
pn_file = Pathname(file)
|
42
|
-
|
46
|
+
|
47
|
+
title = get_video_title(title, options[:original_filename], pn_file)
|
48
|
+
extname = get_video_extname(options[:original_filename], pn_file)
|
49
|
+
|
50
|
+
self.create(title, pass_encoding) do |rep|
|
51
|
+
|
52
|
+
return block.call(nil) unless rep
|
43
53
|
|
44
54
|
GrandCloud.logger.warn(rep)
|
45
55
|
|
@@ -53,7 +63,7 @@ module GrandCloud
|
|
53
63
|
:sid => rep['sid'],
|
54
64
|
:cfrom => 'client',
|
55
65
|
:filesize => pn_file.size,
|
56
|
-
:ext =>
|
66
|
+
:ext => extname
|
57
67
|
},
|
58
68
|
:timeout => {
|
59
69
|
:inactivity_timeout => 0
|
@@ -65,8 +75,12 @@ module GrandCloud
|
|
65
75
|
end
|
66
76
|
|
67
77
|
def pull_by_vms title, download_url, &block
|
78
|
+
return EM.stop unless block_given?
|
79
|
+
|
68
80
|
self.create(title) do |rep|
|
69
81
|
|
82
|
+
return block.call(nil) unless rep
|
83
|
+
|
70
84
|
GrandCloud.logger.warn(rep)
|
71
85
|
|
72
86
|
req = Base.send_request({
|
@@ -237,6 +251,15 @@ module GrandCloud
|
|
237
251
|
self
|
238
252
|
end
|
239
253
|
|
254
|
+
def get_video_title title, original_filename, pn_file
|
255
|
+
return title unless title.blank?
|
256
|
+
original_filename ? File.basename(original_filename, File.extname(original_filename)) : pn_file.basename(pn_file.extname)
|
257
|
+
end
|
258
|
+
|
259
|
+
def get_video_extname original_filename, pn_file
|
260
|
+
original_filename ? File.extname(original_filename) : pn_file.extname
|
261
|
+
end
|
262
|
+
|
240
263
|
end
|
241
264
|
|
242
265
|
end
|
data/lib/grandcloud.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
3
|
require 'spec_heler'
|
4
|
+
require 'tempfile'
|
4
5
|
require 'debugger'
|
5
6
|
|
6
7
|
module GrandCloud
|
@@ -39,6 +40,19 @@ module GrandCloud
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
43
|
+
it "should upload while mocking a rails controller" do
|
44
|
+
file_path = '/tmp/test.mp4'
|
45
|
+
@video.run do
|
46
|
+
GrandCloud.logger.info('start uploading, please wait...')
|
47
|
+
temp_file = Tempfile.new('/tmp/Rack_tempfiles_0')
|
48
|
+
temp_file.write(File.new(file_path).read)
|
49
|
+
@video.upload('mock_tempfile_as_video', temp_file, {:original_filename => 'woce.mp4'}){ |rep|
|
50
|
+
@@video_id = rep['vid']
|
51
|
+
rep['code'].should == 200
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
42
56
|
it "should get video detail" do
|
43
57
|
@video.get(@@video_id).vid.should_not nil
|
44
58
|
end
|
@@ -82,6 +96,16 @@ module GrandCloud
|
|
82
96
|
@video.update(nil, nil, nil).should == false
|
83
97
|
end
|
84
98
|
|
99
|
+
it "should return nil when uploading video with a temp file without passed an original_filename" do
|
100
|
+
file_path = '/tmp/test.mp4'
|
101
|
+
nil.should == @video.run do
|
102
|
+
GrandCloud.logger.info('start uploading, please wait...')
|
103
|
+
temp_file = Tempfile.new('/tmp/Rack_tempfiles_0')
|
104
|
+
temp_file.write(File.new(file_path).read)
|
105
|
+
@video.upload('mock_tempfile_as_video', temp_file) {}
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
85
109
|
it "should return false when deleting video raise exception" do
|
86
110
|
@video.destory(nil).should == false
|
87
111
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ku6vms_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: em-http-request
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/grand_cloud/authentication.rb
|
60
60
|
- lib/grand_cloud/base.rb
|
61
61
|
- lib/grand_cloud/exceptions.rb
|
62
|
+
- lib/grand_cloud/object_ext.rb
|
62
63
|
- lib/grand_cloud/version.rb
|
63
64
|
- lib/grand_cloud/video.rb
|
64
65
|
- lib/grandcloud.rb
|