ku6vms_sdk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +47 -0
- data/LICENSE +20 -0
- data/README.md +9 -0
- data/ku6vms_sdk.gemspec +30 -0
- data/lib/grand_cloud/authentication.rb +52 -0
- data/lib/grand_cloud/base.rb +61 -0
- data/lib/grand_cloud/exceptions.rb +13 -0
- data/lib/grand_cloud/version.rb +5 -0
- data/lib/grand_cloud/video.rb +207 -0
- data/lib/grandcloud.rb +29 -0
- data/spec/grand_cloud/video_spec.rb +103 -0
- data/spec/spec_heler.rb +22 -0
- data/test/test.html +11 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZWI1NTZmNjIzMDhiMjVhMjQxMjQwMjRlNjhjYzBhZmY1ZDFjODkzOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDgzZTJhMjU4ODU2YmVlZDlmNGQ3MDQyNmM4MTczNjQ1YTIzMDI2Ng==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NGFiN2IyMmNkOWU1MjljZTJiMTBhYWNiNTE2ZTFiMWZhNGUxNTFkN2M0NjI1
|
10
|
+
OGQ0YjRhOGFmZDFhMmE2OTZmZTE5MzkxZGI3ODViZGQ3Yzk0ODBhM2FlZDNk
|
11
|
+
ZjkyYjFiODdhMzgwZWRmMDg5ZjVkM2M3YzQ0MzkyZGMwMGFmMTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODE0MDFhZDFmODkyYTQ5MWZmMTkzZTgzY2UzZWM3YzAyYzI0MjE0ZGI0OTJh
|
14
|
+
MjdhOTVlNTQyOWMyYTlhMzkwMTdiODUwZGMwNzlkYjFmM2M2NzMzMmMzNWM5
|
15
|
+
Mzc3MjY5M2U0YjA3YTg1OGM5MWFiY2E2NzhjNGZmZTRiNGFhYzg=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.5)
|
5
|
+
columnize (0.3.6)
|
6
|
+
cookiejar (0.3.0)
|
7
|
+
debugger (1.1.3)
|
8
|
+
columnize (>= 0.3.1)
|
9
|
+
debugger-linecache (~> 1.1.1)
|
10
|
+
debugger-ruby_core_source (~> 1.1.2)
|
11
|
+
debugger-linecache (1.1.2)
|
12
|
+
debugger-ruby_core_source (>= 1.1.1)
|
13
|
+
debugger-ruby_core_source (1.1.9)
|
14
|
+
diff-lcs (1.2.4)
|
15
|
+
em-http-request (1.1.0)
|
16
|
+
addressable (>= 2.3.4)
|
17
|
+
cookiejar
|
18
|
+
em-socksify (>= 0.3)
|
19
|
+
eventmachine (>= 1.0.3)
|
20
|
+
http_parser.rb (>= 0.6.0.beta.2)
|
21
|
+
em-socksify (0.3.0)
|
22
|
+
eventmachine (>= 1.0.0.beta.4)
|
23
|
+
eventmachine (1.0.3)
|
24
|
+
http_parser.rb (0.6.0.beta.2)
|
25
|
+
metaclass (0.0.1)
|
26
|
+
mocha (0.12.3)
|
27
|
+
metaclass (~> 0.0.1)
|
28
|
+
multipart_body (0.2.1)
|
29
|
+
rspec (2.14.1)
|
30
|
+
rspec-core (~> 2.14.0)
|
31
|
+
rspec-expectations (~> 2.14.0)
|
32
|
+
rspec-mocks (~> 2.14.0)
|
33
|
+
rspec-core (2.14.4)
|
34
|
+
rspec-expectations (2.14.0)
|
35
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
36
|
+
rspec-mocks (2.14.2)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
debugger
|
43
|
+
em-http-request
|
44
|
+
eventmachine
|
45
|
+
mocha
|
46
|
+
multipart_body
|
47
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Tim Lang <langyong135@gmail.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/ku6vms_sdk.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Load version requiring the canonical "sndacs/version", otherwise Ruby will think
|
4
|
+
# is a different file and complaint about a double declaration of Sndacs::VERSION.
|
5
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
6
|
+
require "grandcloud"
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = "ku6vms_sdk"
|
10
|
+
s.version = GrandCloud::VERSION
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.authors = ["Tim Lang"]
|
13
|
+
s.email = ["langyong135@gmail.com"]
|
14
|
+
s.homepage = "https://github.com/TimLang/ku6vms_sdk"
|
15
|
+
s.summary = "Library for accessing Ku6vms"
|
16
|
+
s.description = "ku6vms library provides access to SNDA ku6vms."
|
17
|
+
|
18
|
+
s.required_rubygems_version = ">= 1.3.6"
|
19
|
+
|
20
|
+
s.add_dependency "em-http-request", "~> 1.0.0"
|
21
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
22
|
+
#s.add_development_dependency "rspec", "~> 2.0"
|
23
|
+
#s.add_development_dependency "test-unit", ">= 2.0"
|
24
|
+
|
25
|
+
s.files = `git ls-files`.split("\n")
|
26
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
27
|
+
s.require_path = "lib"
|
28
|
+
s.license = 'MIT'
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module GrandCloud
|
4
|
+
|
5
|
+
class Authentication
|
6
|
+
attr_reader :secret_access_key, :snda_access_key_id
|
7
|
+
|
8
|
+
def initialize(secret_access_key, snda_access_key_id)
|
9
|
+
@secret_access_key, @snda_access_key_id = secret_access_key, snda_access_key_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_signature options
|
13
|
+
secret_access_key = @secret_access_key
|
14
|
+
http_verb = options[:method].to_s.upcase
|
15
|
+
host = options[:host] || DEFAULT_HOST_URL
|
16
|
+
uri = options[:uri] || ''
|
17
|
+
protocal_params = options[:protocal_params]
|
18
|
+
|
19
|
+
partial_signature = "#{http_verb}\n#{host}\n#{uri}"
|
20
|
+
partial_signature << "\n#{protocal_params}" unless protocal_params.nil?
|
21
|
+
digest = OpenSSL::Digest::Digest.new("sha256")
|
22
|
+
hmac = OpenSSL::HMAC.digest(digest, secret_access_key, partial_signature)
|
23
|
+
|
24
|
+
Base64.encode64(hmac).chomp
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_protocol_params additional_params
|
28
|
+
{
|
29
|
+
:Expires => format_time((DateTime.now+(1/24.00)).to_time),
|
30
|
+
#:Expires => '2013-07-03 00:00:00',
|
31
|
+
:SignatureMethod => 'HmacSHA256',
|
32
|
+
:SndaAccessKeyId => @snda_access_key_id,
|
33
|
+
:Timestamp => format_time(Time.now)
|
34
|
+
#:Timestamp => '2013-07-02 11:36:11'
|
35
|
+
}.merge!(additional_params ? additional_params : {}).sort.collect{|k,v| "#{k}=#{v}"}.join('&')
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_upload_params request_params
|
39
|
+
request_params.merge!({
|
40
|
+
:SignatureMethod => 'HmacSHA256',
|
41
|
+
:SndaAccessKeyId => @snda_access_key_id
|
42
|
+
}).sort.collect{|k,v| "#{k}=#{v}"}.join('&')
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def format_time time
|
47
|
+
time.strftime("%Y-%m-%d %H:%M:%S")
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module GrandCloud
|
4
|
+
|
5
|
+
module Base
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :secret_access_key, :snda_access_key_id
|
9
|
+
|
10
|
+
def send_request options
|
11
|
+
auth = GrandCloud::Authentication.new(@secret_access_key, @snda_access_key_id)
|
12
|
+
protocal_params = auth.generate_protocol_params options[:additional_params]
|
13
|
+
|
14
|
+
signature = auth.create_signature({
|
15
|
+
:method => options[:method],
|
16
|
+
:uri => options[:uri],
|
17
|
+
:protocal_params => protocal_params,
|
18
|
+
:host => options[:host]
|
19
|
+
})
|
20
|
+
|
21
|
+
url = URI.escape((options[:url] || ("http://#{(options[:host] || DEFAULT_HOST_URL)+options[:uri]}")) + "?" + protocal_params)+'&Signature='+CGI::escape(signature)
|
22
|
+
|
23
|
+
params = {:head => {:Accept => options[:header_accept] || 'application/json'}}
|
24
|
+
params.merge!(options[:request_params]) if options[:request_params]
|
25
|
+
EM::HttpRequest.new(url).send((options[:method] && options[:method].downcase) || "get", params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def file_upload options
|
29
|
+
auth = GrandCloud::Authentication.new(@secret_access_key, @snda_access_key_id)
|
30
|
+
|
31
|
+
protocal_params = auth.generate_upload_params options[:request_params]
|
32
|
+
signature = auth.create_signature({
|
33
|
+
:method => options[:method],
|
34
|
+
:uri => options[:uri],
|
35
|
+
:host => options[:host],
|
36
|
+
:protocal_params => protocal_params
|
37
|
+
})
|
38
|
+
|
39
|
+
url = URI.escape(options[:url] + "?" + protocal_params) + '&Signature=' + CGI::escape(signature)
|
40
|
+
|
41
|
+
#multipart patch
|
42
|
+
partfile = Part.new(
|
43
|
+
:name => 'file',
|
44
|
+
:filename => File.basename(options[:file_path]),
|
45
|
+
:body => File.new(options[:file_path]).read
|
46
|
+
)
|
47
|
+
parts = [partfile]
|
48
|
+
body = MultipartBody.new(parts)
|
49
|
+
|
50
|
+
EM::HttpRequest.new(url).post(
|
51
|
+
:head => {
|
52
|
+
'content-type' => "multipart/form-data; boundary=#{body.boundary}"
|
53
|
+
},
|
54
|
+
:body => body.to_s
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,207 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module GrandCloud
|
5
|
+
|
6
|
+
class Video
|
7
|
+
|
8
|
+
def get id
|
9
|
+
json = common_request do
|
10
|
+
Base.send_request({:method => 'get', :uri => "/video/#{id}"})
|
11
|
+
end
|
12
|
+
wrap_object(json['video'])
|
13
|
+
rescue Error::ResponseError => e
|
14
|
+
GrandCloud.logger.error(e)
|
15
|
+
return nil
|
16
|
+
end
|
17
|
+
|
18
|
+
#u must start an event loop when u uploading an media
|
19
|
+
def run
|
20
|
+
EM.run { yield }
|
21
|
+
end
|
22
|
+
|
23
|
+
# upload is an async method
|
24
|
+
def upload title, file_path, &block
|
25
|
+
file = File.new(file_path)
|
26
|
+
creation = Base.send_request({
|
27
|
+
:method => 'post',
|
28
|
+
:uri => '/video',
|
29
|
+
:additional_params => {
|
30
|
+
:Title => title
|
31
|
+
}
|
32
|
+
})
|
33
|
+
creation.callback do
|
34
|
+
rep = JSON.parse(creation.response)
|
35
|
+
GrandCloud.logger.warn(rep)
|
36
|
+
req = Base.file_upload({
|
37
|
+
:method => 'post',
|
38
|
+
:uri => '/vmsUpload.htm',
|
39
|
+
:url => rep['uploadUrl'],
|
40
|
+
:file_path => file_path,
|
41
|
+
:host => rep['uploadUrl'].gsub(/^http:\/\/(.+)\/.+/, '\1'),
|
42
|
+
:request_params => {
|
43
|
+
:sid => rep['sid'],
|
44
|
+
:cfrom => 'client',
|
45
|
+
:filesize => file.size,
|
46
|
+
:ext => File.extname(file)
|
47
|
+
}
|
48
|
+
})
|
49
|
+
callback(req, block.to_proc, rep.select{|k, v| k =='sid' || k =='vid'})
|
50
|
+
end
|
51
|
+
creation.errback do
|
52
|
+
GrandCloud.logger.error('requesting error...')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def update id, title, desc
|
57
|
+
json = common_request do
|
58
|
+
Base.send_request({
|
59
|
+
:method => 'put',
|
60
|
+
:uri => "/video/#{id}",
|
61
|
+
:request_params => {
|
62
|
+
:body => {
|
63
|
+
:Vid => id,
|
64
|
+
:Title => title,
|
65
|
+
:Description => desc
|
66
|
+
}
|
67
|
+
}
|
68
|
+
})
|
69
|
+
end
|
70
|
+
json['returnValue']
|
71
|
+
rescue Error::ResponseError => e
|
72
|
+
GrandCloud.logger.error(e)
|
73
|
+
return false
|
74
|
+
end
|
75
|
+
|
76
|
+
def destory id
|
77
|
+
json = common_request do
|
78
|
+
Base.send_request({
|
79
|
+
:method => 'delete',
|
80
|
+
:uri => "/videos/#{id}"
|
81
|
+
})
|
82
|
+
end
|
83
|
+
json['returnValue']
|
84
|
+
rescue Error::ResponseError => e
|
85
|
+
GrandCloud.logger.error(e)
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
|
89
|
+
def list
|
90
|
+
json = common_request do
|
91
|
+
Base.send_request({:method => 'get', :uri => "/videos"})
|
92
|
+
end
|
93
|
+
json['videoSet'].map{|v| wrap_object(v) }
|
94
|
+
rescue Error::ResponseError => e
|
95
|
+
GrandCloud.logger.error(e)
|
96
|
+
return []
|
97
|
+
end
|
98
|
+
|
99
|
+
def import_ku6 ku6vid
|
100
|
+
common_request do
|
101
|
+
Base.send_request({
|
102
|
+
:method => 'get',
|
103
|
+
:uri => '/videos/importation/ku6',
|
104
|
+
:additional_params => {
|
105
|
+
:Ku6vids => ku6vid
|
106
|
+
}
|
107
|
+
})
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def publish id, programId
|
112
|
+
publish_attributes = %w(vid ku6vid publishedJavaScript publishedHtml publishedSwf)
|
113
|
+
|
114
|
+
json = common_request do
|
115
|
+
Base.send_request({
|
116
|
+
:method => 'get',
|
117
|
+
:uri => "/video/#{id}/publication",
|
118
|
+
:additional_params => {
|
119
|
+
:ProgramId => programId
|
120
|
+
}
|
121
|
+
})
|
122
|
+
end
|
123
|
+
|
124
|
+
json = json['publication'].select {|k, v| publish_attributes.include?(k) }.inject({}) do |r, (k, v)|
|
125
|
+
r.merge!(k => (v.is_a?(Hash) ? v['value'] : v))
|
126
|
+
end
|
127
|
+
wrap_object(json)
|
128
|
+
rescue Error::ResponseError => e
|
129
|
+
GrandCloud.logger.error(e)
|
130
|
+
return nil
|
131
|
+
end
|
132
|
+
|
133
|
+
def get_programs
|
134
|
+
common_request do
|
135
|
+
Base.send_request({
|
136
|
+
:method => 'get',
|
137
|
+
:uri => '/programs'
|
138
|
+
})
|
139
|
+
end
|
140
|
+
rescue Error::ResponseError => e
|
141
|
+
GrandCloud.logger.error(e)
|
142
|
+
return []
|
143
|
+
end
|
144
|
+
|
145
|
+
#15622
|
146
|
+
def get_default_program_id
|
147
|
+
programs = get_programs
|
148
|
+
unless programs.empty?
|
149
|
+
result = programs['programSet'].select{|a| a['programName'] == '默认方案'}
|
150
|
+
result.empty? ? nil : result[0]['programId']
|
151
|
+
else
|
152
|
+
nil
|
153
|
+
end
|
154
|
+
rescue Error::ResponseError => e
|
155
|
+
GrandCloud.logger.error(e)
|
156
|
+
return nil
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
def callback req, func=nil, additional_attributes=nil
|
162
|
+
response = EM::DefaultDeferrable.new
|
163
|
+
req.callback do
|
164
|
+
rep = JSON.parse(req.response)
|
165
|
+
if rep['errors']
|
166
|
+
response.fail(rep)
|
167
|
+
else
|
168
|
+
response.succeed(additional_attributes ? rep.merge!(additional_attributes) : rep)
|
169
|
+
end
|
170
|
+
raise Error::ResponseError.new(rep['errors'][0]) if rep['errors']
|
171
|
+
func.call(rep) if func
|
172
|
+
EM.stop
|
173
|
+
end
|
174
|
+
req.errback do
|
175
|
+
response.fail(nil)
|
176
|
+
raise Error::ResponseError.new("Maybe the network doesn't working")
|
177
|
+
EM.stop
|
178
|
+
end
|
179
|
+
response
|
180
|
+
end
|
181
|
+
|
182
|
+
# mock a sysynchronous request
|
183
|
+
def common_request
|
184
|
+
result= ''
|
185
|
+
EM.run do
|
186
|
+
callback(yield).callback do |rep|
|
187
|
+
result = rep
|
188
|
+
end.errback do |rep|
|
189
|
+
result = rep
|
190
|
+
end
|
191
|
+
end
|
192
|
+
result
|
193
|
+
end
|
194
|
+
|
195
|
+
#wrap object from json, please see the ku6vms document for the object attribute detail
|
196
|
+
def wrap_object json
|
197
|
+
json.inject(self) do |r, (k, v)|
|
198
|
+
r.class.class_eval do; attr_accessor k; end
|
199
|
+
r.__send__("#{k}=", v)
|
200
|
+
r
|
201
|
+
end
|
202
|
+
self
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
data/lib/grandcloud.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'date'
|
3
|
+
require 'net/http'
|
4
|
+
require 'cgi'
|
5
|
+
require 'eventmachine'
|
6
|
+
require 'em-http'
|
7
|
+
require 'json'
|
8
|
+
require 'base64'
|
9
|
+
require 'openssl'
|
10
|
+
require 'multipart_body'
|
11
|
+
require 'logger'
|
12
|
+
require 'grand_cloud/exceptions'
|
13
|
+
require 'grand_cloud/authentication'
|
14
|
+
require 'grand_cloud/base'
|
15
|
+
require 'grand_cloud/video'
|
16
|
+
require 'grand_cloud/version'
|
17
|
+
|
18
|
+
module GrandCloud
|
19
|
+
|
20
|
+
DEFAULT_HOST_URL = "api.ku6vms.com"
|
21
|
+
|
22
|
+
attr_reader :logger
|
23
|
+
|
24
|
+
def self.logger
|
25
|
+
@logger || (@logger = Logger.new(STDOUT))
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_heler'
|
4
|
+
require 'debugger'
|
5
|
+
|
6
|
+
module GrandCloud
|
7
|
+
|
8
|
+
module Rspec
|
9
|
+
#21430166
|
10
|
+
@@video_id = nil
|
11
|
+
|
12
|
+
describe Video do
|
13
|
+
|
14
|
+
before :all do
|
15
|
+
@video = GrandCloud::Video.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def raise_common_request_exception
|
19
|
+
@video.stubs(:common_request).raises(GrandCloud::Error::ResponseError, '')
|
20
|
+
end
|
21
|
+
|
22
|
+
context "#video must done successfully functions" do
|
23
|
+
|
24
|
+
it 'should upload video' do
|
25
|
+
@video.run do
|
26
|
+
GrandCloud.logger.info('start uploading, please wait...')
|
27
|
+
@video.upload('spec_video', '/tmp/test.mp4'){ |rep|
|
28
|
+
@@video_id = rep['vid']
|
29
|
+
rep['code'].should == 200
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should get video detail" do
|
35
|
+
@video.get(@@video_id).vid.should_not nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should list video size greater than zero' do
|
39
|
+
@video.list.size.should > 0
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should list video can get vid' do
|
43
|
+
videos = @video.list
|
44
|
+
videos.each do |v|
|
45
|
+
v.vid.should_not nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should list programs greater than zero' do
|
50
|
+
@video.get_programs.size.should > 0
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should get default program id' do
|
54
|
+
@video.get_default_program_id.should_not nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should update video successfully' do
|
58
|
+
@video.update(@@video_id, 'test foo', 'Foo Bar').should == true
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should delete video successfully' do
|
62
|
+
@video.destory(@@video_id).should == true
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context '#video must done failed functions' do
|
68
|
+
|
69
|
+
it 'should return nil when getting video raise exception' do
|
70
|
+
@video.get(nil).should == nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return false when updating video raise exception" do
|
74
|
+
@video.update(nil, nil, nil).should == false
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return false when deleting video raise exception" do
|
78
|
+
@video.destory(nil).should == false
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should return empty array when listing videos raise exception" do
|
82
|
+
raise_common_request_exception
|
83
|
+
@video.list.should == []
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should return empty array when getting programs raise exception" do
|
87
|
+
raise_common_request_exception
|
88
|
+
@video.get_programs.should == []
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return nil when getting default program id raise exception" do
|
92
|
+
raise_common_request_exception
|
93
|
+
@video.get_default_program_id.should == nil
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should return nil when publishing video raise exception" do
|
97
|
+
@video.publish(nil, nil).should == nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/spec/spec_heler.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
$: << File.join(File.dirname(__FILE__), '../lib')
|
4
|
+
require 'grandcloud'
|
5
|
+
require 'rspec'
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.include RSpec::Matchers
|
10
|
+
|
11
|
+
config.mock_with :rspec
|
12
|
+
end
|
13
|
+
|
14
|
+
module GrandCloud
|
15
|
+
|
16
|
+
GrandCloud::Base.secret_access_key = 'YmU0Mzk5NDYtZGZlMC00ZmNiLWI0Y2YtNzA4NGQxYzk4MGQ1'
|
17
|
+
GrandCloud::Base.snda_access_key_id = 'BH297OBMKFV0T2LO9MC189P2J'
|
18
|
+
|
19
|
+
GrandCloud.logger.formatter = proc do |severity, datetime, progname, msg|
|
20
|
+
"#{datetime}: #{msg}\n"
|
21
|
+
end
|
22
|
+
end
|
data/test/test.html
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
4
|
+
</head>
|
5
|
+
<body>
|
6
|
+
<form action="http://58.215.38.43/vmsUpload.htm?SignatureMethod=HmacSHA256&SndaAccessKeyId=BH297OBMKFV0T2LO9MC189P2J&cfrom=client&ext=.avi&filesize=1987072&sid=1380664177266&Signature=78ohtr7UJGrdz3cOgLpR6FluduK4K0FIUTyQGKWRVzM%3D" method="post" enctype="multipart/form-data">
|
7
|
+
<input name="file" type="file" />
|
8
|
+
<input name="submit" value="Upload" type="submit" />
|
9
|
+
</form>
|
10
|
+
</body>
|
11
|
+
</html>
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ku6vms_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Lang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: em-http-request
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
description: ku6vms library provides access to SNDA ku6vms.
|
42
|
+
email:
|
43
|
+
- langyong135@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
- ku6vms_sdk.gemspec
|
54
|
+
- lib/grand_cloud/authentication.rb
|
55
|
+
- lib/grand_cloud/base.rb
|
56
|
+
- lib/grand_cloud/exceptions.rb
|
57
|
+
- lib/grand_cloud/version.rb
|
58
|
+
- lib/grand_cloud/video.rb
|
59
|
+
- lib/grandcloud.rb
|
60
|
+
- spec/grand_cloud/video_spec.rb
|
61
|
+
- spec/spec_heler.rb
|
62
|
+
- test/test.html
|
63
|
+
homepage: https://github.com/TimLang/ku6vms_sdk
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.3.6
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.0.6
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Library for accessing Ku6vms
|
87
|
+
test_files: []
|
88
|
+
has_rdoc:
|