lib/sendgrid_toolkit/statistics.rb in sendgrid_toolkit-1.0.5 vs lib/sendgrid_toolkit/statistics.rb in sendgrid_toolkit-1.0.6
- old
+ new
@@ -1,23 +1,32 @@
module SendgridToolkit
class Statistics < AbstractSendgridClient
def retrieve(options = {})
response = api_post('stats', 'get', options)
+ response.each {|r| r['date'] = Date.parse(r['date']) if r.kind_of?(Hash) && r.has_key?('date')}
response
end
def retrieve_aggregate(options = {})
options.merge! :aggregate => 1
response = retrieve options
- %w(bounces clicks delivered invalid_email opens repeat_bounces repeat_spamreports repeat_unsubscribes requests spamreports unsubscribes).each do |int_field|
- response[int_field] = response[int_field].to_i if response.has_key?(int_field)
+ if Hash === response.parsed_response
+ to_ints(response.parsed_response)
+ elsif Array === response.parsed_response
+ response.parsed_response.each {|o| to_ints(o) }
end
response
end
-
+
+ def to_ints(resp)
+ %w(bounces clicks delivered invalid_email opens repeat_bounces repeat_spamreports repeat_unsubscribes requests spamreports unsubscribes).each do |int_field|
+ resp[int_field] = resp[int_field].to_i if resp.has_key?(int_field)
+ end
+ end
+
def list_categories(options = {})
options.merge! :list => true
response = retrieve options
response
end
end
-end
\ No newline at end of file
+end