Class: Fleck::Client::Response
- Inherits:
-
Object
- Object
- Fleck::Client::Response
- Includes:
- Loggable
- Defined in:
- lib/fleck/client/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#deprecated ⇒ Object
Returns the value of attribute deprecated.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #deprecated? ⇒ Boolean
-
#initialize(payload) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #to_json(filter: false) ⇒ Object
- #to_s ⇒ Object
Methods included from Loggable
Constructor Details
#initialize(payload) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 12 13 14 |
# File 'lib/fleck/client/response.rb', line 7 def initialize(payload) @data = Oj.load(payload, mode: :compat).to_hash_with_indifferent_access.filtered! @status = @data["status"] @headers = @data["headers"] || {} @body = @data["body"] @errors = @data["errors"] || [] @deprecated = !!@data["deprecated"] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
6 7 8 |
# File 'lib/fleck/client/response.rb', line 6 def body @body end |
#deprecated ⇒ Object
Returns the value of attribute deprecated.
6 7 8 |
# File 'lib/fleck/client/response.rb', line 6 def deprecated @deprecated end |
#errors ⇒ Object
Returns the value of attribute errors.
6 7 8 |
# File 'lib/fleck/client/response.rb', line 6 def errors @errors end |
#headers ⇒ Object
Returns the value of attribute headers.
6 7 8 |
# File 'lib/fleck/client/response.rb', line 6 def headers @headers end |
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'lib/fleck/client/response.rb', line 6 def status @status end |
Instance Method Details
#deprecated? ⇒ Boolean
16 17 18 |
# File 'lib/fleck/client/response.rb', line 16 def deprecated? @deprecated end |
#inspect ⇒ Object
43 44 45 |
# File 'lib/fleck/client/response.rb', line 43 def inspect self.to_s end |
#to_json(filter: false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fleck/client/response.rb', line 20 def to_json(filter: false) data = { "status" => @status, "errors" => @errors, "headers" => @headers, "body" => @body, "deprecated" => @deprecated } data.filter! if filter return Oj.dump(data, mode: :compat) rescue => e logger.error e.inspect + "\n" + e.backtrace.join("\n") return Oj.dump({ "status" => 500, "errors" => ['Internal Server Error', 'Failed to dump the response to JSON'] }, mode: :compat) end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/fleck/client/response.rb', line 39 def to_s return "#<#{self.class} #{self.to_json(filter: true)}>" end |