Class: Vufer::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/vufer/target.rb

Class Method Summary collapse

Class Method Details

.allArray

List all targets associated with server access keys and cloud database.

Returns:

  • (Array)

    A list of target ids associated with the account



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.message
end

.create(name, file_path, width = 50.0, active_flag = false, metadata = nil) ⇒ JSON

Creates a new target on Vuforia Web Services API.

Parameters:

  • Name (String)

    The name of the image to create

  • FileURL (String)

    Contains the base64 encoded binary recognition image data

  • Width (Fixnum)

    Width of the target in scene unit

  • ActiveFlag (Boolean)

    Indicates whether or not the target is active for query, default: false

  • Metadata (Hash)

    The base64 encoded application metadata associated with the target

Returns:

  • (JSON)

    A newly target id from Vuforia.



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.message
end

.destroy(id) ⇒ JSON

Deletes a specific targets from the database.

Note: Targets in a processing status cannot be deleted.

Parameters:

  • ID (String)

    The ID(identifier) of the target on the database.

Returns:

  • (JSON)

    The result code and transaction id indicating the update was ok.



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.message
end

.dups(id) ⇒ JSON

Review all duplicates targets from the database.

Parameters:

  • ID (String)

    The identifier of the target on database.

Returns:

  • (JSON)

    An Array of ids of similar targets



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.message
end

.find(id) ⇒ JSON

Find a specific target on Vuforia Web Services API.

Parameters:

  • ID (String)

    The identifier that exists on Vuforia.

Returns:

  • (JSON)

    the object parsed in JSON from Vuforia.



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.message
end

.summary(id) ⇒ JSON

Load a summary of a specific target on the database.

Parameters:

  • ID (String)

    The identifier of the target on database.

Returns:

  • (JSON)

    All the info about database and target.



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.message
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.

Parameters:

  • ID (String)

    The ID(identifier) of the target on Vuforia.

  • Name (String)

    The name of the image to create

  • FileURL (String)

    Contains the base64 encoded binary recognition image data

  • Width (Fixnum)

    Width of the target in scene unit

  • ActiveFlag (Boolean)

    Indicates whether or not the target is active for query

  • Metadata (Hash)

    The base64 encoded application metadata associated with the target

Returns:

  • (JSON)

    A info showing success that the target was updated.



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.message
end