Class: Aaww::Transaction

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
ActiveModel::Model
Defined in:
lib/aaww/transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#emailObject

Returns the value of attribute email.



6
7
8
# File 'lib/aaww/transaction.rb', line 6

def email
  @email
end

#fileObject

Returns the value of attribute file.



6
7
8
# File 'lib/aaww/transaction.rb', line 6

def file
  @file
end

#job_idObject

Returns the value of attribute job_id.



6
7
8
# File 'lib/aaww/transaction.rb', line 6

def job_id
  @job_id
end

#keyObject

Returns the value of attribute key.



6
7
8
# File 'lib/aaww/transaction.rb', line 6

def key
  @key
end

Returns the value of attribute link.



6
7
8
# File 'lib/aaww/transaction.rb', line 6

def link
  @link
end

#progressObject

Returns the value of attribute progress.



6
7
8
# File 'lib/aaww/transaction.rb', line 6

def progress
  @progress
end

Returns the value of attribute ssl_link.



6
7
8
# File 'lib/aaww/transaction.rb', line 6

def ssl_link
  @ssl_link
end

#statusObject

Returns the value of attribute status.



6
7
8
# File 'lib/aaww/transaction.rb', line 6

def status
  @status
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/aaww/transaction.rb', line 6

def token
  @token
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/aaww/transaction.rb', line 6

def value
  @value
end

Instance Method Details

#check_print_status!Object

Returns a detailed print status for a specific token Returns Print Status GET /api3/api_get_partner_print_status?api_key=#key&token=#token“ TODO enforce 15 seconds API restriction



56
57
58
59
60
61
62
63
# File 'lib/aaww/transaction.rb', line 56

def check_print_status!
  if token
    response = Aaww.get '/api3/api_get_partner_print_status', query: { api_key: key, token: token }
    self.status = Status.new response['status']
    self.progress = Progress.new response['data']
    response
  end
end

#create_tokenObject

Creates a single unique token for this transaction Returns Token GET /api3/api_create_partner_token?api_key=#key



14
15
16
17
18
19
# File 'lib/aaww/transaction.rb', line 14

def create_token
  response = Aaww.get '/api3/api_create_partner_token', query: { api_key: key }
  self.status = Status.new response['status']
  self.token = response['data']['token']
  response
end

#upload(file, email, value, job_id = nil) ⇒ Object

Uploads a 3D object associated with a specific token and purchase order information Returns token_link and ssl_token_link POST /api3/api_upload_partner_stl?api_key=#key&receiver_email=#email&print_value=#value&token=&partner_job_id=#job_id



24
25
26
27
28
29
30
31
# File 'lib/aaww/transaction.rb', line 24

def upload(file, email, value, job_id = nil)
  self.file = file
  self.email = email
  self.value = value
  self.job_id = job_id unless job_id.nil?

  upload!
end

#upload!Object



33
34
35
36
37
38
39
40
41
# File 'lib/aaww/transaction.rb', line 33

def upload!
  create_token if token.nil?

  response = Aaww.post '/api3/api_upload_partner_stl', query: upload_query
  self.status = Status.new response['status']
  self.link = response['data']['token_link']
  self.ssl_link = response['data']['ssl_token_link']
  response
end

#upload_queryObject



43
44
45
46
47
48
49
50
# File 'lib/aaww/transaction.rb', line 43

def upload_query
  { api_key: key,
    receiver_email: email,
    print_value: value,
    token: token,
    partner_job_id: job_id,
    stl_file: file }.reject { |_, value| value.nil? }
end