Class: SendgridToolkit::Statistics

Inherits:
AbstractSendgridClient show all
Defined in:
lib/sendgrid_toolkit/statistics.rb

Instance Method Summary collapse

Methods inherited from AbstractSendgridClient

#initialize

Constructor Details

This class inherits a constructor from SendgridToolkit::AbstractSendgridClient

Instance Method Details

#list_categories(options = {}) ⇒ Object



25
26
27
28
29
# File 'lib/sendgrid_toolkit/statistics.rb', line 25

def list_categories(options = {})
  options.merge! :list => true
  response = retrieve options
  response
end

#retrieve(options = {}) ⇒ Object



3
4
5
6
# File 'lib/sendgrid_toolkit/statistics.rb', line 3

def retrieve(options = {})
  response = api_post('stats', 'get', options)
  response
end

#retrieve_aggregate(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/sendgrid_toolkit/statistics.rb', line 8

def retrieve_aggregate(options = {})
  options.merge! :aggregate => 1
  response = retrieve options
  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

#to_ints(resp) ⇒ Object



19
20
21
22
23
# File 'lib/sendgrid_toolkit/statistics.rb', line 19

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