Class: NolijWeb::Handler
- Inherits:
-
Object
- Object
- NolijWeb::Handler
- Defined in:
- lib/nolij_web/handler.rb
Constant Summary collapse
- @@doc_handler_path =
'handler/api/docs'
- @@doc_viewer_path =
''
- @@workflow_path =
'handler/api/workflow/workcomplete'
- @@api_path =
'handler/api'
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#delete_document(options = {}, &block) ⇒ Object
Delete a document required options: :document_id, :folder_id additional options: :user_code, :user_id, :wfma_code.
-
#document_metadata(options = {}, &block) ⇒ Object
Retrieve metadata for a document as a hash see #document_metadata_xml for options.
-
#document_metadata_xml(options = {}, &block) ⇒ Object
Retrieve metadata for a document as XML required options: :document_id, :folder_id additional options: :user_code, :user_id, :start, :end, :wfma_code.
-
#folder_contents(options = {}, &block) ⇒ Object
Folder contents as array Returns an array of hashes with the file info for each file in the folder See #folder_info for options.
-
#folder_info(options = {}, &block) ⇒ Object
Folder contents as Nokogiri XML required options: :folder_id additional options: :user_code, :user_id, :sort, :offset, :limit, :wfma_code.
-
#initialize(connection_config) ⇒ Handler
constructor
A new instance of Handler.
-
#login_check(options = {}) ⇒ Object
URL or path to verify that user is authenticated to Nolijweb in their browser.
-
#print_document(options = {}, &block) ⇒ Object
Print one or more documents to a single pdf required options: :document_id - can be a number or an array of numbers additional options: :user_code, :document_id, :user_id.
-
#retrieve_document_image(options = {}, &block) ⇒ Object
Return a jpeg of a page of a document required options: :document_id, :folder_id additional options: :user_code, :user_id, :rotation, :wpixels, :hpixels, :redact, :annot, :wfma_code, :page :page will default to 1 if no page is provided.
-
#submit_document(local_file, options = {}, &block) ⇒ Object
Submit a file.
-
#version(&block) ⇒ Object
Nolij Web server version information.
-
#viewer_url(options = {}) ⇒ Object
URL or path to open the standalone document viewer utility.
-
#work_complete(options = {}, &block) ⇒ Object
Issue work complete to push item along in work flow required options: :wfma_code, :folder_name additional options: :user_id, :user_code.
Constructor Details
#initialize(connection_config) ⇒ Handler
Returns a new instance of Handler.
12 13 14 15 |
# File 'lib/nolij_web/handler.rb', line 12 def initialize(connection_config) @config = connection_config @connection = Connection.new(@config) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
10 11 12 |
# File 'lib/nolij_web/handler.rb', line 10 def connection @connection end |
Instance Method Details
#delete_document(options = {}, &block) ⇒ Object
Delete a document required options: :document_id, :folder_id additional options: :user_code, :user_id, :wfma_code
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/nolij_web/handler.rb', line 125 def delete_document( = {}, &block) folder_id = [:folder_id] document_id = [:document_id] raise AttributeMissingError, 'Folder ID is required to delete a document.' unless folder_id.is_a?(String) && ! folder_id.empty? raise AttributeMissingError, 'Document ID is required to delete a document.' unless document_id.is_a?(String) && ! document_id.empty? allowed_query_params_keys = [:user_code, :user_id, :wfma_code] query_params = format_query_params(, allowed_query_params_keys) headers = [:headers] || {} relative_path = [@@doc_handler_path, 'delete', folder_id, document_id].join('/') + formatted_query @connection.delete relative_path, headers.merge(:params => query_params), &block end |
#document_metadata(options = {}, &block) ⇒ Object
Retrieve metadata for a document as a hash see #document_metadata_xml for options
159 160 161 162 163 164 165 166 167 |
# File 'lib/nolij_web/handler.rb', line 159 def ( = {}, &block) doc = (, &block) node = doc.xpath('/documentmeta').first = node.attributes.inject({}){|n, (k,v)| n[k] = v.value; n} ['pages'] = node.xpath('//pagemeta').collect{|p| p.attributes.inject({}){|n, (k,v)| n[k] = v.value; n} } return end |
#document_metadata_xml(options = {}, &block) ⇒ Object
Retrieve metadata for a document as XML required options: :document_id, :folder_id additional options: :user_code, :user_id, :start, :end, :wfma_code
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/nolij_web/handler.rb', line 142 def ( = {}, &block) folder_id = [:folder_id] document_id = [:document_id].to_i raise AttributeMissingError, 'Folder ID is required to retrieve a document.' unless folder_id.is_a?(String) && ! folder_id.empty? raise AttributeMissingError, 'Document ID is required to retrieve a document.' unless document_id > 0 allowed_query_params_keys = [:user_code, :user_id, :start, :end, :wfma_code] query_params = format_query_params(, allowed_query_params_keys) headers = [:headers] || {} relative_path = [@@doc_handler_path, folder_id, document_id, 'documentmeta'].join('/') response = @connection.get relative_path, headers.merge(:params => query_params), &block doc = Nokogiri.XML(response) end |
#folder_contents(options = {}, &block) ⇒ Object
Folder contents as array Returns an array of hashes with the file info for each file in the folder See #folder_info for options
37 38 39 40 41 42 43 44 45 |
# File 'lib/nolij_web/handler.rb', line 37 def folder_contents( = {}, &block) folder = folder_info(, &block) files = folder.xpath('//folderobjects//folderobject') file_attrs = files.collect(&:attributes) file_attrs = file_attrs.collect {|attr| attr.inject({}){|n, (k,v)| n[k] = v.value; n} } end |
#folder_info(options = {}, &block) ⇒ Object
Folder contents as Nokogiri XML required options: :folder_id additional options: :user_code, :user_id, :sort, :offset, :limit, :wfma_code
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/nolij_web/handler.rb', line 20 def folder_info( = {}, &block) folder_id = [:folder_id] raise AttributeMissingError, 'Folder ID is required.' unless folder_id.is_a?(String) && !folder_id.empty? allowed_query_params_keys = [:user_code, :user_id, :sort, :offset, :limit, :wfma_code] query_params = format_query_params(, allowed_query_params_keys) headers = [:headers] || {} relative_path = [@@doc_handler_path, [:folder_id]].join('/') response = @connection.get relative_path, headers.merge(:params => query_params), &block folder = Nokogiri.XML(response) end |
#login_check(options = {}) ⇒ Object
URL or path to verify that user is authenticated to Nolijweb in their browser. If the user is logged in redirect them to :redir path. If not, redirect to login and return them to the URL provided once they’ve authenticated. Redirect path must be relative to /public :redir is required. A path is returned unless :full_url => true
174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/nolij_web/handler.rb', line 174 def login_check( = {}) raise AttributeMissingError, 'Redirect path is required to check login' unless [:redir].is_a?(String) && ![:redir].empty? full_url = .delete(:full_url) || false allowed_query_params_keys = [:redir] formatted_query = query_str(:allowed_query_params_keys => allowed_query_params_keys , :query_params => ) relative_path = ['public', 'apiLoginCheck.jsp'].join('/') + formatted_query path = relative_path url = full_url ? [@connection.base_url, path].join('/') : path return url end |
#print_document(options = {}, &block) ⇒ Object
Print one or more documents to a single pdf required options: :document_id - can be a number or an array of numbers additional options: :user_code, :document_id, :user_id
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/nolij_web/handler.rb', line 89 def print_document( = {}, &block) doc_ids = .delete(:document_id) raise AttributeMissingError, 'At least one document ID is required to print a document.' unless doc_ids [:document_id] = [doc_ids].flatten.compact.collect(&:to_i).join('-') allowed_query_params_keys = [:user_code, :wfma_code, :user_id, :document_id] query_params = format_query_params(, allowed_query_params_keys) headers = [:headers] || {} relative_path = [@@doc_handler_path, 'print'].join('/') @connection.get relative_path, headers.merge(:params => query_params), &block end |
#retrieve_document_image(options = {}, &block) ⇒ Object
Return a jpeg of a page of a document required options: :document_id, :folder_id additional options: :user_code, :user_id, :rotation, :wpixels, :hpixels, :redact, :annot, :wfma_code, :page :page will default to 1 if no page is provided.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/nolij_web/handler.rb', line 106 def retrieve_document_image( = {}, &block) folder_id = [:folder_id] document_id = [:document_id].to_i page = [:page].to_i page = page == 0 ? 1 : page raise AttributeMissingError, 'Folder ID is required to retrieve a document.' unless folder_id.is_a?(String) && ! folder_id.empty? raise AttributeMissingError, 'Document ID is required to retrieve a document.' unless document_id > 0 allowed_query_params_keys = [:user_code, :user_id, :rotation, :wpixels, :hpixels, :redact, :annot, :wfma_code] query_params = format_query_params(, allowed_query_params_keys) headers = [:headers] || {} relative_path = [@@doc_handler_path, folder_id, document_id, 'page', page].join('/') @connection.get relative_path, headers.merge(:params => query_params), &block end |
#submit_document(local_file, options = {}, &block) ⇒ Object
Submit a file. A local file path is required. required options: :folder_id additional options: :user_code, :wfma_code, :index_code, :dept_code, :custom_name
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/nolij_web/handler.rb', line 51 def submit_document(local_file, = {}, &block) folder_id = [:folder_id] folder_id = if folder_id.kind_of?(Numeric) || folder_id.kind_of?(String) folder_id.to_s else nil end raise AttributeMissingError, 'Folder ID is required to submit a document.' unless folder_id.is_a?(String) && !folder_id.empty? local_file ||= '' file = begin File.new(local_file) rescue Errno::ENOENT end raise AttributeMissingError, 'Valid file or local filepath is required to submit a document.' unless file.is_a?(File) [:file_name] = File.basename(file.path) allowed_query_params_keys = [:user_code, :wfma_code, :index_code, :dept_code, :custom_name, :file_name] formatted_query = query_str(:allowed_query_params_keys => allowed_query_params_keys , :query_params => ) relative_path = [@@doc_handler_path, folder_id].join('/') + formatted_query # TODO custom attributes? form_params = {} form_params[:ocrwords] = [:ocr_words] if .has_key?(:oci_words) form_params[:my_file] = file #upload file to nolijweb response = @connection.post relative_path, form_params, ([:headers] || {}), &block # return Nolij file id = Nokogiri.XML(response) document_id = .xpath('//documentmeta/@documentid').first return document_id.value if document_id end |
#version(&block) ⇒ Object
Nolij Web server version information
221 222 223 224 225 226 227 228 229 |
# File 'lib/nolij_web/handler.rb', line 221 def version(&block) relative_path = [@@api_path, 'version'].join('/') response = @connection.get relative_path, &block info = Nokogiri.XML(response).xpath('//version').collect(&:attributes) info= info.collect {|attr| attr.inject({}){|n, (k,v)| n[k] = v.value; n} }.first end |
#viewer_url(options = {}) ⇒ Object
URL or path to open the standalone document viewer utility. required options: :document_id is required additional options: :user_code, :wfma_code use option :full_url => true for a full url, otherwise a relative path is returned.
191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/nolij_web/handler.rb', line 191 def viewer_url( = {}) raise AttributeMissingError, 'Document ID is required to launch viewer' unless ([:document_id].is_a?(String) && ![:document_id].empty?) || [:document_id].is_a?(Integer) full_url = .delete(:full_url) || false url_opts = {} allowed_query_params_keys = [:document_id, :user_code, :wfma_code] formatted_query = query_str(:allowed_query_params_keys => allowed_query_params_keys , :query_params => ) relative_path = [@@doc_viewer_path, 'documentviewer'].join('/') + formatted_query path = relative_path url = full_url ? [@connection.base_url, path].join('/') : path return url end |
#work_complete(options = {}, &block) ⇒ Object
Issue work complete to push item along in work flow required options: :wfma_code, :folder_name additional options: :user_id, :user_code
206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/nolij_web/handler.rb', line 206 def work_complete( = {}, &block) raise AttributeMissingError, 'Workflow master code is required for workflow requests.' unless [:wfma_code] folder_id = [:folder_id] raise AttributeMissingError, 'Folder ID is required.' unless folder_id raise AttributeMissingError, 'Folder name is required.' unless [:folder_name] allowed_query_params_keys = [:wfma_code, :user_id, :user_code, :folder_name] formatted_query = query_str(:allowed_query_params_keys => allowed_query_params_keys , :query_params => ) relative_path = [@@workflow_path, folder_id, formatted_query].join('/') @connection.post relative_path, {}, [:headers] || {}, &block end |