Module: NetsuiteApi::Concerns::ResponseHandler

Included in:
NetsuiteApi::Contact, NetsuiteApi::CreditMemo, NetsuiteApi::Customer, Invoice, Payment, Vendor, VendorBill
Defined in:
lib/netsuite_api/concerns/response_handler.rb

Defined Under Namespace

Classes: NetSuiteApiError

Instance Method Summary collapse

Instance Method Details

#delete_response_handler(response) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/netsuite_api/concerns/response_handler.rb', line 29

def delete_response_handler(response)
  if response.success?
    true
  else
    error_handler(response)
  end
end

#error_handler(response) ⇒ Object

Raises:



37
38
39
40
# File 'lib/netsuite_api/concerns/response_handler.rb', line 37

def error_handler(response)
  response_body = JSON.parse(response.body)
  raise NetSuiteApiError.new(response_body["title"], response_body["title"], response_body["o:errorDetails"])
end

#get_response_handler(response) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/netsuite_api/concerns/response_handler.rb', line 13

def get_response_handler(response)
  if response.success?
    JSON.parse(response.body)
  else
    error_handler(response)
  end
end

#post_and_patch_response_handler(response) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/netsuite_api/concerns/response_handler.rb', line 21

def post_and_patch_response_handler(response)
  if response.success?
    response.headers["location"].split('/').last
  else
    error_handler(response)
  end
end