nsivideogranulate 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/nsivideogranulate/client.rb +188 -0
- data/lib/nsivideogranulate/configuration.rb +58 -0
- data/lib/nsivideogranulate/errors.rb +26 -0
- data/lib/nsivideogranulate/fake_server.rb +71 -0
- data/lib/nsivideogranulate.rb +11 -0
- data/spec/configuration_spec.rb +36 -0
- data/spec/nsivideogranulate_spec.rb +127 -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 = "nsivideogranulate"
|
18
|
+
gem.homepage = "http://github.com/nsi-iff/nsivideogranulate-ruby.git"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A simple gem to access a nsi.videogranulate node}
|
21
|
+
gem.description = %Q{A simple gem to access a nsi.videogranulate 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,188 @@
|
|
1
|
+
require "json"
|
2
|
+
require "net/http"
|
3
|
+
require File.dirname(__FILE__) + '/errors'
|
4
|
+
require File.dirname(__FILE__) + '/configuration'
|
5
|
+
|
6
|
+
module NSIVideoGranulate
|
7
|
+
class Client
|
8
|
+
|
9
|
+
# Initialize a client to a VideoGranulate node
|
10
|
+
#
|
11
|
+
# @param [Hash] options used to connect to the VideoGranulate 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
|
+
# videogranulate = NSIVideoGranulate::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 granulated by a nsi.videogranulate node
|
32
|
+
#
|
33
|
+
# @param [Hash] options used to send a video to be graulated
|
34
|
+
# @option options [String] file the base64 encoded file to be granulated
|
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 videogranulate 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 granulated
|
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 granulation
|
41
|
+
# @option options [String] verb the callback request verb, when not provided, nsi.videogranulate defaults to POST
|
42
|
+
#
|
43
|
+
# @example A simple granulation
|
44
|
+
# require 'base64'
|
45
|
+
# video = Base64.encode64(File.new('video.ogv', 'r').read)
|
46
|
+
# response = nsivideogranulate.granulate(:file => video, :filename => 'video.ogv')
|
47
|
+
# nsivideogranulate.done(response["video_key"])
|
48
|
+
# nsivideogranulate.grains_keys_for(response["video_key"])
|
49
|
+
# @example Granulating 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 = nsivideogranulate.granulate(:sam_uid => video_key, :filename => 'video.ogv')
|
54
|
+
# nsivideogranulate.done(response["video_key"])
|
55
|
+
# nsivideogranulate.grains_keys_for(response["video_key"])
|
56
|
+
# @example Downloading and granulating from web
|
57
|
+
# response = nsivideogranulate.granulate(:video_link => 'http://google.com/video.ogv')
|
58
|
+
# nsivideogranulate.done(response["video_key"])
|
59
|
+
# nsivideogranulate.grains_keys_for(response["video_key"])
|
60
|
+
# @example Sending a callback url
|
61
|
+
# video = Base64.encode64(File.new('video.ogv', 'r').read)
|
62
|
+
# nsivideogranulate.granulate(:file => video, :filename => 'video.ogv', :callback => 'http://google.com')
|
63
|
+
# nsivideogranulate.granulate(: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
|
+
# nsivideogranulate.granulate(:file => video, :filename => 'video.ogv', :callback => 'http://google.com', :verb => "PUT")
|
67
|
+
# nsivideogranulate.granulate(: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 granulated video in the sam node it was stored
|
71
|
+
#
|
72
|
+
# @raise NSIVideoGranulate::Errors::Client::MissingParametersError when an invalid or incomplete set of parameters is provided
|
73
|
+
# @raise NSIVideoGranulate::Errors::Client::SAMConnectionError when cannot connect to the SAM node
|
74
|
+
# @raise NSIVideoGranulate::Errors::Client::AuthenticationError when invalids user and/or password are provided
|
75
|
+
# @raise NSIVideoGranulate::Errors::Client::KeyNotFoundError when an invalid sam_uid is provided
|
76
|
+
#
|
77
|
+
def granulate(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 NSIVideoGranulate::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 granulated
|
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
|
+
# nsivideogranulate.done("some key")
|
104
|
+
#
|
105
|
+
# @raise NSIVideoGranulate::Errors::Client::SAMConnectionError when cannot connect to the SAM node
|
106
|
+
# @raise NSIVideoGranulate::Errors::Client::AuthenticationError when invalids user and/or password are provided
|
107
|
+
# @raise NSIVideoGranulate::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
|
+
# Return the keys of the grains of a video
|
115
|
+
#
|
116
|
+
#
|
117
|
+
# @param [String] key of the desired video
|
118
|
+
# @return [Hash] response
|
119
|
+
# * "images" [String] keys to the images grains of the video
|
120
|
+
# * "files" [String] keys to the files grains of the video
|
121
|
+
#
|
122
|
+
# @example
|
123
|
+
# nsivideogranulate.grains_keys_for("some key")
|
124
|
+
#
|
125
|
+
# @raise NSIVideoGranulate::Errors::Client::SAMConnectionError when cannot connect to the SAM node
|
126
|
+
# @raise NSIVideoGranulate::Errors::Client::AuthenticationError when invalids user and/or password are provided
|
127
|
+
# @raise NSIVideoGranulate::Errors::Client::KeyNotFoundError when an invalid key is provided
|
128
|
+
#
|
129
|
+
def grains_keys_for(video_key)
|
130
|
+
request = prepare_request :GET, {:video_key => video_key}.to_json
|
131
|
+
execute_request(request)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Pre-configure the NSIVideoGranulate module with default params for the NSIVideoGranulate::Client
|
135
|
+
#
|
136
|
+
# @yield a Configuration object (see {NSIVideoGranulate::Client::Configuration})
|
137
|
+
#
|
138
|
+
# @example
|
139
|
+
# NSIVideoGranulate::Client.configure do
|
140
|
+
# user "why"
|
141
|
+
# password "chunky"
|
142
|
+
# host "localhost"
|
143
|
+
# port "8888"
|
144
|
+
# end
|
145
|
+
def self.configure(&block)
|
146
|
+
Configuration.instance_eval(&block)
|
147
|
+
end
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
def insert_download_data(options)
|
152
|
+
download_data = {video_link: options[:video_link]}
|
153
|
+
@request_data.merge! download_data
|
154
|
+
end
|
155
|
+
|
156
|
+
def insert_callback_data(options)
|
157
|
+
@request_data[:callback] = options[:callback] unless options[:callback].nil?
|
158
|
+
@request_data[:verb] = options[:verb] unless options[:verb].nil?
|
159
|
+
end
|
160
|
+
|
161
|
+
def prepare_request(verb, body)
|
162
|
+
verb = verb.to_s.capitalize!
|
163
|
+
request = Net::HTTP.const_get("#{verb}").new '/'
|
164
|
+
request.body = body
|
165
|
+
request.basic_auth @user, @password
|
166
|
+
request
|
167
|
+
end
|
168
|
+
|
169
|
+
def execute_request(request)
|
170
|
+
begin
|
171
|
+
response = Net::HTTP.start @host, @port do |http|
|
172
|
+
http.request(request)
|
173
|
+
end
|
174
|
+
rescue Errno::ECONNREFUSED => e
|
175
|
+
raise NSIVideoGranulate::Errors::Client::ConnectionRefusedError
|
176
|
+
else
|
177
|
+
raise NSIVideoGranulate::Errors::Client::KeyNotFoundError if response.code == "404"
|
178
|
+
raise NSIVideoGranulate::Errors::Client::MalformedRequestError if response.code == "400"
|
179
|
+
raise NSIVideoGranulate::Errors::Client::AuthenticationError if response.code == "401"
|
180
|
+
raise NSIVideoGranulate::Errors::Client::QueueServiceConnectionError if response.code == "503"
|
181
|
+
if response.code == "500" and response.body.include?("SAM")
|
182
|
+
raise NSIVideoGranulate::Errors::Client::SAMConnectionError
|
183
|
+
end
|
184
|
+
JSON.parse(response.body)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module NSIVideoGranulate
|
2
|
+
class Client
|
3
|
+
class Configuration
|
4
|
+
class << self
|
5
|
+
# Set the default {NSIVideoGranulate::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 {NSIVideoGranulate::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 {NSIVideoGranulate::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 {NSIVideoGranulate::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 NSIVideoGranulate
|
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,71 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "sinatra"
|
3
|
+
require "json"
|
4
|
+
require "thread"
|
5
|
+
|
6
|
+
module NSIVideoGranulate
|
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
|
+
video_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
|
+
elsif incoming.has_key? "video_key"
|
44
|
+
return {:images => [], :files => []}.to_json
|
45
|
+
end
|
46
|
+
return 404 if incoming["key"].include? "dont"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class FakeServerManager
|
51
|
+
|
52
|
+
# Start the nsi.videogranulate fake server
|
53
|
+
#
|
54
|
+
# @param [Fixnum] port the port where the fake server will listen
|
55
|
+
# * make sure there's not anything else listenning on this port
|
56
|
+
def start_server(port=9886)
|
57
|
+
@thread = Thread.new do
|
58
|
+
Server.prepare
|
59
|
+
Server.run! :port => port
|
60
|
+
end
|
61
|
+
sleep(1)
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
# Stop the fake server
|
66
|
+
def stop_server
|
67
|
+
@thread.kill
|
68
|
+
self
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "NSIVideoGranulate::Client::Configuration" do
|
4
|
+
Configuration = NSIVideoGranulate::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,127 @@
|
|
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 NSIVideoGranulate do
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
@nsivideogranulate = NSIVideoGranulate::Client.new user: 'test', password: 'test',
|
10
|
+
host: 'localhost', port: '9886'
|
11
|
+
@fake_cloudooo = NSIVideoGranulate::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
|
+
nsivideogranulate = NSIVideoGranulate::Client.new user: 'test', password: 'test',
|
21
|
+
host: 'localhost', port: '4000'
|
22
|
+
expect { nsivideogranulate.granulate(:file => 'video', :filename => "teste.odt") }.to \
|
23
|
+
raise_error(NSIVideoGranulate::Errors::Client::ConnectionRefusedError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "simple granulation" do
|
28
|
+
it "can send a video to be granulated by a nsivideogranulate node" do
|
29
|
+
response = @nsivideogranulate.granulate(:file => 'video', :filename => 'video.ogv')
|
30
|
+
response.should_not be_nil
|
31
|
+
response["video_key"].should == "key for video video.ogv"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should throw error if any required parameter is missing" do
|
35
|
+
expect { @nsivideogranulate.granulate(:file => 'video') }.to raise_error(NSIVideoGranulate::Errors::Client::MissingParametersError)
|
36
|
+
expect { @nsivideogranulate.granulate(:cloudooo_uid => 'video') }.to raise_error(NSIVideoGranulate::Errors::Client::MissingParametersError)
|
37
|
+
expect { @nsivideogranulate.granulate(:filename => 'video') }.to raise_error(NSIVideoGranulate::Errors::Client::MissingParametersError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "granulation with conversion" do
|
42
|
+
it "can send video in a closed format to be granulated by a cloudooo node" do
|
43
|
+
response = @nsivideogranulate.granulate(:file => 'video', :filename => 'video.ogv')
|
44
|
+
response.should_not be_nil
|
45
|
+
response["video_key"].should == "key for video video.ogv"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "granulation with download" do
|
50
|
+
it "can download videos from a link to be granulated by a cloudooo node" do
|
51
|
+
response = @nsivideogranulate.granulate(:video_link => "http://video_link/video.ogv")
|
52
|
+
response.should_not be_nil
|
53
|
+
response["video_key"].should == "key for video video.ogv"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "granualtion with callback" do
|
58
|
+
it "can send a video to be granulated by a cloudooo node and specify a callback url" do
|
59
|
+
response = @nsivideogranulate.granulate(:file => 'video', :filename => 'video.ogv', :callback => 'http://google.com')
|
60
|
+
response.should_not be_nil
|
61
|
+
response["video_key"].should == "key for video video.ogv"
|
62
|
+
response["callback"].should == 'http://google.com'
|
63
|
+
end
|
64
|
+
|
65
|
+
it "can send a video to be granulated by a cloudooo node and specify the verb" do
|
66
|
+
response = @nsivideogranulate.granulate(:file => 'video', :filename => 'video.ogv', :callback => 'http://google.com', :verb => 'PUT')
|
67
|
+
response.should_not be_nil
|
68
|
+
response["video_key"].should == "key for video video.ogv"
|
69
|
+
response["callback"].should == 'http://google.com'
|
70
|
+
response["verb"].should == 'PUT'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "verify granulation" do
|
75
|
+
it "can verify is a granulation is done or not" do
|
76
|
+
key = @nsivideogranulate.granulate(:file => 'video', :filename => '2secs.odt')["video_key"]
|
77
|
+
@nsivideogranulate.done(key)["done"].should be_false
|
78
|
+
@nsivideogranulate.done(key)["done"].should be_true
|
79
|
+
@nsivideogranulate.grains_keys_for(key)["images"].should have(0).images
|
80
|
+
@nsivideogranulate.grains_keys_for(key)["files"].should have(0).files
|
81
|
+
end
|
82
|
+
|
83
|
+
it "can access the keys for all its grains" do
|
84
|
+
key = @nsivideogranulate.granulate(:file => 'video', :filename => '2secs.odt')["video_key"]
|
85
|
+
@nsivideogranulate.grains_keys_for(key)["images"].should have(0).images
|
86
|
+
@nsivideogranulate.grains_keys_for(key)["files"].should have(0).files
|
87
|
+
end
|
88
|
+
|
89
|
+
it "raises an error when trying to verify if non-existing key is done" do
|
90
|
+
expect { @nsivideogranulate.done("dont")["done"].should be_false }.to raise_error(NSIVideoGranulate::Errors::Client::KeyNotFoundError)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "raises an error when the server can't connect to the queue service" do
|
94
|
+
expect { @nsivideogranulate.granulate(:file => 'video', :filename => 'queue error' ).should be_false }.to raise_error(NSIVideoGranulate::Errors::Client::QueueServiceConnectionError)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
context "get configuration" do
|
100
|
+
before do
|
101
|
+
NSIVideoGranulate::Client.configure do
|
102
|
+
user "why"
|
103
|
+
password "chunky"
|
104
|
+
host "localhost"
|
105
|
+
port "8888"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it "by configure" do
|
110
|
+
cloudooo = NSIVideoGranulate::Client.new
|
111
|
+
cloudooo.instance_variable_get(:@user).should == "why"
|
112
|
+
cloudooo.instance_variable_get(:@password).should == "chunky"
|
113
|
+
cloudooo.instance_variable_get(:@host).should == "localhost"
|
114
|
+
cloudooo.instance_variable_get(:@port).should == "8888"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "by initialize parameters" do
|
118
|
+
cloudooo = NSIVideoGranulate::Client.new(user: 'luckystiff', password: 'bacon', host: 'why.com', port: '9999')
|
119
|
+
cloudooo.instance_variable_get(:@user).should == "luckystiff"
|
120
|
+
cloudooo.instance_variable_get(:@password).should == "bacon"
|
121
|
+
cloudooo.instance_variable_get(:@host).should == "why.com"
|
122
|
+
cloudooo.instance_variable_get(:@port).should == "9999"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
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 'nsivideogranulate'
|
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: nsivideogranulate
|
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-17 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.videogranulate 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/nsivideogranulate.rb
|
126
|
+
- lib/nsivideogranulate/client.rb
|
127
|
+
- lib/nsivideogranulate/configuration.rb
|
128
|
+
- lib/nsivideogranulate/errors.rb
|
129
|
+
- lib/nsivideogranulate/fake_server.rb
|
130
|
+
- spec/configuration_spec.rb
|
131
|
+
- spec/nsivideogranulate_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
homepage: http://github.com/nsi-iff/nsivideogranulate-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: 3685508388169519734
|
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.videogranulate node
|
161
|
+
test_files: []
|