Class: DubbletrackRemote::Error
- Inherits:
-
Object
- Object
- DubbletrackRemote::Error
- Defined in:
- lib/dubbletrack_remote/errors.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#text ⇒ Object
Returns the value of attribute text.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
- #error_text(response) ⇒ Object
-
#initialize(response) ⇒ Error
constructor
A new instance of Error.
- #to_json ⇒ Object
Constructor Details
#initialize(response) ⇒ Error
Returns a new instance of Error.
10 11 12 13 14 |
# File 'lib/dubbletrack_remote/errors.rb', line 10 def initialize(response) @time = Time.now.iso8601 @code = response.status @text = error_text(response) end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
8 9 10 |
# File 'lib/dubbletrack_remote/errors.rb', line 8 def code @code end |
#text ⇒ Object
Returns the value of attribute text.
8 9 10 |
# File 'lib/dubbletrack_remote/errors.rb', line 8 def text @text end |
#time ⇒ Object
Returns the value of attribute time.
8 9 10 |
# File 'lib/dubbletrack_remote/errors.rb', line 8 def time @time end |
Instance Method Details
#error_text(response) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dubbletrack_remote/errors.rb', line 16 def error_text(response) error_text = response.body begin json = JSON.parse(response.body) errors = json["errors"] || [] error_text = errors.flatten.collect { |error| error["detail"] }.join(",") rescue JSON::ParserError # keep the error text as response.body end error_text end |
#to_json ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/dubbletrack_remote/errors.rb', line 28 def to_json { text: @text, code: @code, time: @time } end |