Class: SendGrid::StatsResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/sendgrid/helpers/stats/stats_response.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ StatsResponse

Returns a new instance of StatsResponse.



3
4
5
6
# 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

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/sendgrid/helpers/stats/stats_response.rb', line 14

def error?
  !@errors.nil?
end

#errorsObject



8
9
10
11
12
# File 'lib/sendgrid/helpers/stats/stats_response.rb', line 8

def errors
  @errors.map do |error|
    error['message']
  end
end

#metricsObject



18
19
20
21
22
23
24
25
26
27
# 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