Class: KeytechKit::ElementFileHandler
- Inherits:
-
Object
- Object
- KeytechKit::ElementFileHandler
- Includes:
- HTTParty
- Defined in:
- lib/keytechKit/elements/element_files/element_file_handler.rb
Overview
Element File handler
Instance Method Summary collapse
- #delete_masterfile(element_key) ⇒ Object
- #delete_preview(element_key) ⇒ Object
- #delete_quickpreview(element_key) ⇒ Object
-
#initialize(base_url, username, password) ⇒ ElementFileHandler
constructor
A new instance of ElementFileHandler.
-
#load(element_key) ⇒ Object
Loads the filelist Returns a full list of file data.
-
#load_masterfile(element_key) ⇒ Object
Loads the masterfile directly.
-
#masterfile?(element_key) ⇒ Boolean
Returns true or false if a masterfile exist.
-
#masterfile_info(element_key) ⇒ Object
Returns information about masterfile.
-
#masterfile_name(element_key) ⇒ Object
Returns the name of a masterfile if present.
-
#upload_masterfile(element_key, file, original_filename) ⇒ Object
Masterfile is the main file attached to a document.
-
#upload_preview(element_key, file, original_filename) ⇒ Object
The preview is a larger preview file.
-
#upload_quickpreview(element_key, file, original_filename) ⇒ Object
A Quickpreview is mostly a smaller image file.
Constructor Details
#initialize(base_url, username, password) ⇒ ElementFileHandler
Returns a new instance of ElementFileHandler.
11 12 13 14 |
# File 'lib/keytechKit/elements/element_files/element_file_handler.rb', line 11 def initialize(base_url, username, password) self.class.base_uri(base_url) @auth = { username: username, password: password } end |
Instance Method Details
#delete_masterfile(element_key) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/keytechKit/elements/element_files/element_file_handler.rb', line 119 def delete_masterfile(element_key) file_list = load(element_key) if !file_list.nil? file_list.each do |file| return delete_file(element_key, file.fileId) if file.fileStorageType.casecmp('master').zero? end end { success: true, message: 'No file found' } end |
#delete_preview(element_key) ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/keytechKit/elements/element_files/element_file_handler.rb', line 129 def delete_preview(element_key) file_list = load(element_key) if !file_list.nil? file_list.each do |file| return delete_file(element_key, file.fileId) if file.fileStorageType.casecmp('preview').zero? end end { success: true, message: 'No file found' } end |
#delete_quickpreview(element_key) ⇒ Object
139 140 141 142 143 144 145 146 147 |
# File 'lib/keytechKit/elements/element_files/element_file_handler.rb', line 139 def delete_quickpreview(element_key) file_list = load(element_key) if !file_list.nil? file_list.each do |file| return delete_file(element_key, file.fileId) if file.fileStorageType.casecmp('quickpreview').zero? end end { success: true, message: 'No file found' } end |
#load(element_key) ⇒ Object
Loads the filelist Returns a full list of file data
55 56 57 58 59 |
# File 'lib/keytechKit/elements/element_files/element_file_handler.rb', line 55 def load(element_key) parameter = { basic_auth: @auth } response = self.class.get("/elements/#{element_key}/files", parameter) parse_files(response['FileInfos']) if response.success? end |
#load_masterfile(element_key) ⇒ Object
Loads the masterfile directly
62 63 64 65 66 |
# File 'lib/keytechKit/elements/element_files/element_file_handler.rb', line 62 def load_masterfile(element_key) parameter = { basic_auth: @auth } response = self.class.get("/elements/#{element_key}/files/masterfile", parameter) return response if response.success? end |
#masterfile?(element_key) ⇒ Boolean
Returns true or false if a masterfile exist
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/keytechKit/elements/element_files/element_file_handler.rb', line 17 def masterfile?(element_key) if Tools.class_type(element_key) == 'DO' # Only DO Types can have a file file_list = load(element_key) unless file_list.nil? file_list.each do |file| return true if file.fileStorageType.casecmp('master').zero? end end end false end |
#masterfile_info(element_key) ⇒ Object
Returns information about masterfile
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/keytechKit/elements/element_files/element_file_handler.rb', line 30 def masterfile_info(element_key) if Tools.class_type(element_key) == 'DO' # Only DO Types can have a file file_list = load(element_key) unless file_list.nil? file_list.each do |file| return file if file.fileStorageType.casecmp('master').zero? end end end false end |
#masterfile_name(element_key) ⇒ Object
Returns the name of a masterfile if present
43 44 45 46 47 48 49 50 51 |
# File 'lib/keytechKit/elements/element_files/element_file_handler.rb', line 43 def masterfile_name(element_key) file_list = load(element_key) unless file_list.nil? file_list.each do |file| return file.fileName if file.fileStorageType.downcase! == 'master' end end '' end |
#upload_masterfile(element_key, file, original_filename) ⇒ Object
Masterfile is the main file attached to a document
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/keytechKit/elements/element_files/element_file_handler.rb', line 70 def upload_masterfile(element_key, file, original_filename) # file, elementkey , name?? content_length = file.size content_type = 'application/octet-stream; charset=utf-8' parameter = { basic_auth: @auth, headers: { 'Content-Type' => content_type, 'Content-Length' => content_length.to_s, 'storageType' => 'MASTER', 'filename' => original_filename.to_s }, body: file.read } upload_file element_key, parameter end |
#upload_preview(element_key, file, original_filename) ⇒ Object
The preview is a larger preview file. It must not have the same type as the masterfile, But should allow a sneak preview to its contents. e.g.: You have a large (200MB) CAD file, then der prebview may represent a 2D Drawing of the large fole. You can have more than one preview file
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/keytechKit/elements/element_files/element_file_handler.rb', line 88 def upload_preview(element_key, file, original_filename) # file, elementkey , name?? content_length = file.size content_type = 'application/octet-stream; charset=utf-8' parameter = { basic_auth: @auth, headers: { 'Content-Type' => content_type, 'Content-Length' => content_length.to_s, 'storageType' => 'PREVIEW', 'filename' => original_filename.to_s }, body: file.read } upload_file element_key, parameter end |
#upload_quickpreview(element_key, file, original_filename) ⇒ Object
A Quickpreview is mostly a smaller image file. Best is to make a image_file from the quickpreview. Respect modern retina displays - so dont be shy to upload image files of at least 800x600 pixels in size
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/keytechKit/elements/element_files/element_file_handler.rb', line 105 def upload_quickpreview(element_key, file, original_filename) # file, elementkey , name?? content_length = file.size content_type = 'application/octet-stream; charset=utf-8' parameter = { basic_auth: @auth, headers: { 'Content-Type' => content_type, 'Content-Length' => content_length.to_s, 'storageType' => 'QUICKPREVIEW', 'filename' => original_filename.to_s }, body: file.read } upload_file element_key, parameter end |