class Slash3D::Response

Parse a 3D Slash POST response and extract URLs to the new model

Attributes

api[R]
content[R]
nonce[R]
uid[R]

Public Class Methods

new(params) click to toggle source
# File lib/slash3d/response.rb, line 10
def initialize(params)
  @api = params[:api]
  @content = params[:content]
  @uid = params[:dslashUID]
  @nonce = params[:nonce]
end

Public Instance Methods

permanent_url() click to toggle source
# File lib/slash3d/response.rb, line 29
def permanent_url
  url = URI.parse(action_url("url"))
  Net::HTTP.get_response(url).body
end
slash3d_url() click to toggle source
# File lib/slash3d/response.rb, line 25
def slash3d_url
  action_url("3dslash")
end
stl_url() click to toggle source
# File lib/slash3d/response.rb, line 17
def stl_url
  action_url("stl")
end
thumbnail_url(width: nil, height: nil) click to toggle source
# File lib/slash3d/response.rb, line 21
def thumbnail_url(width: nil, height: nil)
  action_url("thumbnail", width: width, height: height)
end

Private Instance Methods

action_url(action, width: nil, height: nil) click to toggle source
# File lib/slash3d/response.rb, line 39
def action_url(action, width: nil, height: nil)
  params = {
    action: action,
    :alias => uid,
    nonce: nonce,
    partner: Slash3D.configuration.partner_code,
    sign: signature(action),
  }

  params[:width] = width if width
  params[:height] = height if height

  "#{api}?#{params.to_query}"
end
signature(action) click to toggle source
# File lib/slash3d/response.rb, line 54
def signature(action)
  signature_values = [
    Slash3D.configuration.api_key,
    Slash3D.configuration.partner_code,
    nonce,
    uid,
    action,
  ]

  Digest::SHA256.hexdigest(signature_values.join("|"))
end