class Reparty::Report::Sendgrid

Attributes

api_key[R]
api_user[R]

Public Class Methods

new(*args, &block) click to toggle source
Calls superclass method Reparty::Report::new
# File lib/reparty/report/sendgrid.rb, line 12
def initialize(*args, &block)
  super(args.shift, args.shift)

  @api_user = args.shift
  @api_key = args.shift

  @color = "#287abe"
end

Public Instance Methods

attach(attachments) click to toggle source
# File lib/reparty/report/sendgrid.rb, line 21
def attach(attachments)
  @graph = build_daily_line_graph

  %W{requests delivered bounces spamreports}.each do |stat|
    @graph.data(stat.capitalize, stats.map{|s| s.fetch(stat,0)})
  end

  attachments.inline["#{self.hash}.png"] = @graph.to_blob
end
stats(today=DateTime.now) click to toggle source
# File lib/reparty/report/sendgrid.rb, line 31
def stats(today=DateTime.now)
  @stats ||= self.class.get(
      "https://sendgrid.com/api/stats.get.json?" +
      "api_user=" + @api_user +
      "&api_key=" + @api_key +
      "&start_date=" + (today.utc.to_date - 1).strftime("%Y-%m-%d") +
      "&days=7",
      options: { format: 'json' }
  )

  @stats.pop if @stats.size == 8
  @stats
end