Class: Shipwire::Response
- Inherits:
-
Object
- Object
- Shipwire::Response
- Defined in:
- lib/shipwire/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#error_summary ⇒ Object
readonly
Returns the value of attribute error_summary.
-
#validation_errors ⇒ Object
readonly
Returns the value of attribute validation_errors.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #error_report ⇒ Object
- #has_error_summary? ⇒ Boolean
- #has_validation_errors? ⇒ Boolean
- #has_warnings? ⇒ Boolean
-
#initialize(underlying_response: nil, error_summary: nil) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
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 load_response() end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/shipwire/response.rb', line 5 def body @body end |
#error_summary ⇒ Object (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_errors ⇒ Object (readonly)
Returns the value of attribute validation_errors.
5 6 7 |
# File 'lib/shipwire/response.rb', line 5 def validation_errors @validation_errors end |
#warnings ⇒ Object (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_report ⇒ Object
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
22 23 24 |
# File 'lib/shipwire/response.rb', line 22 def has_error_summary? !error_summary.nil? end |
#has_validation_errors? ⇒ Boolean
26 27 28 |
# File 'lib/shipwire/response.rb', line 26 def has_validation_errors? !validation_errors.empty? end |
#has_warnings? ⇒ Boolean
30 31 32 |
# File 'lib/shipwire/response.rb', line 30 def has_warnings? !warnings.empty? end |
#ok? ⇒ Boolean
18 19 20 |
# File 'lib/shipwire/response.rb', line 18 def ok? !has_error_summary? && !has_validation_errors? end |