Class: Vufer::Target
- Inherits:
-
Object
- Object
- Vufer::Target
- Defined in:
- lib/vufer/target.rb
Class Method Summary collapse
-
.all ⇒ Array
List all targets associated with server access keys and cloud database.
-
.create(name, file_path, width = 50.0, active_flag = false, metadata = nil) ⇒ JSON
Creates a new target on Vuforia Web Services API.
-
.destroy(id) ⇒ JSON
Deletes a specific targets from the database.
-
.dups(id) ⇒ JSON
Review all duplicates targets from the database.
-
.find(id) ⇒ JSON
Find a specific target on Vuforia Web Services API.
-
.summary(id) ⇒ JSON
Load a summary of a specific target on the database.
-
.update(id, name = nil, file_path = nil, width = nil, active_flag = nil, metadata = nil) ⇒ JSON
Performs an update for a specific target on the database.
Class Method Details
.all ⇒ Array
List all targets associated with server access keys and cloud database.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vufer/target.rb', line 33 def all time = Time.now.httpdate signature = Vufer::Signature.generate('/targets', nil, 'GET', time) res = Faraday.get("#{Vufer::BASE_URI}/targets", {}, { Date: time, Authorization: "VWS #{Vufer.access_key}:#{signature}" }) JSON.parse(res.body) rescue StandardError => e e. end |
.create(name, file_path, width = 50.0, active_flag = false, metadata = nil) ⇒ JSON
Creates a new target on Vuforia Web Services API.
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 |
# File 'lib/vufer/target.rb', line 57 def create(name, file_path, width = 50.0, active_flag = false, = nil) time = Time.now.httpdate file_encoded = Base64.encode64(open(file_path) { |io| io.read }) = Base64.encode64(.to_s) body_hash = { name: name, width: width, image: file_encoded, active_flag: active_flag, application_metadata: } signature = Vufer::Signature.generate( '/targets', body_hash, 'POST', time ) res = Faraday.post("#{Vufer::BASE_URI}/targets", body_hash.to_json, { Date: time, Authorization: "VWS #{Vufer.access_key}:#{signature}", 'Content-Type': 'application/json', Accept: 'application/json' }) JSON.parse(res.body) rescue StandardError => e e. end |
.destroy(id) ⇒ JSON
Deletes a specific targets from the database.
Note: Targets in a processing status cannot be deleted.
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/vufer/target.rb', line 127 def destroy(id) time = Time.now.httpdate signature = Vufer::Signature.generate("/targets/#{id}", nil, 'DELETE', time) res = Faraday.delete("#{Vufer::BASE_URI}/targets/#{id}", {}, { Date: time, Authorization: "VWS #{Vufer.access_key}:#{signature}" }) JSON.parse(res.body) rescue StandardError => e e. end |
.dups(id) ⇒ JSON
Review all duplicates targets from the database.
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/vufer/target.rb', line 147 def dups(id) time = Time.now.httpdate signature = Vufer::Signature.generate("/duplicates/#{id}", nil, 'GET', time) res = Faraday.get("#{Vufer::BASE_URI}/duplicates/#{id}", {}, { Date: time, Authorization: "VWS #{Vufer.access_key}:#{signature}" }) JSON.parse(res.body) rescue StandardError => e. end |
.find(id) ⇒ JSON
Find a specific target on Vuforia Web Services API.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vufer/target.rb', line 15 def find(id) time = Time.now.httpdate signature = Vufer::Signature.generate("/targets/#{id}", nil, 'GET', time) res = Faraday.get("#{Vufer::BASE_URI}/targets/#{id}", {}, { Date: time, Authorization: "VWS #{Vufer.access_key}:#{signature}" }) JSON.parse(res.body) rescue StandardError => e e. end |
.summary(id) ⇒ JSON
Load a summary of a specific target on the database.
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/vufer/target.rb', line 167 def summary(id) time = Time.now.httpdate signature = Vufer::Signature.generate("/summary/#{id}", nil, 'GET', time) res = Faraday.get("#{Vufer::BASE_URI}/summary/#{id}", {}, { Date: time, Authorization: "VWS #{Vufer.access_key}:#{signature}" }) JSON.parse(res.body) rescue StandardError => e. end |
.update(id, name = nil, file_path = nil, width = nil, active_flag = nil, metadata = nil) ⇒ JSON
Performs an update for a specific target on the database.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/vufer/target.rb', line 94 def update(id, name = nil, file_path = nil, width = nil, active_flag = nil, = nil) time = Time.now.httpdate contents_encoded = file_path ? Base64.encode64(open(file_path) { |io| io.read }) : nil = ? Base64.encode64(.to_s) : nil body_hash = {}.merge(name ? { name: name } : {}) body_hash = body_hash.merge(width ? { width: width } : {}) body_hash = body_hash.merge(contents_encoded ? { image: contents_encoded } : {}) body_hash = body_hash.merge(!active_flag.nil? ? { active_flag: active_flag } : {}) body_hash = body_hash.merge( ? { application_metadata: } : {}) signature = Vufer::Signature.generate("/targets/#{id}", body_hash, 'PUT', time) res = Faraday.put("#{Vufer::BASE_URI}/targets/#{id}", body_hash.to_json, { Date: time, Authorization: "VWS #{Vufer.access_key}:#{signature}", 'Content-Type': 'application/json', Accept: 'application/json' }) JSON.parse(res.body) rescue StandardError => e e. end |