Class: Perry::Persistence::Response
- Inherits:
-
Object
- Object
- Perry::Persistence::Response
- Defined in:
- lib/perry/persistence/response.rb
Constant Summary collapse
- ATTRIBUTES =
[:success, :status, :meta, :raw, :raw_format, :parsed]
- @@parsers =
{ :json => ::JSON }
Instance Attribute Summary collapse
-
#meta ⇒ Object
Any adapter specific response metadata.
- #parsed ⇒ Object
-
#raw ⇒ Object
Raw response – format specified by raw_format.
-
#raw_format ⇒ Object
Format of the raw response.
-
#status ⇒ Object
A more detailed report of the success/failure of the response.
-
#success ⇒ Object
A boolean value reflecting whether or not the response was successful.
Class Method Summary collapse
Instance Method Summary collapse
- #array_attributes ⇒ Object
- #errors ⇒ Object
-
#initialize(attrs = {}) ⇒ Response
constructor
@attrs: Sets any values listed in ATTRIBUTES.
- #model_attributes ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Response
@attrs: Sets any values listed in ATTRIBUTES
26 27 28 29 30 |
# File 'lib/perry/persistence/response.rb', line 26 def initialize(attrs={}) ATTRIBUTES.each do |attr| self.send("#{attr}=", attrs[attr]) end end |
Instance Attribute Details
#meta ⇒ Object
Any adapter specific response metadata
14 15 16 |
# File 'lib/perry/persistence/response.rb', line 14 def @meta end |
#parsed ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/perry/persistence/response.rb', line 32 def parsed if parser = self.class.parsers[self.raw_format] begin @parsed ||= parser.parse(self.raw) rescue Exception => err Perry.logger.error("Failure parsing raw response #{err.inspect}") Perry.logger.error("Response: #{self.inspect}") nil end else @parsed end end |
#raw ⇒ Object
Raw response – format specified by raw_format
17 18 19 |
# File 'lib/perry/persistence/response.rb', line 17 def raw @raw end |
#raw_format ⇒ Object
Format of the raw response
20 21 22 |
# File 'lib/perry/persistence/response.rb', line 20 def raw_format @raw_format end |
#status ⇒ Object
A more detailed report of the success/failure of the response
11 12 13 |
# File 'lib/perry/persistence/response.rb', line 11 def status @status end |
#success ⇒ Object
A boolean value reflecting whether or not the response was successful
8 9 10 |
# File 'lib/perry/persistence/response.rb', line 8 def success @success end |
Class Method Details
.parsers ⇒ Object
46 47 48 |
# File 'lib/perry/persistence/response.rb', line 46 def self.parsers @@parsers end |
Instance Method Details
#array_attributes ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/perry/persistence/response.rb', line 55 def array_attributes if parsed.is_a?(Array) parsed.collect { |item| item.is_a?(Hash) ? extract_attributes(item) : item } else [] end end |
#errors ⇒ Object
63 64 65 |
# File 'lib/perry/persistence/response.rb', line 63 def errors parsed_hash.symbolize_keys end |
#model_attributes ⇒ Object
50 51 52 53 |
# File 'lib/perry/persistence/response.rb', line 50 def model_attributes # return the inner hash if nested extract_attributes(parsed_hash) end |