/lib/aws/ses/info.rb

http://github.com/drewblas/aws-ses · Ruby · 100 lines · 39 code · 9 blank · 52 comment · 1 complexity · fd52b0e3ed2e11627b2294a20340a9b9 MD5 · raw file

  1. module AWS
  2. module SES
  3. # Adds functionality for the statistics and info send quota data that Amazon SES makes available
  4. #
  5. # You can access these methods as follows:
  6. #
  7. # ses = AWS::SES::Base.new( ... connection info ... )
  8. #
  9. # == Get the quota information
  10. # response = ses.quota
  11. # # How many e-mails you've sent in the last 24 hours
  12. # response.sent_last_24_hours
  13. # # How many e-mails you're allowed to send in 24 hours
  14. # response.max_24_hour_send
  15. # # How many e-mails you can send per second
  16. # response.max_send_rate
  17. #
  18. # == Get detailed send statistics
  19. # The result is a list of data points, representing the last two weeks of sending activity.
  20. # Each data point in the list contains statistics for a 15-minute interval.
  21. # GetSendStatisticsResponse#data_points is an array where each element is a hash with give string keys:
  22. #
  23. # * +Bounces+
  24. # * +DeliveryAttempts+
  25. # * +Rejects+
  26. # * +Complaints+
  27. # * +Timestamp+
  28. #
  29. # response = ses.statistics
  30. # response.data_points # =>
  31. # [{"Bounces"=>"0",
  32. # "Timestamp"=>"2011-01-26T16:30:00Z",
  33. # "DeliveryAttempts"=>"1",
  34. # "Rejects"=>"0",
  35. # "Complaints"=>"0"},
  36. # {"Bounces"=>"0",
  37. # "Timestamp"=>"2011-02-09T14:45:00Z",
  38. # "DeliveryAttempts"=>"3",
  39. # "Rejects"=>"0",
  40. # "Complaints"=>"0"},
  41. # {"Bounces"=>"0",
  42. # "Timestamp"=>"2011-01-31T15:30:00Z",
  43. # "DeliveryAttempts"=>"3",
  44. # "Rejects"=>"0",
  45. # "Complaints"=>"0"},
  46. # {"Bounces"=>"0",
  47. # "Timestamp"=>"2011-01-31T16:00:00Z",
  48. # "DeliveryAttempts"=>"3",
  49. # "Rejects"=>"0",
  50. # "Complaints"=>"0"}]
  51. module Info
  52. # Returns quota information provided by SES
  53. #
  54. # The return format inside the response result will look like:
  55. # {"SentLast24Hours"=>"0.0", "MaxSendRate"=>"1.0", "Max24HourSend"=>"200.0"}
  56. def quota
  57. request('GetSendQuota')
  58. end
  59. def statistics
  60. request('GetSendStatistics')
  61. end
  62. end
  63. class GetSendQuotaResponse < AWS::SES::Response
  64. def result
  65. parsed['GetSendQuotaResult']
  66. end
  67. def sent_last_24_hours
  68. result['SentLast24Hours']
  69. end
  70. def max_24_hour_send
  71. result['Max24HourSend']
  72. end
  73. def max_send_rate
  74. result['MaxSendRate']
  75. end
  76. end
  77. class GetSendStatisticsResponse < AWS::SES::Response
  78. def result
  79. if members = parsed['GetSendStatisticsResult']['SendDataPoints']
  80. [members['member']].flatten
  81. else
  82. []
  83. end
  84. end
  85. memoized :result
  86. def data_points
  87. result
  88. end
  89. end
  90. end
  91. end