class SendGrid::StatsResponse

Public Class Methods

new(args) click to toggle source
# File lib/sendgrid/helpers/stats/stats_response.rb, line 3
def initialize(args)
  @errors = args['errors'] if args.is_a? Hash
  @stats = args if args.is_a? Array
end

Public Instance Methods

error?() click to toggle source
# File lib/sendgrid/helpers/stats/stats_response.rb, line 14
def error?
  !@errors.nil?
end
errors() click to toggle source
# File lib/sendgrid/helpers/stats/stats_response.rb, line 8
def errors
  @errors.map do |error|
    error['message']
  end
end
metrics() click to toggle source
# File lib/sendgrid/helpers/stats/stats_response.rb, line 18
def metrics
  @stats.flat_map do |stat|
    starting_date = stat['date']
    all_stats_for_date = stat['stats']

    all_stats_for_date.map do |metric|
      Metrics.new(metric['metrics'].merge('date' => starting_date))
    end
  end
end