nsivideoconvert 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/lib/nsivideoconvert.rb +11 -0
- data/lib/nsivideoconvert/client.rb +168 -0
- data/lib/nsivideoconvert/configuration.rb +58 -0
- data/lib/nsivideoconvert/errors.rb +26 -0
- data/lib/nsivideoconvert/fake_server.rb +69 -0
- data/spec/configuration_spec.rb +36 -0
- data/spec/nsivideoconvert_spec.rb +111 -0
- data/spec/spec_helper.rb +12 -0
- metadata +161 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem 'sinatra'
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "yard", "~> 0.7"
|
11
|
+
gem "rdoc", "~> 3.12"
|
12
|
+
gem "bundler", "~> 1.1.0"
|
13
|
+
gem "jeweler", "~> 1.8.3"
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Douglas Camata
|
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.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= nsivideogranulate
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to nsivideogranulate
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Douglas Camata. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "nsivideoconvert"
|
18
|
+
gem.homepage = "http://github.com/nsi-iff/nsivideoconvert-ruby.git"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A simple gem to access a nsi.videoconvert node}
|
21
|
+
gem.description = %Q{A simple gem to access a nsi.videogconvert node}
|
22
|
+
gem.email = "d.camata@gmail.com"
|
23
|
+
gem.authors = ["Douglas Camata"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
spec.rspec_opts = "--color --format nested"
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'yard'
|
38
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require "json"
|
2
|
+
require "net/http"
|
3
|
+
require File.dirname(__FILE__) + '/errors'
|
4
|
+
require File.dirname(__FILE__) + '/configuration'
|
5
|
+
|
6
|
+
module NSIVideoConvert
|
7
|
+
class Client
|
8
|
+
|
9
|
+
# Initialize a client to a VideoConvert node
|
10
|
+
#
|
11
|
+
# @param [Hash] options used to connect to the VideoConvert node
|
12
|
+
# @options options [String] host to connect
|
13
|
+
# @options options [String] port to connect
|
14
|
+
# @options options [String] user to authenticatie with
|
15
|
+
# @options options [String] password to the refered user
|
16
|
+
#
|
17
|
+
# @return [Client] the object itself
|
18
|
+
# @example
|
19
|
+
# videoconvert = NSIVideoConvert::Client.new host: 'localhost', port: '8886', user: 'test', password: 'test'
|
20
|
+
#
|
21
|
+
# @note if you had used the 'configure' method, you can use it without parameters
|
22
|
+
# and those you provided before will be used (see Client#configure)
|
23
|
+
def initialize(params = {})
|
24
|
+
params = Configuration.settings.merge(params)
|
25
|
+
@user = params[:user]
|
26
|
+
@password = params[:password]
|
27
|
+
@host = params[:host]
|
28
|
+
@port = params[:port]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Send a video be converted by a nsi.videoconvert node
|
32
|
+
#
|
33
|
+
# @param [Hash] options used to send a video to be converted
|
34
|
+
# @option options [String] file the base64 encoded file to be converted
|
35
|
+
# @option options [String] sam_uid the UID of a video at SAM
|
36
|
+
# @option options [String] filename the filename of the video
|
37
|
+
# @note the filename is very importante, the videoconvert node will use the proper coding/encoding option for the video type
|
38
|
+
# @option options [String] video_link link to the video that'll be converted
|
39
|
+
# @note if provided both video_link and file options, file will be ignored and the client will download the video instead
|
40
|
+
# @option options [String] callback a callback url to the file convertion
|
41
|
+
# @option options [String] verb the callback request verb, when not provided, nsi.videoconvert defaults to POST
|
42
|
+
#
|
43
|
+
# @example A simple convertion
|
44
|
+
# require 'base64'
|
45
|
+
# video = Base64.encode64(File.new('video.ogv', 'r').read)
|
46
|
+
# response = nsivideoconvert.convert(:file => video, :filename => 'video.ogv')
|
47
|
+
# nsivideoconvert.done(response["video_key"])
|
48
|
+
# nsivideoconvert.grains_keys_for(response["video_key"])
|
49
|
+
# @example Converting from a SAM uid
|
50
|
+
# video = Base64.encode64(File.new('video.ogv', 'r').read)
|
51
|
+
# response = sam.store({:doc => doc})
|
52
|
+
# video_key = response["key"]
|
53
|
+
# response = nsivideoconvert.convert(:sam_uid => video_key, :filename => 'video.ogv')
|
54
|
+
# nsivideoconvert.done(response["video_key"])
|
55
|
+
# nsivideoconvert.grains_keys_for(response["video_key"])
|
56
|
+
# @example Downloading and converting from web
|
57
|
+
# response = nsivideoconvert.convert(:video_link => 'http://google.com/video.ogv')
|
58
|
+
# nsivideoconvert.done(response["video_key"])
|
59
|
+
# nsivideoconvert.grains_keys_for(response["video_key"])
|
60
|
+
# @example Sending a callback url
|
61
|
+
# video = Base64.encode64(File.new('video.ogv', 'r').read)
|
62
|
+
# nsivideoconvert.convert(:file => video, :filename => 'video.ogv', :callback => 'http://google.com')
|
63
|
+
# nsivideoconvert.convert(:video_link => 'http://google.com/video.ogv', :callback => 'http://google.com')
|
64
|
+
# @example Using a custom verb to the callback
|
65
|
+
# video = Base64.encode64(File.new('video.ogv', 'r').read)
|
66
|
+
# nsivideoconvert.convert(:file => video, :filename => 'video.ogv', :callback => 'http://google.com', :verb => "PUT")
|
67
|
+
# nsivideoconvert.convert(:video_link => 'http://google.com/video.ogv', :callback => 'http://google.com', :verb => "PUT")
|
68
|
+
#
|
69
|
+
# @return [Hash] response
|
70
|
+
# * "video_key" [String] the key to access the converted video in the sam node it was stored
|
71
|
+
#
|
72
|
+
# @raise NSIVideoConvert::Errors::Client::MissingParametersError when an invalid or incomplete set of parameters is provided
|
73
|
+
# @raise NSIVideoConvert::Errors::Client::SAMConnectionError when cannot connect to the SAM node
|
74
|
+
# @raise NSIVideoConvert::Errors::Client::AuthenticationError when invalids user and/or password are provided
|
75
|
+
# @raise NSIVideoConvert::Errors::Client::KeyNotFoundError when an invalid sam_uid is provided
|
76
|
+
#
|
77
|
+
def convert(options = {})
|
78
|
+
@request_data = Hash.new
|
79
|
+
if options[:video_link]
|
80
|
+
insert_download_data options
|
81
|
+
elsif options[:sam_uid] && options[:filename]
|
82
|
+
file_data = {:sam_uid => options[:sam_uid], :filename => options[:filename]}
|
83
|
+
@request_data.merge! file_data
|
84
|
+
elsif options[:file] && options[:filename]
|
85
|
+
file_data = {:video => options[:file], :filename => options[:filename]}
|
86
|
+
@request_data.merge! file_data
|
87
|
+
else
|
88
|
+
raise NSIVideoConvert::Errors::Client::MissingParametersError
|
89
|
+
end
|
90
|
+
insert_callback_data options
|
91
|
+
request = prepare_request :POST, @request_data.to_json
|
92
|
+
execute_request(request)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Verify if a video is already converted
|
96
|
+
#
|
97
|
+
#
|
98
|
+
# @param [String] key of the desired video
|
99
|
+
# @return [Hash] response
|
100
|
+
# * "done" [String] true if the video was already granualted, otherwise, false
|
101
|
+
#
|
102
|
+
# @example
|
103
|
+
# nsivideoconvert.done("some key")
|
104
|
+
#
|
105
|
+
# @raise NSIVideoConvert::Errors::Client::SAMConnectionError when cannot connect to the SAM node
|
106
|
+
# @raise NSIVideoConvert::Errors::Client::AuthenticationError when invalids user and/or password are provided
|
107
|
+
# @raise NSIVideoConvert::Errors::Client::KeyNotFoundError when an invalid key is provided
|
108
|
+
#
|
109
|
+
def done(key)
|
110
|
+
request = prepare_request :GET, {:key => key}.to_json
|
111
|
+
execute_request(request)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Pre-configure the NSIVideoConvert module with default params for the NSIVideoConvert::Client
|
115
|
+
#
|
116
|
+
# @yield a Configuration object (see {NSIVideoConvert::Client::Configuration})
|
117
|
+
#
|
118
|
+
# @example
|
119
|
+
# NSIVideoConvert::Client.configure do
|
120
|
+
# user "why"
|
121
|
+
# password "chunky"
|
122
|
+
# host "localhost"
|
123
|
+
# port "8888"
|
124
|
+
# end
|
125
|
+
def self.configure(&block)
|
126
|
+
Configuration.instance_eval(&block)
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
def insert_download_data(options)
|
132
|
+
download_data = {video_link: options[:video_link]}
|
133
|
+
@request_data.merge! download_data
|
134
|
+
end
|
135
|
+
|
136
|
+
def insert_callback_data(options)
|
137
|
+
@request_data[:callback] = options[:callback] unless options[:callback].nil?
|
138
|
+
@request_data[:verb] = options[:verb] unless options[:verb].nil?
|
139
|
+
end
|
140
|
+
|
141
|
+
def prepare_request(verb, body)
|
142
|
+
verb = verb.to_s.capitalize!
|
143
|
+
request = Net::HTTP.const_get("#{verb}").new '/'
|
144
|
+
request.body = body
|
145
|
+
request.basic_auth @user, @password
|
146
|
+
request
|
147
|
+
end
|
148
|
+
|
149
|
+
def execute_request(request)
|
150
|
+
begin
|
151
|
+
response = Net::HTTP.start @host, @port do |http|
|
152
|
+
http.request(request)
|
153
|
+
end
|
154
|
+
rescue Errno::ECONNREFUSED => e
|
155
|
+
raise NSIVideoConvert::Errors::Client::ConnectionRefusedError
|
156
|
+
else
|
157
|
+
raise NSIVideoConvert::Errors::Client::KeyNotFoundError if response.code == "404"
|
158
|
+
raise NSIVideoConvert::Errors::Client::MalformedRequestError if response.code == "400"
|
159
|
+
raise NSIVideoConvert::Errors::Client::AuthenticationError if response.code == "401"
|
160
|
+
raise NSIVideoConvert::Errors::Client::QueueServiceConnectionError if response.code == "503"
|
161
|
+
if response.code == "500" and response.body.include?("SAM")
|
162
|
+
raise NSIVideoConvert::Errors::Client::SAMConnectionError
|
163
|
+
end
|
164
|
+
JSON.parse(response.body)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module NSIVideoConvert
|
2
|
+
class Client
|
3
|
+
class Configuration
|
4
|
+
class << self
|
5
|
+
# Set the default {NSIVideoConvert::Client} user
|
6
|
+
#
|
7
|
+
#
|
8
|
+
# @param [String] user to set
|
9
|
+
#
|
10
|
+
# @return [String] the user set
|
11
|
+
def user(user = nil)
|
12
|
+
@user = user unless user.nil?
|
13
|
+
@user
|
14
|
+
end
|
15
|
+
|
16
|
+
# Set the default {NSIVideoConvert::Client} password
|
17
|
+
#
|
18
|
+
#
|
19
|
+
# @param [String] password to set
|
20
|
+
#
|
21
|
+
# @return [String] the password set
|
22
|
+
def password(password = nil)
|
23
|
+
@password = password unless password.nil?
|
24
|
+
@password
|
25
|
+
end
|
26
|
+
|
27
|
+
# Set the default {NSIVideoConvert::Client} host
|
28
|
+
#
|
29
|
+
#
|
30
|
+
# @param [String] host to set
|
31
|
+
#
|
32
|
+
# @return [String] the host set
|
33
|
+
def host(host = nil)
|
34
|
+
@host = host unless host.nil?
|
35
|
+
@host
|
36
|
+
end
|
37
|
+
|
38
|
+
# Set the default {NSIVideoConvert::Client} port
|
39
|
+
#
|
40
|
+
#
|
41
|
+
# @param [String] port to set
|
42
|
+
#
|
43
|
+
# @return [String] the port set
|
44
|
+
def port(port = nil)
|
45
|
+
@port = port unless port.nil?
|
46
|
+
@port
|
47
|
+
end
|
48
|
+
|
49
|
+
# See how are the settings
|
50
|
+
#
|
51
|
+
# @return [Hash] actual settings
|
52
|
+
def settings
|
53
|
+
{user: @user, password: @password, host: @host, port: @port}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module NSIVideoConvert
|
2
|
+
module Errors
|
3
|
+
module Client
|
4
|
+
class KeyNotFoundError < RuntimeError
|
5
|
+
end
|
6
|
+
|
7
|
+
class MissingParametersError < RuntimeError
|
8
|
+
end
|
9
|
+
|
10
|
+
class MalformedRequestError < RuntimeError
|
11
|
+
end
|
12
|
+
|
13
|
+
class AuthenticationError < RuntimeError
|
14
|
+
end
|
15
|
+
|
16
|
+
class SAMConnectionError < RuntimeError
|
17
|
+
end
|
18
|
+
|
19
|
+
class ConnectionRefusedError < RuntimeError
|
20
|
+
end
|
21
|
+
|
22
|
+
class QueueServiceConnectionError < RuntimeError
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "sinatra"
|
3
|
+
require "json"
|
4
|
+
require "thread"
|
5
|
+
|
6
|
+
module NSIVideoConvert
|
7
|
+
class Server < Sinatra::Application
|
8
|
+
|
9
|
+
def self.prepare
|
10
|
+
@@done = Hash.new
|
11
|
+
end
|
12
|
+
|
13
|
+
post "/" do
|
14
|
+
content_type :json
|
15
|
+
incoming = JSON.parse(request.body.read)
|
16
|
+
filename = incoming["filename"]
|
17
|
+
filename = File.basename(incoming["video_link"]) if incoming.has_key? "video_link"
|
18
|
+
callback = incoming["callback"] || nil
|
19
|
+
verb = incoming["verb"] || nil
|
20
|
+
if filename.include? "secs"
|
21
|
+
seconds = filename.split(".")[0].delete("secs").to_i
|
22
|
+
sleep seconds-1
|
23
|
+
elsif filename.include? "queue error"
|
24
|
+
return 503
|
25
|
+
end
|
26
|
+
{
|
27
|
+
key: "key for video #{filename}",
|
28
|
+
callback: callback,
|
29
|
+
verb: verb,
|
30
|
+
}.to_json
|
31
|
+
end
|
32
|
+
|
33
|
+
get "/" do
|
34
|
+
content_type :json
|
35
|
+
incoming = JSON.parse(request.body.read)
|
36
|
+
if incoming.has_key?("key") && incoming["key"].include?("secs")
|
37
|
+
unless @@done.has_key? incoming["key"]
|
38
|
+
@@done[incoming["key"]] = true
|
39
|
+
return {done: false}.to_json
|
40
|
+
else
|
41
|
+
return {done: true}.to_json
|
42
|
+
end
|
43
|
+
end
|
44
|
+
return 404 if incoming["key"].include? "dont"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class FakeServerManager
|
49
|
+
|
50
|
+
# Start the nsi.videoconvert fake server
|
51
|
+
#
|
52
|
+
# @param [Fixnum] port the port where the fake server will listen
|
53
|
+
# * make sure there's not anything else listenning on this port
|
54
|
+
def start_server(port=9886)
|
55
|
+
@thread = Thread.new do
|
56
|
+
Server.prepare
|
57
|
+
Server.run! :port => port
|
58
|
+
end
|
59
|
+
sleep(1)
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
63
|
+
# Stop the fake server
|
64
|
+
def stop_server
|
65
|
+
@thread.kill
|
66
|
+
self
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "NSIVideoConvert::Client::Configuration" do
|
4
|
+
Configuration = NSIVideoConvert::Client::Configuration
|
5
|
+
|
6
|
+
it "set and return user" do
|
7
|
+
Configuration.user 'why'
|
8
|
+
Configuration.user.should == 'why'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "set and return password" do
|
12
|
+
Configuration.password 'admin123'
|
13
|
+
Configuration.password.should == 'admin123'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "set and return host" do
|
17
|
+
Configuration.host '192.168.0.100'
|
18
|
+
Configuration.host.should == '192.168.0.100'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "set and return port" do
|
22
|
+
Configuration.port '8888'
|
23
|
+
Configuration.port.should == '8888'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "return a hash of attributes" do
|
27
|
+
Configuration.instance_eval do
|
28
|
+
user "why"
|
29
|
+
password "chunky"
|
30
|
+
host "localhost"
|
31
|
+
port "8888"
|
32
|
+
end
|
33
|
+
Configuration.settings.should == {user: "why", password: "chunky",
|
34
|
+
host: "localhost", port: "8888"}
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
$folder = File.expand_path(File.dirname(__FILE__))
|
5
|
+
|
6
|
+
describe NSIVideoConvert do
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
@nsivideoconvert = NSIVideoConvert::Client.new user: 'test', password: 'test',
|
10
|
+
host: 'localhost', port: '9886'
|
11
|
+
@fake_cloudooo = NSIVideoConvert::FakeServerManager.new.start_server
|
12
|
+
end
|
13
|
+
|
14
|
+
after :all do
|
15
|
+
@fake_cloudooo.stop_server
|
16
|
+
end
|
17
|
+
|
18
|
+
context "cannot connect to the server" do
|
19
|
+
it "throws error if couldn't connec to the server" do
|
20
|
+
nsivideoconvert = NSIVideoConvert::Client.new user: 'test', password: 'test',
|
21
|
+
host: 'localhost', port: '4000'
|
22
|
+
expect { nsivideoconvert.convert(:file => 'video', :filename => "teste.flv") }.to \
|
23
|
+
raise_error(NSIVideoConvert::Errors::Client::ConnectionRefusedError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "simple convertion" do
|
28
|
+
it "can send a video to be converted by a nsivideoconvert node" do
|
29
|
+
response = @nsivideoconvert.convert(:file => 'video', :filename => 'video.ogv')
|
30
|
+
response.should_not be_nil
|
31
|
+
response["key"].should == "key for video video.ogv"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should throw error if any required parameter is missing" do
|
35
|
+
expect { @nsivideoconvert.convert(:file => 'video') }.to raise_error(NSIVideoConvert::Errors::Client::MissingParametersError)
|
36
|
+
expect { @nsivideoconvert.convert(:cloudooo_uid => 'video') }.to raise_error(NSIVideoConvert::Errors::Client::MissingParametersError)
|
37
|
+
expect { @nsivideoconvert.convert(:filename => 'video') }.to raise_error(NSIVideoConvert::Errors::Client::MissingParametersError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "convertion with download" do
|
42
|
+
it "can download videos from a link to be convertd by a cloudooo node" do
|
43
|
+
response = @nsivideoconvert.convert(:video_link => "http://video_link/video.ogv")
|
44
|
+
response.should_not be_nil
|
45
|
+
response["key"].should == "key for video video.ogv"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "convertion with callback" do
|
50
|
+
it "can send a video to be converted by a cloudooo node and specify a callback url" do
|
51
|
+
response = @nsivideoconvert.convert(:file => 'video', :filename => 'video.ogv', :callback => 'http://google.com')
|
52
|
+
response.should_not be_nil
|
53
|
+
response["key"].should == "key for video video.ogv"
|
54
|
+
response["callback"].should == 'http://google.com'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "can send a video to be convertd by a cloudooo node and specify the verb" do
|
58
|
+
response = @nsivideoconvert.convert(:file => 'video', :filename => 'video.ogv', :callback => 'http://google.com', :verb => 'PUT')
|
59
|
+
response.should_not be_nil
|
60
|
+
response["key"].should == "key for video video.ogv"
|
61
|
+
response["callback"].should == 'http://google.com'
|
62
|
+
response["verb"].should == 'PUT'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "verify convertion" do
|
67
|
+
it "can verify is a convertion is done or not" do
|
68
|
+
key = @nsivideoconvert.convert(:file => 'video', :filename => '2secs.flv')["key"]
|
69
|
+
@nsivideoconvert.done(key)["done"].should be_false
|
70
|
+
@nsivideoconvert.done(key)["done"].should be_true
|
71
|
+
end
|
72
|
+
|
73
|
+
it "raises an error when trying to verify if non-existing key is done" do
|
74
|
+
expect { @nsivideoconvert.done("dont")["done"].should be_false }.to raise_error(NSIVideoConvert::Errors::Client::KeyNotFoundError)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "raises an error when the server can't connect to the queue service" do
|
78
|
+
expect { @nsivideoconvert.convert(:file => 'video', :filename => 'queue error' ).should be_false }.to raise_error(NSIVideoConvert::Errors::Client::QueueServiceConnectionError)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
context "get configuration" do
|
84
|
+
before do
|
85
|
+
NSIVideoConvert::Client.configure do
|
86
|
+
user "why"
|
87
|
+
password "chunky"
|
88
|
+
host "localhost"
|
89
|
+
port "8888"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "by configure" do
|
94
|
+
cloudooo = NSIVideoConvert::Client.new
|
95
|
+
cloudooo.instance_variable_get(:@user).should == "why"
|
96
|
+
cloudooo.instance_variable_get(:@password).should == "chunky"
|
97
|
+
cloudooo.instance_variable_get(:@host).should == "localhost"
|
98
|
+
cloudooo.instance_variable_get(:@port).should == "8888"
|
99
|
+
end
|
100
|
+
|
101
|
+
it "by initialize parameters" do
|
102
|
+
cloudooo = NSIVideoConvert::Client.new(user: 'luckystiff', password: 'bacon', host: 'why.com', port: '9999')
|
103
|
+
cloudooo.instance_variable_get(:@user).should == "luckystiff"
|
104
|
+
cloudooo.instance_variable_get(:@password).should == "bacon"
|
105
|
+
cloudooo.instance_variable_get(:@host).should == "why.com"
|
106
|
+
cloudooo.instance_variable_get(:@port).should == "9999"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'nsivideoconvert'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nsivideoconvert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Douglas Camata
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.8.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.8.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: yard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.7'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rdoc
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.12'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.12'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.1.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.1.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: jeweler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.8.3
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.3
|
110
|
+
description: A simple gem to access a nsi.videogconvert node
|
111
|
+
email: d.camata@gmail.com
|
112
|
+
executables: []
|
113
|
+
extensions: []
|
114
|
+
extra_rdoc_files:
|
115
|
+
- LICENSE.txt
|
116
|
+
- README.rdoc
|
117
|
+
files:
|
118
|
+
- .document
|
119
|
+
- .rspec
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.rdoc
|
123
|
+
- Rakefile
|
124
|
+
- VERSION
|
125
|
+
- lib/nsivideoconvert.rb
|
126
|
+
- lib/nsivideoconvert/client.rb
|
127
|
+
- lib/nsivideoconvert/configuration.rb
|
128
|
+
- lib/nsivideoconvert/errors.rb
|
129
|
+
- lib/nsivideoconvert/fake_server.rb
|
130
|
+
- spec/configuration_spec.rb
|
131
|
+
- spec/nsivideoconvert_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
homepage: http://github.com/nsi-iff/nsivideoconvert-ruby.git
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
hash: -1837295922174083911
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 1.8.21
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: A simple gem to access a nsi.videoconvert node
|
161
|
+
test_files: []
|