Class: Legato::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/legato/response.rb

Instance Method Summary collapse

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

#collectionObject



12
13
14
# File 'lib/legato/response.rb', line 12

def collection
  raw_attributes.map {|attributes| @instance_klass.new(attributes)}
end

#dataObject



8
9
10
# File 'lib/legato/response.rb', line 8

def data
  @data ||= MultiJson.decode(@raw_response.body)
end

#total_resultsObject



16
17
18
# File 'lib/legato/response.rb', line 16

def total_results
  data["totalResults"]
end

#totals_for_all_resultsObject



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