Class: Aaww::Transaction

Inherits:
Object
  • Object
show all
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.



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

def email
  @email
end

#fileObject

Returns the value of attribute file.



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

def file
  @file
end

#job_idObject

Returns the value of attribute job_id.



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

def job_id
  @job_id
end

#keyObject

Returns the value of attribute key.



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

def key
  @key
end

Returns the value of attribute link.



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

def link
  @link
end

Returns the value of attribute ssl_link.



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

def ssl_link
  @ssl_link
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#create_tokenObject

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



10
11
12
13
14
# File 'lib/aaww/transaction.rb', line 10

def create_token
  response = Aaww.get '/api3/api_create_partner_token', query: { api_key: key }
  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



19
20
21
22
23
24
25
26
# File 'lib/aaww/transaction.rb', line 19

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



28
29
30
31
32
33
34
35
# File 'lib/aaww/transaction.rb', line 28

def upload!
  create_token if token.nil?

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

#upload_queryObject



37
38
39
40
41
42
43
44
# File 'lib/aaww/transaction.rb', line 37

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