Class: Shipwire::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/shipwire/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(underlying_response: nil, error_summary: nil) ⇒ Response

Returns a new instance of Response.



7
8
9
10
11
12
13
14
15
16
# File 'lib/shipwire/response.rb', line 7

def initialize(underlying_response: nil, error_summary: nil)
  @error_summary = error_summary

  @validation_errors = []
  @warnings = []

  if underlying_response
    load_response(underlying_response)
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/shipwire/response.rb', line 5

def body
  @body
end

#error_summaryObject (readonly)

Returns the value of attribute error_summary.



5
6
7
# File 'lib/shipwire/response.rb', line 5

def error_summary
  @error_summary
end

#validation_errorsObject (readonly)

Returns the value of attribute validation_errors.



5
6
7
# File 'lib/shipwire/response.rb', line 5

def validation_errors
  @validation_errors
end

#warningsObject (readonly)

Returns the value of attribute warnings.



5
6
7
# File 'lib/shipwire/response.rb', line 5

def warnings
  @warnings
end

Instance Method Details

#error_reportObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/shipwire/response.rb', line 34

def error_report
  report_lines = []

  if has_error_summary?
    report_lines << 'Error summary:'
    report_lines << error_summary
  end

  if has_validation_errors?
    report_lines << 'Validation errors:'
    report_lines << validation_errors.pretty_inspect.rstrip
  end

  report_lines.join("\n")
end

#has_error_summary?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/shipwire/response.rb', line 22

def has_error_summary?
  !error_summary.nil?
end

#has_validation_errors?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/shipwire/response.rb', line 26

def has_validation_errors?
  !validation_errors.empty?
end

#has_warnings?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/shipwire/response.rb', line 30

def has_warnings?
  !warnings.empty?
end

#ok?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/shipwire/response.rb', line 18

def ok?
  !has_error_summary? && !has_validation_errors?
end