Method: Vufer::Target.create
- Defined in:
- lib/vufer/target.rb
.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 |