Class: Tazworks::Order

Inherits:
Model
  • Object
show all
Defined in:
lib/tazworks/order.rb

Overview

Tazworks Orders Model

Instance Attribute Summary

Attributes inherited from Model

#attributes, #attributes_loaded, #ids

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#attributes_loaded?, #clientGuid, find, #initialize, initialize_from_response, #load_attributes, #loaded_attributes, #reload

Constructor Details

This class inherits a constructor from Tazworks::Model

Class Method Details

.all(clientGuid, params = {}) ⇒ Object



14
15
16
17
# File 'lib/tazworks/order.rb', line 14

def self.all(clientGuid, params = {})
  raw_response = RestClient.get("/v1/clients/#{clientGuid}/orders", { params: })
  OrderPagedResponse.new(raw_response, { clientGuid: })
end

.create(clientGuid, params) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tazworks/order.rb', line 20

def self.create(clientGuid, params)
  required_params = %w[applicantGuid clientProductGuid]
  required_params.each do |rp|
    raise ArgumentError, "#{rp} is missing in params hash." unless params.key?(rp.to_sym)
  end

  response = RestClient.post("/v1/clients/#{clientGuid}/orders", params)

  order = Order.initialize_from_response({ clientGuid: }, response)
  order.ids[:orderGuid] = order.attributes[:orderGuid]
  order
end

.get(ids) ⇒ Object



9
10
11
# File 'lib/tazworks/order.rb', line 9

def self.get(ids)
  RestClient.get("/v1/clients/#{ids[:clientGuid]}/orders/#{ids[:orderGuid]}")
end

Instance Method Details

#order_statusObject



34
35
36
37
# File 'lib/tazworks/order.rb', line 34

def order_status
  response = RestClient.get("/v1/clients/#{clientGuid}/orders/#{orderGuid}/status")
  JSON.parse(response.body)
end

#orderGuidObject



50
51
52
# File 'lib/tazworks/order.rb', line 50

def orderGuid
  @ids[:orderGuid]
end


54
55
56
# File 'lib/tazworks/order.rb', line 54

def quickappApplicantLink
  loaded_attributes[:quickappApplicantLink]
end

#results_as_pdfObject



40
41
42
43
44
45
46
47
48
# File 'lib/tazworks/order.rb', line 40

def results_as_pdf
  begin
    response = RestClient.get("/v1/clients/#{clientGuid}/orders/#{orderGuid}/resultsAsPdf")
  rescue ::RestClient::BadRequest => e
    raise Error, e.response.body
  end
  json_parsed = JSON.parse(response.body, { symbolize_names: true })
  json_parsed[:resultsUrl]
end