Module: Authentise::API::Warehouse
- Defined in:
- lib/authentise/api/warehouse.rb
Overview
Upload models and take snapshot pictures
Class Method Summary collapse
-
.create_model(session_token: nil, name: nil) ⇒ Object
Params: - cookie.
-
.create_snapshot(arguments = {}) ⇒ Object
Create a model snapshot.
-
.get_model(url: nil, uuid: nil, session_token: nil) ⇒ Object
Get information about a model from its URL or UUID.
-
.get_snapshot(url: nil, session_token: nil) ⇒ Object
Get information about a snapshot from its URL.
-
.parse_snapshot(response) ⇒ Object
rubocop:disable Metrics/AbcSize.
- .put_file(url: nil, path: nil) ⇒ Object
Class Method Details
.create_model(session_token: nil, name: nil) ⇒ Object
Params:
-
cookie
-
name (string) – Required. The name of the model. This can be any string and should be meaningful to the user
-
allowed_transformations (hash) – Optional. The transformations that are allowed on this model.
-
resize (boolean) – Optional. true if this model is allowed to be resized automatically by other services. Default: false.
-
rotation (boolean) – Optional. true if this model is allowed to be rotated automatically by other services. Default: false.
-
-
callback (hash) – Optional. The URL to call when this model changes states.
-
url (string) – Optional. The URL to request for the callback
-
method (string) – Optional. The method to use for the request, one of GET, POST or PUT.
-
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/authentise/api/warehouse.rb', line 30 def create_model(session_token: nil, name: nil) url = "https://models.authentise.com/model/" body = { name: name, }.to_json = { content_type: :json, accept: :json, cookies: { session: session_token }, open_timeout: 2, timeout: 2, } RestClient.post(url, body, ) do |response, _request, _result| if response.code == 201 { model_url: response.headers[:location], upload_url: response.headers[:x_upload_location], } else fail UnknownResponseCodeError.new(response.code, response) end end end |
.create_snapshot(arguments = {}) ⇒ Object
Create a model snapshot.
Required arguments:
-
session_token: for authentication.
-
model_uuid: which model to create a snapshot for.
Optional arguments:
-
samples (int) – The number of samples to use in requesting the
snapshot. Min 0, Max 5000. Higher numbers will take konger but yield better-looking results
-
layer (int) – The number of the layer of the model to show. This
allows you to visualize the model when partially printed
-
color (string) – The color, in HTML color codes, to use for the
material the model is made of. Ex: #AFAA75
-
height (int) – The height of the image in pixels. Min 0, Max 768
-
width (int) – The width oft he image in pixels. Min 0, Max 1024
-
x (float) – The position of the camera on the X axis
-
y (float) – The position of the camera on the Y axis
-
z (float) – The position of the camera on the Z axis
-
u (float) – The camera direction vector’s X component
-
v (float) – The camera direction vector’s Y component
-
w (float) – The camera direction vector’s Z component
-
callback (hash):
-
url (string) – The url to callback to once model processing is
finished.
-
method (string) – The http method for the callback to use when
calling back.
-
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/authentise/api/warehouse.rb', line 161 def create_snapshot(arguments = {}) params = arguments.dup session_token = params.delete(:session_token) model_uuid = params.delete(:model_uuid) url = "https://models.authentise.com/model/#{model_uuid}/snapshot/" body = params.to_json headers = { content_type: :json, accept: :json, cookies: { session: session_token }, open_timeout: 2, timeout: 2, } RestClient.post(url, body, headers) do |response, _request, _result| if response.code == 201 { url: response.headers[:location], } else fail UnknownResponseCodeError.new(response.code, response) end end end |
.get_model(url: nil, uuid: nil, session_token: nil) ⇒ Object
Get information about a model from its URL or UUID.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/authentise/api/warehouse.rb', line 72 def get_model(url: nil, uuid: nil, session_token: nil) url ||= "https://models.authentise.com/model/#{uuid}/" headers = { content_type: :json, accept: :json, cookies: { session: session_token }, open_timeout: 2, timeout: 2, } RestClient.get(url, headers) do |response, _request, _result| if response.code == 200 parse_model(response, url) elsif response.code == 404 fail NotFoundError else fail UnknownResponseCodeError.new(response.code, response) end end end |
.get_snapshot(url: nil, session_token: nil) ⇒ Object
Get information about a snapshot from its URL.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/authentise/api/warehouse.rb', line 188 def get_snapshot(url: nil, session_token: nil) headers = { content_type: :json, accept: :json, cookies: { session: session_token }, open_timeout: 2, timeout: 2, } RestClient.get(url, headers) do |response, _request, _result| if response.code == 200 parse_snapshot(response) elsif response.code == 404 fail NotFoundError else fail UnknownResponseCodeError.new(response.code, response) end end end |
.parse_snapshot(response) ⇒ Object
rubocop:disable Metrics/AbcSize
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/authentise/api/warehouse.rb', line 241 def parse_snapshot(response) data = JSON.parse(response) { status: "snapshot_rendering", samples: data["samples"], layer: data["layer"], color: data["color"], height: data["height"], width: data["width"], x: data["x"], y: data["y"], z: data["z"], u: data["u"], v: data["v"], w: data["w"], slice_height: data["slice_height"], created_at: parse_time(data["created"]), content_url: data["content"], } end |
.put_file(url: nil, path: nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/authentise/api/warehouse.rb', line 55 def put_file(url: nil, path: nil) file = File.read(path) = { content_type: 'application/octet-stream', open_timeout: 2, timeout: 2, } RestClient.put(url, file, ) do |response, _request, _result| if response.code == 200 || response.code == 204 true else fail UnknownResponseCodeError.new(response.code, response) end end end |