Class: KeytechKit::ElementHandler
- Inherits:
-
Object
- Object
- KeytechKit::ElementHandler
- Includes:
- HTTParty
- Defined in:
- lib/keytechKit/elements/element_handler.rb
Overview
All operations for a element is here
Instance Attribute Summary collapse
-
#keytechkit ⇒ Object
Returns the value of attribute keytechkit.
Instance Method Summary collapse
-
#billOfMaterial(element_key, options = {}) ⇒ Object
Loads the bill of meterial on articles
options
can have these values: size, page, attribute = ALL|NONE|GLOBALLISTER|SECONDARY|EXPLORER Returns a list of elements It returns nil if no element with this elementKey was found. -
#delete(element_key) ⇒ Object
Deletes an element with the key It returns the http response.
-
#file_handler ⇒ Object
Returns the file object.
-
#initialize(keytechkit, base_url, username, password) ⇒ ElementHandler
constructor
A new instance of ElementHandler.
-
#load(element_key, options = {}) ⇒ Object
Find an existing element with
elementkey
in form of classkey:<nummeric> e.g.: MISC_FILE:1234options
is one of attributes=ALL|NONE|EDITOR It returns nil if no element with this elementKey was found. -
#mails(element_key, options = {}) ⇒ Object
Loads the list of mails on folders,
options
can have these values: size, page, attribute = ALL|NONE|GLOBALLISTER|SECONDARY|EXPLORER Returns a list of elements It returns nil if no element with this elementKey was found. -
#new_element(key) ⇒ Object
It returns a element prototype with the given elementKey you can check valid elementkeys with the classdefinition.
-
#note_handler ⇒ Object
Returns Notes resource.
-
#notes(element_key) ⇒ Object
It returns the notes of an element if anything are given Notes list can be empty It returns nil if no element with this elementKey was found.
-
#preview(element_key) ⇒ Object
Loads the preview image.
-
#save(element) ⇒ Object
Saves a element to keytech web api and returns the saved element.
-
#structure(element_key, options = {}) ⇒ Object
Loads the structure
options
can have these values: size, page, attribute = ALL|NONE|GLOBALLISTER|SECONDARY|EXPLORER Returns a list of elements It returns nil if no element with this elementKey was found. -
#thumbnail(element_key) ⇒ Object
Loads a small thumbnail.
-
#update(element) ⇒ Object
Saves a element to keytech web api and returns the saved element.
-
#whereused(element_key, options = {}) ⇒ Object
Loads the parent elements
options
can have these values: size, page, attribute = ALL|NONE|GLOBALLISTER|SECONDARY|EXPLORER Returns a list of elements It returns nil if no element with this elementKey was found.
Constructor Details
#initialize(keytechkit, base_url, username, password) ⇒ ElementHandler
Returns a new instance of ElementHandler.
14 15 16 17 18 |
# File 'lib/keytechKit/elements/element_handler.rb', line 14 def initialize(keytechkit, base_url, username, password) self.class.base_uri(base_url) @auth = { username: username, password: password } @keytechkit = keytechkit end |
Instance Attribute Details
#keytechkit ⇒ Object
Returns the value of attribute keytechkit.
12 13 14 |
# File 'lib/keytechKit/elements/element_handler.rb', line 12 def keytechkit @keytechkit end |
Instance Method Details
#billOfMaterial(element_key, options = {}) ⇒ Object
Loads the bill of meterial on articles options
can have these values: size, page, attribute = ALL|NONE|GLOBALLISTER|SECONDARY|EXPLORER Returns a list of elements It returns nil if no element with this elementKey was found
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/keytechKit/elements/element_handler.rb', line 118 def billOfMaterial(element_key, = {}) parameter = { query: } parameter[:basic_auth] = @auth response = self.class.get("/elements/#{element_key}/bom", parameter) if response.success? bom_list = BomElementList.new(response) return bom_list.bomElementList end end |
#delete(element_key) ⇒ Object
Deletes an element with the key It returns the http response.
76 77 78 79 80 81 82 83 |
# File 'lib/keytechKit/elements/element_handler.rb', line 76 def delete(element_key) parameter = { basic_auth: @auth } response = self.class.delete("/elements/#{element_key}", parameter) unless response.success? puts "Could not save element: #{response.headers['x-errordescription']}" end response end |
#file_handler ⇒ Object
Returns the file object. Every element can have a Masterfile and one or more preview files
164 165 166 167 |
# File 'lib/keytechKit/elements/element_handler.rb', line 164 def file_handler @_element_file_handler = ElementFileHandler.new(keytechkit.base_url, keytechkit.username, keytechkit.password) if @_element_file_handler.nil? @_element_file_handler end |
#load(element_key, options = {}) ⇒ Object
Find an existing element with elementkey
in form of classkey:<nummeric> e.g.: MISC_FILE:1234 options
is one of attributes=ALL|NONE|EDITOR It returns nil if no element with this elementKey was found
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/keytechKit/elements/element_handler.rb', line 25 def load(element_key, = {}) parameter = { query: } parameter[:basic_auth] = @auth response = self.class.get("/elements/#{element_key}", parameter) if response.success? searchResponseHeader = SearchResponseHeader.new(response) searchResponseHeader.elementList.first # TODO: Can we do better if element was not found? end end |
#mails(element_key, options = {}) ⇒ Object
Loads the list of mails on folders, options
can have these values: size, page, attribute = ALL|NONE|GLOBALLISTER|SECONDARY|EXPLORER Returns a list of elements It returns nil if no element with this elementKey was found
133 134 135 136 137 138 139 |
# File 'lib/keytechKit/elements/element_handler.rb', line 133 def mails(element_key, = {}) parameter = { query: } parameter[:basic_auth] = @auth response = self.class.get("/elements/#{element_key}/mails", parameter) return response['ElementList'] if response.success? end |
#new_element(key) ⇒ Object
It returns a element prototype with the given elementKey you can check valid elementkeys with the classdefinition
40 41 42 |
# File 'lib/keytechKit/elements/element_handler.rb', line 40 def new_element(key) Element.new('Key' => key) end |
#note_handler ⇒ Object
Returns Notes resource. Every Element can have zero, one or more notes. You can notes only access in context of its element which ownes the notes
157 158 159 160 |
# File 'lib/keytechKit/elements/element_handler.rb', line 157 def note_handler @_note_handler = NoteHandler.new(keytechkit.base_url, keytechkit.username, keytechkit.password) if @_note_handler.nil? @_note_handler end |
#notes(element_key) ⇒ Object
It returns the notes of an element if anything are given Notes list can be empty It returns nil if no element with this elementKey was found
144 145 146 147 148 149 150 151 152 |
# File 'lib/keytechKit/elements/element_handler.rb', line 144 def notes(element_key) parameter = { basic_auth: @auth } response = self.class.get("/elements/#{element_key}/notes", parameter) if response.success? search_response_header = SearchResponseHeader.new(response) search_response_header.elementList end end |
#preview(element_key) ⇒ Object
Loads the preview image. This is a size limited image version of the files content. Text documents often show the first Page. Make no assumtions about the image size
172 173 174 175 |
# File 'lib/keytechKit/elements/element_handler.rb', line 172 def preview(element_key) parameter = { basic_auth: @auth } self.class.get("/elements/#{element_key}/preview", parameter) end |
#save(element) ⇒ Object
Saves a element to keytech web api and returns the saved element. If anything goes wrong - a http response is returned
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/keytechKit/elements/element_handler.rb', line 46 def save(element) elementHash = element.to_hash parameter = { basic_auth: @auth, body: elementHash.to_json, headers: { 'Content-Type' => 'application/json; charset=utf-8 ' } } save_response = self.class.post('/elements', parameter) if save_response.success? Element.new(save_response.parsed_response) else puts "Could not save element: #{save_response.headers['x-errordescription']}" end end |
#structure(element_key, options = {}) ⇒ Object
Loads the structure options
can have these values: size, page, attribute = ALL|NONE|GLOBALLISTER|SECONDARY|EXPLORER Returns a list of elements It returns nil if no element with this elementKey was found
89 90 91 92 93 94 95 96 97 |
# File 'lib/keytechKit/elements/element_handler.rb', line 89 def structure(element_key, = {}) parameter = { query: } parameter[:basic_auth] = @auth response = self.class.get("/elements/#{element_key}/structure", parameter) if response.success? searchResponseHeader = SearchResponseHeader.new(response) return searchResponseHeader.elementList end end |
#thumbnail(element_key) ⇒ Object
Loads a small thumbnail. Thumbnails are like file type icons. They normaly show the type of a document, not its content
179 180 181 182 |
# File 'lib/keytechKit/elements/element_handler.rb', line 179 def thumbnail(element_key) parameter = { basic_auth: @auth } self.class.get("/elements/#{element_key}/thumbnail", parameter) end |
#update(element) ⇒ Object
Saves a element to keytech web api and returns the saved element. If anything goes wrong - a http response is returned
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/keytechKit/elements/element_handler.rb', line 61 def update(element) elementHash = element.to_hash parameter = { basic_auth: @auth, body: elementHash.to_json, headers: { 'Content-Type' => 'application/json; charset=utf-8 ' } } save_response = self.class.put("/elements/#{element.key}", parameter) if save_response.success? Element.new(save_response.parsed_response) else puts "Could not save element: #{save_response.headers['x-errordescription']}" end end |
#whereused(element_key, options = {}) ⇒ Object
Loads the parent elements options
can have these values: size, page, attribute = ALL|NONE|GLOBALLISTER|SECONDARY|EXPLORER Returns a list of elements It returns nil if no element with this elementKey was found
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/keytechKit/elements/element_handler.rb', line 103 def whereused(element_key, = {}) parameter = { query: } parameter[:basic_auth] = @auth response = self.class.get("/elements/#{element_key}/whereused", parameter) if response.success? searchResponseHeader = SearchResponseHeader.new(response) return searchResponseHeader.elementList end end |