sendgrid-web 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sendgrid/web/statistics.rb +101 -0
- data/lib/sendgrid/web/version.rb +1 -1
- data/lib/sendgrid/web.rb +1 -0
- data/spec/sendgrid/web/statistics_spec.rb +46 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72f7a0fbf53971295a55c04915c382e9499e8573
|
4
|
+
data.tar.gz: c71046c3bf1adbd9536c3bacbb5bd4af8b80f332
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00b0c2db81803f65e168fbdd9e94f595a3258ff0a1e43c48a771b8bcd6ccd9c9a1b3c0f8fc10d270fa2eeab64f497faab2bf43b901f1c5295bfe9749a6315c4c
|
7
|
+
data.tar.gz: e28781fe17f6ba28e392524548aa7f905ceaca73f771ea5a131275dbe68a6764b2d0682e406854cda68322f08dc4143f316322c925de5351f29372dbc3d042d9
|
@@ -0,0 +1,101 @@
|
|
1
|
+
class Sendgrid::Web::Statistics < Sendgrid::Web::Client
|
2
|
+
|
3
|
+
# Retrieve statistics and data about your use of SendGrid.
|
4
|
+
#
|
5
|
+
# @param days [Integer] Number of days in the past to include
|
6
|
+
# statistics (Includes today).
|
7
|
+
# @param start_date [DateTime] The start date to look up statistics.
|
8
|
+
# @param end_date [DateTime] The end date to look up statistics.
|
9
|
+
# @param aggregate [Integer] This is used to indicate you are
|
10
|
+
# interested in all-time totals.
|
11
|
+
# @param list [bool] Determins if SendGrid should return a list of
|
12
|
+
# categories.
|
13
|
+
# @param category [String] The category you will specify to retrieve
|
14
|
+
# detailed stats.
|
15
|
+
# @return [Sendgrid::Web::Response] The SendGrid response.
|
16
|
+
# @note All parameters are optional.
|
17
|
+
def get(
|
18
|
+
days: nil, start_date: nil, end_date: nil,
|
19
|
+
aggregate: nil, list: nil, category: nil)
|
20
|
+
res = connection.post(
|
21
|
+
'/api/stats.get.json',
|
22
|
+
default_params(
|
23
|
+
days: days,
|
24
|
+
start_date: start_date,
|
25
|
+
end_date: end_date,
|
26
|
+
aggregate: aggregate,
|
27
|
+
list: list,
|
28
|
+
category: category))
|
29
|
+
craft_response(res)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Retrieve more advanced and in-depth statistics.
|
33
|
+
#
|
34
|
+
# @param data_type [String] Must be one of the following:
|
35
|
+
# - +browsers+: Browser data obtained from click events.
|
36
|
+
# - +clients+: Email client data obtained from open events.
|
37
|
+
# - +devices+: Device data obtained from open events.
|
38
|
+
# - +geo+: Geographical data obtained from multiple events.
|
39
|
+
# - +global+: Global account data obtained from multiple events.
|
40
|
+
# - +isps+: ISP data obtained from multiple events.
|
41
|
+
# @param start_date [String] Date format is based on aggregated_by
|
42
|
+
# value (default is yyyy-mm-dd):
|
43
|
+
# - yyyy-mm-dd (i.e 2012-12-13) if aggregated_by=day (default)
|
44
|
+
# - yyyy-ww (i.e 2012-43) if aggregated_by=week
|
45
|
+
# - yyyy-mm (i.e 2012-11) if aggregated_by=month
|
46
|
+
# @param end_date [String] Date format is based on aggregated_by
|
47
|
+
# value (default is yyyy-mm-dd):
|
48
|
+
# - yyyy-mm-dd (i.e 2012-12-13) if aggregated_by=day (default)
|
49
|
+
# - yyyy-ww (i.e 2012-43) if aggregated_by=week
|
50
|
+
# - yyyy-mm (i.e 2012-11) if aggregated_by=month
|
51
|
+
# @param metric [String] One of the following (default is all):
|
52
|
+
# - +open+: Opens
|
53
|
+
# - +click+: Clicks
|
54
|
+
# - +unique_open+: Unique opens
|
55
|
+
# - +unique_click+: Unique clicks
|
56
|
+
# - +processed+: Processed emails
|
57
|
+
# - +delivered+: Delivered emails
|
58
|
+
# - +drop+: Dropped emails
|
59
|
+
# - +bounce+: Bounced emails
|
60
|
+
# - +deferred+: Deferred email tries
|
61
|
+
# - +spamreport+: Emails marked as spam
|
62
|
+
# - +blocked+: Emails that have been blocked
|
63
|
+
# - +all+: All metrics are returned
|
64
|
+
# @param category [String] Return stats for the given category.
|
65
|
+
# @param aggregated_by [String] Aggregate the data by the given
|
66
|
+
# period (default is day):
|
67
|
+
# - +day+: Keys are returned in the format yyyy-mm-dd
|
68
|
+
# (i.e 2012-12-13)
|
69
|
+
# - +week+: Keys are return in the format yyyy-ww (i.e 2012-43)
|
70
|
+
# - +month+: Keys are return in the format yyyy-mm (i.e 2012-11)
|
71
|
+
# @param country [String] Get stats for each region/state for the
|
72
|
+
# given country. Only US (United States) and CA (Canada) is
|
73
|
+
# supported at this time. Country code is two letter characters
|
74
|
+
# based on {http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2}.
|
75
|
+
#
|
76
|
+
# This parameter is only used for when data_type=geo
|
77
|
+
# @return [Sendgrid::Web::Response] The SendGrid response.
|
78
|
+
# @note The +data_type+ and +start_date+ parameters are required.
|
79
|
+
def get_advanced(
|
80
|
+
data_type: nil, start_date: nil, end_date: nil,
|
81
|
+
metric: nil, category: nil, aggregated_by: nil,
|
82
|
+
country: nil)
|
83
|
+
if data_type.nil?
|
84
|
+
raise ArgumentError.new('Missing required `data_type` option')
|
85
|
+
elsif start_date.nil?
|
86
|
+
raise ArgumentError.new('Missing required `start_date` option')
|
87
|
+
end
|
88
|
+
res = connection.post(
|
89
|
+
'/api/stats.getAdvanced.json',
|
90
|
+
default_params(
|
91
|
+
data_type: data_type,
|
92
|
+
start_date: start_date,
|
93
|
+
end_date: end_date,
|
94
|
+
metric: metric,
|
95
|
+
category: category,
|
96
|
+
aggregated_by: aggregated_by,
|
97
|
+
country: country))
|
98
|
+
craft_response(res)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
data/lib/sendgrid/web/version.rb
CHANGED
data/lib/sendgrid/web.rb
CHANGED
@@ -16,6 +16,7 @@ module Sendgrid
|
|
16
16
|
autoload :Profile, 'sendgrid/web/profile'
|
17
17
|
autoload :SpamReports, 'sendgrid/web/spam_reports'
|
18
18
|
autoload :Unsubscribes, 'sendgrid/web/unsubscribes'
|
19
|
+
autoload :Statistics, 'sendgrid/web/statistics'
|
19
20
|
autoload :Response, 'sendgrid/web/response'
|
20
21
|
end
|
21
22
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sendgrid::Web::Statistics do
|
4
|
+
describe '#get' do
|
5
|
+
it_behaves_like('a sendgrid response', '/api/stats.get.json') do
|
6
|
+
let(:action) { subject.get }
|
7
|
+
let(:response) do
|
8
|
+
'[
|
9
|
+
{
|
10
|
+
"date": "2009-06-20",
|
11
|
+
"requests": 12342,
|
12
|
+
"bounces": 12,
|
13
|
+
"clicks": 10223,
|
14
|
+
"opens": 9992,
|
15
|
+
"spamreports": 5,
|
16
|
+
"unique_clicks": 3,
|
17
|
+
"unique_opens": 6,
|
18
|
+
"blocked": 7
|
19
|
+
}
|
20
|
+
]'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#get_advanced' do
|
26
|
+
it_behaves_like('a sendgrid response', '/api/stats.getAdvanced.json') do
|
27
|
+
let(:action) { subject.get_advanced(
|
28
|
+
data_type: :global,
|
29
|
+
start_date: DateTime.new(2013, 01, 01)) }
|
30
|
+
let(:response) do
|
31
|
+
'[
|
32
|
+
{
|
33
|
+
"delivered": 41,
|
34
|
+
"request": 41,
|
35
|
+
"unique_open": 1,
|
36
|
+
"unique_click": 1,
|
37
|
+
"processed": 41,
|
38
|
+
"date": "2013-01-01",
|
39
|
+
"open": 2,
|
40
|
+
"click": 1
|
41
|
+
}
|
42
|
+
]'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid-web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darren Coxall
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- lib/sendgrid/web/profile.rb
|
110
110
|
- lib/sendgrid/web/response.rb
|
111
111
|
- lib/sendgrid/web/spam_reports.rb
|
112
|
+
- lib/sendgrid/web/statistics.rb
|
112
113
|
- lib/sendgrid/web/unsubscribes.rb
|
113
114
|
- lib/sendgrid/web/version.rb
|
114
115
|
- sendgrid-web.gemspec
|
@@ -124,6 +125,7 @@ files:
|
|
124
125
|
- spec/sendgrid/web/profile_spec.rb
|
125
126
|
- spec/sendgrid/web/response_spec.rb
|
126
127
|
- spec/sendgrid/web/spam_reports_spec.rb
|
128
|
+
- spec/sendgrid/web/statistics_spec.rb
|
127
129
|
- spec/sendgrid/web/unsubscribes_spec.rb
|
128
130
|
- spec/spec_helper.rb
|
129
131
|
- spec/support/shared_sendgrid_response.rb
|
@@ -164,6 +166,7 @@ test_files:
|
|
164
166
|
- spec/sendgrid/web/profile_spec.rb
|
165
167
|
- spec/sendgrid/web/response_spec.rb
|
166
168
|
- spec/sendgrid/web/spam_reports_spec.rb
|
169
|
+
- spec/sendgrid/web/statistics_spec.rb
|
167
170
|
- spec/sendgrid/web/unsubscribes_spec.rb
|
168
171
|
- spec/spec_helper.rb
|
169
172
|
- spec/support/shared_sendgrid_response.rb
|