Class: Legato::Response
- Inherits:
-
Object
- Object
- Legato::Response
- Defined in:
- lib/legato/response.rb
Instance Method Summary collapse
- #collection ⇒ Object
- #data ⇒ Object
-
#initialize(raw_response, instance_klass = OpenStruct) ⇒ Response
constructor
A new instance of Response.
- #total_results ⇒ Object
- #totals_for_all_results ⇒ Object
Constructor Details
#initialize(raw_response, instance_klass = OpenStruct) ⇒ Response
Returns a new instance of Response.
3 4 5 6 |
# File 'lib/legato/response.rb', line 3 def initialize(raw_response, instance_klass = OpenStruct) @raw_response = raw_response @instance_klass = instance_klass end |
Instance Method Details
#collection ⇒ Object
12 13 14 |
# File 'lib/legato/response.rb', line 12 def collection raw_attributes.map {|attributes| @instance_klass.new(attributes)} end |
#data ⇒ Object
8 9 10 |
# File 'lib/legato/response.rb', line 8 def data @data ||= MultiJson.decode(@raw_response.body) end |
#total_results ⇒ Object
16 17 18 |
# File 'lib/legato/response.rb', line 16 def total_results data["totalResults"] end |
#totals_for_all_results ⇒ Object
20 21 22 |
# File 'lib/legato/response.rb', line 20 def totals_for_all_results Hash[data["totalsForAllResults"].map{|k,v| [Legato.from_ga_string(k), number_for(v)]}] end |