Class: NSICloudooo::Client
- Inherits:
-
Object
- Object
- NSICloudooo::Client
- Defined in:
- lib/nsicloudooo/client.rb,
lib/nsicloudooo/configuration.rb
Defined Under Namespace
Classes: Configuration
Class Method Summary collapse
-
.configure { ... } ⇒ Object
Pre-configure the NSICloudooo module with default params for the NSICloudooo::Client.
Instance Method Summary collapse
-
#done(key) ⇒ Hash
Verify if a document is already granulated.
-
#extract_metadata(document_key, type, callback_url = nil, callback_verb = nil) ⇒ Hash
Enqueue a document to have its metadata extracted.
-
#grains_keys_for(document_key) ⇒ Hash
Return the keys of the grains of a document.
-
#granulate(options = {}) ⇒ Hash
Send a document be granulated by a nsi.cloudooo node.
-
#initialize(params = {}) ⇒ Client
constructor
Initialize a client to a CloudoooManager node.
-
#metadata_key_for(document_key) ⇒ String
Return the key of the metadata of a document.
-
#thumbnail_key_for(document_key) ⇒ String
Return the key of the thumbnail of a document.
Constructor Details
#initialize(params = {}) ⇒ Client
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 CloudoooManager node
23 24 25 26 27 28 29 |
# File 'lib/nsicloudooo/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 NSICloudooo module with default params for the NSICloudooo::Client
202 203 204 |
# File 'lib/nsicloudooo/client.rb', line 202 def self.configure(&block) Configuration.instance_eval(&block) end |
Instance Method Details
#done(key) ⇒ Hash
Verify if a document is already granulated
109 110 111 112 |
# File 'lib/nsicloudooo/client.rb', line 109 def done(key) request = prepare_request :GET, {:key => key}.to_json execute_request(request) end |
#extract_metadata(document_key, type, callback_url = nil, callback_verb = nil) ⇒ Hash
Enqueue a document to have its metadata extracted
166 167 168 169 170 171 |
# File 'lib/nsicloudooo/client.rb', line 166 def (document_key, type, callback_url=nil, callback_verb=nil) @request_data = {:sam_uid => document_key, :type => type, :metadata => true} insert_callback_data :callback => callback_url, :verb => callback_verb request = prepare_request :POST, @request_data.to_json execute_request(request) end |
#grains_keys_for(document_key) ⇒ Hash
Return the keys of the grains of a document
129 130 131 132 |
# File 'lib/nsicloudooo/client.rb', line 129 def grains_keys_for(document_key) request = prepare_request :GET, {:doc_key => document_key}.to_json execute_request(request).select {|chave| ['images', 'files'].include? chave} end |
#granulate(options = {}) ⇒ Hash
the filename is very importante, the cloudooo node will convert the document based on its filename, if necessary
if provided both doc_link and file options, file will be ignored and the client will download the document instead
Send a document be granulated by a nsi.cloudooo node
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/nsicloudooo/client.rb', line 77 def granulate( = {}) @request_data = Hash.new if [:doc_link] insert_download_data elsif [:sam_uid] && [:filename] file_data = {:sam_uid => [:sam_uid], :filename => [:filename]} @request_data.merge! file_data elsif [:file] && [:filename] file_data = {:doc => [:file], :filename => [:filename]} @request_data.merge! file_data else raise NSICloudooo::Errors::Client::MissingParametersError end insert_callback_data request = prepare_request :POST, @request_data.to_json execute_request(request) end |
#metadata_key_for(document_key) ⇒ String
Return the key of the metadata of a document
186 187 188 189 |
# File 'lib/nsicloudooo/client.rb', line 186 def (document_key) request = prepare_request :GET, {:doc_key => document_key, :metadata => true}.to_json execute_request(request)["metadata_key"] end |
#thumbnail_key_for(document_key) ⇒ String
Return the key of the thumbnail of a document
147 148 149 150 |
# File 'lib/nsicloudooo/client.rb', line 147 def thumbnail_key_for(document_key) request = prepare_request :GET, {:doc_key => document_key}.to_json execute_request(request)["thumbnail"] end |