Class: NSIVideoGranulate::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/nsivideogranulate/client.rb,
lib/nsivideogranulate/configuration.rb

Defined Under Namespace

Classes: Configuration

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Client

Note:

if you had used the ‘configure’ method, you can use it without parameters and those you provided before will be used (see Client#configure)

Initialize a client to a VideoGranulate node

Examples:

videogranulate = NSIVideoGranulate::Client.new host: 'localhost', port: '8886', user: 'test', password: 'test'

Parameters:

  • options (Hash)

    used to connect to the VideoGranulate node



23
24
25
26
27
28
29
# File 'lib/nsivideogranulate/client.rb', line 23

def initialize(params = {})
  params = Configuration.settings.merge(params)
  @user = params[:user]
  @password = params[:password]
  @host = params[:host]
  @port = params[:port]
end

Class Method Details

.configure { ... } ⇒ Object

Pre-configure the NSIVideoGranulate module with default params for the NSIVideoGranulate::Client

Examples:

NSIVideoGranulate::Client.configure do
  user     "why"
  password "chunky"
  host     "localhost"
  port     "8888"
end

Yields:



160
161
162
# File 'lib/nsivideogranulate/client.rb', line 160

def self.configure(&block)
  Configuration.instance_eval(&block)
end

Instance Method Details

#audio_key_for(video_key) ⇒ Object



139
140
141
142
# File 'lib/nsivideogranulate/client.rb', line 139

def audio_key_for(video_key)
  request = prepare_request :GET, {:video_key => video_key, :grains => true}.to_json
  execute_request(request).select { |key| 'audio' == key }
end

#converted_video_key_for(video_key) ⇒ Object



144
145
146
147
# File 'lib/nsivideogranulate/client.rb', line 144

def converted_video_key_for(video_key)
  request = prepare_request :GET, {:video_key => video_key, :grains => true}.to_json
  execute_request(request).select { |key| 'converted_video' == key }
end

#done(key) ⇒ Hash

Verify if a video is already granulated

Examples:

nsivideogranulate.done("some key")

Parameters:

  • key (String)

    of the desired video

Returns:

  • (Hash)

    response

    • “done” [String] true if the video was already granualted, otherwise, false

Raises:

  • NSIVideoGranulate::Errors::Client::SAMConnectionError when cannot connect to the SAM node

  • NSIVideoGranulate::Errors::Client::AuthenticationError when invalids user and/or password are provided

  • NSIVideoGranulate::Errors::Client::KeyNotFoundError when an invalid key is provided



109
110
111
112
# File 'lib/nsivideogranulate/client.rb', line 109

def done(key)
  request = prepare_request :GET, {:key => key}.to_json
  execute_request(request)
end

#grains_keys_for(video_key) ⇒ Hash

Return the keys of the grains of a video

Examples:

nsivideogranulate.grains_keys_for("some key")

Parameters:

  • key (String)

    of the desired video

Returns:

  • (Hash)

    response

    • “images” [String] keys to the images grains of the video

    • “files” [String] keys to the files grains of the video

Raises:

  • NSIVideoGranulate::Errors::Client::SAMConnectionError when cannot connect to the SAM node

  • NSIVideoGranulate::Errors::Client::AuthenticationError when invalids user and/or password are provided

  • NSIVideoGranulate::Errors::Client::KeyNotFoundError when an invalid key is provided



129
130
131
132
# File 'lib/nsivideogranulate/client.rb', line 129

def grains_keys_for(video_key)
  request = prepare_request :GET, {:video_key => video_key, :grains => true}.to_json
  execute_request(request).select { |key| ['images', 'videos'].include? key }
end

#granulate(options = {}) ⇒ Hash

Note:

the filename is very importante, the videogranulate node will use the proper coding/encoding option for the video type

Note:

if provided both video_link and file options, file will be ignored and the client will download the video instead

Send a video be granulated by a nsi.videogranulate node

Examples:

A simple granulation

require 'base64'
video = Base64.encode64(File.new('video.ogv', 'r').read)
response = nsivideogranulate.granulate(:file => video, :filename => 'video.ogv')
nsivideogranulate.done(response["video_key"])
nsivideogranulate.grains_keys_for(response["video_key"])

Granulating from a SAM uid

video = Base64.encode64(File.new('video.ogv', 'r').read)
response = sam.store({:doc => doc})
video_key = response["key"]
response = nsivideogranulate.granulate(:sam_uid => video_key, :filename => 'video.ogv')
nsivideogranulate.done(response["video_key"])
nsivideogranulate.grains_keys_for(response["video_key"])

Downloading and granulating from web

response = nsivideogranulate.granulate(:video_link => 'http://google.com/video.ogv')
nsivideogranulate.done(response["video_key"])
nsivideogranulate.grains_keys_for(response["video_key"])

Sending a callback url

video = Base64.encode64(File.new('video.ogv', 'r').read)
nsivideogranulate.granulate(:file => video, :filename => 'video.ogv', :callback => 'http://google.com')
nsivideogranulate.granulate(:video_link => 'http://google.com/video.ogv', :callback => 'http://google.com')

Using a custom verb to the callback

video = Base64.encode64(File.new('video.ogv', 'r').read)
nsivideogranulate.granulate(:file => video, :filename => 'video.ogv', :callback => 'http://google.com', :verb => "PUT")
nsivideogranulate.granulate(:video_link => 'http://google.com/video.ogv', :callback => 'http://google.com', :verb => "PUT")

Parameters:

  • options (Hash) (defaults to: {})

    used to send a video to be graulated

Options Hash (options):

  • file (String)

    the base64 encoded file to be granulated

  • sam_uid (String)

    the UID of a video at SAM

  • filename (String)

    the filename of the video

  • video_link (String)

    link to the video that’ll be granulated

  • callback (String)

    a callback url to the file granulation

  • verb (String)

    the callback request verb, when not provided, nsi.videogranulate defaults to POST

Returns:

  • (Hash)

    response

    • “video_key” [String] the key to access the granulated video in the sam node it was stored

Raises:

  • NSIVideoGranulate::Errors::Client::MissingParametersError when an invalid or incomplete set of parameters is provided

  • NSIVideoGranulate::Errors::Client::SAMConnectionError when cannot connect to the SAM node

  • NSIVideoGranulate::Errors::Client::AuthenticationError when invalids user and/or password are provided

  • NSIVideoGranulate::Errors::Client::KeyNotFoundError when an invalid sam_uid is provided



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/nsivideogranulate/client.rb', line 77

def granulate(options = {})
  @request_data = Hash.new
  if options[:video_link]
    insert_download_data options
  elsif options[:sam_uid] && options[:filename]
    file_data = {:video_uid => options[:sam_uid], :filename => options[:filename]}
    @request_data.merge! file_data
  elsif options[:file] && options[:filename]
    file_data = {:video => options[:file], :filename => options[:filename]}
    @request_data.merge! file_data
  else
    raise NSIVideoGranulate::Errors::Client::MissingParametersError
  end
  insert_callback_data options
  request = prepare_request :POST, @request_data.to_json
  execute_request(request)
end

#thumbnails_keys_for(video_key) ⇒ Object



134
135
136
137
# File 'lib/nsivideogranulate/client.rb', line 134

def thumbnails_keys_for(video_key)
  request = prepare_request :GET, {:video_key => video_key, :grains => true}.to_json
  execute_request(request).select { |key| 'thumbnails' == key }
end