@@ -20,6 +20,7 @@ private static void Main()
2020 UnsubscribeGroups ( ) ;
2121 Suppressions ( ) ;
2222 GlobalSuppressions ( ) ;
23+ GlobalStats ( ) ;
2324 }
2425
2526 private static void SendAsync ( SendGrid . SendGridMessage message )
@@ -33,13 +34,13 @@ private static void SendAsync(SendGrid.SendGridMessage message)
3334 {
3435 transportWeb . DeliverAsync ( message ) . Wait ( ) ;
3536 Console . WriteLine ( "Email sent to " + message . To . GetValue ( 0 ) ) ;
36- Console . WriteLine ( "Press any key to continue." ) ;
37+ Console . WriteLine ( "\n \n Press any key to continue." ) ;
3738 Console . ReadKey ( ) ;
3839 }
3940 catch ( Exception ex )
4041 {
4142 Console . WriteLine ( ex . Message ) ;
42- Console . WriteLine ( "Press any key to continue." ) ;
43+ Console . WriteLine ( "\n \n Press any key to continue." ) ;
4344 Console . ReadKey ( ) ;
4445 }
4546 }
@@ -69,7 +70,7 @@ private static void ApiKeys()
6970 HttpResponseMessage responseGet = client . ApiKeys . Get ( ) . Result ;
7071 Console . WriteLine ( responseGet . StatusCode ) ;
7172 Console . WriteLine ( responseGet . Content . ReadAsStringAsync ( ) . Result ) ;
72- Console . WriteLine ( "These are your current API Keys. Press any key to continue." ) ;
73+ Console . WriteLine ( "These are your current API Keys.\n \n Press any key to continue." ) ;
7374 Console . ReadKey ( ) ;
7475
7576 // POST API KEYS
@@ -79,14 +80,14 @@ private static void ApiKeys()
7980 var apiKeyId = jsonObject . api_key_id . ToString ( ) ;
8081 Console . WriteLine ( responsePost . StatusCode ) ;
8182 Console . WriteLine ( responsePost . Content . ReadAsStringAsync ( ) . Result ) ;
82- Console . WriteLine ( "API Key created. Press any key to continue." ) ;
83+ Console . WriteLine ( "API Key created.\n \n Press any key to continue." ) ;
8384 Console . ReadKey ( ) ;
8485
8586 // PATCH API KEYS
8687 HttpResponseMessage responsePatch = client . ApiKeys . Patch ( apiKeyId , "CSharpTestKeyPatched" ) . Result ;
8788 Console . WriteLine ( responsePatch . StatusCode ) ;
8889 Console . WriteLine ( responsePatch . Content . ReadAsStringAsync ( ) . Result ) ;
89- Console . WriteLine ( "API Key patched. Press any key to continue." ) ;
90+ Console . WriteLine ( "API Key patched.\n \n Press any key to continue." ) ;
9091 Console . ReadKey ( ) ;
9192
9293 // DELETE API KEYS
@@ -96,7 +97,7 @@ private static void ApiKeys()
9697 HttpResponseMessage responseFinal = client . ApiKeys . Get ( ) . Result ;
9798 Console . WriteLine ( responseFinal . StatusCode ) ;
9899 Console . WriteLine ( responseFinal . Content . ReadAsStringAsync ( ) . Result ) ;
99- Console . WriteLine ( "API Key Deleted, press any key to end." ) ;
100+ Console . WriteLine ( "API Key Deleted. \n \n Press any key to end." ) ;
100101 Console . ReadKey ( ) ;
101102 }
102103
@@ -117,7 +118,7 @@ private static void UnsubscribeGroups()
117118 HttpResponseMessage responseGetUnique = client . UnsubscribeGroups . Get ( unsubscribeGroupID ) . Result ;
118119 Console . WriteLine ( responseGetUnique . StatusCode ) ;
119120 Console . WriteLine ( responseGetUnique . Content . ReadAsStringAsync ( ) . Result ) ;
120- Console . WriteLine ( "This is an Unsubscribe Group with ID: " + unsubscribeGroupID . ToString ( ) + ". Press any key to continue." ) ;
121+ Console . WriteLine ( "This is an Unsubscribe Group with ID: " + unsubscribeGroupID . ToString ( ) + ".\n \n Press any key to continue." ) ;
121122 Console . ReadKey ( ) ;
122123
123124 // POST UNSUBSCRIBE GROUP
@@ -127,7 +128,7 @@ private static void UnsubscribeGroups()
127128 var unsubscribeGroupId = jsonObject . id . ToString ( ) ;
128129 Console . WriteLine ( responsePost . StatusCode ) ;
129130 Console . WriteLine ( responsePost . Content . ReadAsStringAsync ( ) . Result ) ;
130- Console . WriteLine ( "Unsubscribe Group created. Press any key to continue." ) ;
131+ Console . WriteLine ( "Unsubscribe Group created.\n \n Press any key to continue." ) ;
131132 Console . ReadKey ( ) ;
132133
133134 // DELETE UNSUBSCRIBE GROUP
@@ -137,7 +138,7 @@ private static void UnsubscribeGroups()
137138 HttpResponseMessage responseFinal = client . UnsubscribeGroups . Get ( ) . Result ;
138139 Console . WriteLine ( responseFinal . StatusCode ) ;
139140 Console . WriteLine ( responseFinal . Content . ReadAsStringAsync ( ) . Result ) ;
140- Console . WriteLine ( "Unsubscribe Group Deleted, press any key to end." ) ;
141+ Console . WriteLine ( "Unsubscribe Group Deleted. \n \n Press any key to end." ) ;
141142 Console . ReadKey ( ) ;
142143 }
143144
@@ -161,7 +162,7 @@ private static void Suppressions()
161162 dynamic jsonObject = JObject . Parse ( rawString ) ;
162163 Console . WriteLine ( responsePost . StatusCode ) ;
163164 Console . WriteLine ( responsePost . Content . ReadAsStringAsync ( ) . Result ) ;
164- Console . WriteLine ( "Emails added to Suppression Group:" + groupID . ToString ( ) + ". Press any key to continue." ) ;
165+ Console . WriteLine ( "Emails added to Suppression Group:" + groupID . ToString ( ) + ".\n \n Press any key to continue." ) ;
165166 Console . ReadKey ( ) ;
166167
167168 // DELETE EMAILS FROM A SUPPRESSION GROUP
@@ -173,7 +174,7 @@ private static void Suppressions()
173174 HttpResponseMessage responseFinal = client . Suppressions . Get ( groupID ) . Result ;
174175 Console . WriteLine ( responseFinal . StatusCode ) ;
175176 Console . WriteLine ( responseFinal . Content . ReadAsStringAsync ( ) . Result ) ;
176- Console . WriteLine ( "Emails removed from Suppression Group" + groupID . ToString ( ) + "Deleted. Press any key to end." ) ;
177+ Console . WriteLine ( "Emails removed from Suppression Group" + groupID . ToString ( ) + "Deleted.\n \n Press any key to end." ) ;
177178 Console . ReadKey ( ) ;
178179 }
179180
@@ -182,25 +183,25 @@ private static void GlobalSuppressions()
182183 String apiKey = Environment . GetEnvironmentVariable ( "SENDGRID_APIKEY" , EnvironmentVariableTarget . User ) ;
183184 var client = new SendGrid . Client ( apiKey ) ;
184185
185- // GET SUPPRESSED ADDRESSES FOR A GIVEN GROUP
186+ // CHECK IF EMAIL IS ON THE GLOBAL SUPPRESSION LIST
186187187188 HttpResponseMessage responseGetUnique = client . GlobalSuppressions . Get ( email ) . Result ;
188189 Console . WriteLine ( responseGetUnique . StatusCode ) ;
189190 Console . WriteLine ( responseGetUnique . Content . ReadAsStringAsync ( ) . Result ) ;
190191 Console . WriteLine ( "Determines if the given email is listed on the Global Suppressions list. Press any key to continue." ) ;
191192 Console . ReadKey ( ) ;
192193
193- // ADD EMAILS TO A SUPPRESSION GROUP
194+ // ADD EMAILS TO THE GLOBAL SUPPRESSION LIST
194195195196 HttpResponseMessage responsePost = client . GlobalSuppressions . Post ( emails ) . Result ;
196197 var rawString = responsePost . Content . ReadAsStringAsync ( ) . Result ;
197198 dynamic jsonObject = JObject . Parse ( rawString ) ;
198199 Console . WriteLine ( responsePost . StatusCode ) ;
199200 Console . WriteLine ( responsePost . Content . ReadAsStringAsync ( ) . Result ) ;
200- Console . WriteLine ( "Emails added to Global Suppression Group. Press any key to continue." ) ;
201+ Console . WriteLine ( "Emails added to Global Suppression Group.\n \n Press any key to continue." ) ;
201202 Console . ReadKey ( ) ;
202203
203- // DELETE EMAILS FROM A SUPPRESSION GROUP
204+ // DELETE EMAILS FROM THE GLOBAL SUPPRESSION GROUP
204205 Console . WriteLine ( "Deleting emails from Global Suppression Group, please wait." ) ;
205206 HttpResponseMessage responseDelete1 = client . GlobalSuppressions . Delete ( "[email protected] " ) . Result ; 206207 Console . WriteLine ( responseDelete1 . StatusCode ) ;
@@ -212,7 +213,49 @@ private static void GlobalSuppressions()
212213 HttpResponseMessage responseFinal2 = client . GlobalSuppressions . Get ( "[email protected] " ) . Result ; 213214 Console . WriteLine ( responseFinal2 . StatusCode ) ;
214215 Console . WriteLine ( responseFinal2 . Content . ReadAsStringAsync ( ) . Result ) ;
215- Console . WriteLine ( "Emails removed from Global Suppression Group. Press any key to end." ) ;
216+ Console . WriteLine ( "Emails removed from Global Suppression Group.\n \n Press any key to end." ) ;
217+ Console . ReadKey ( ) ;
218+ }
219+
220+ private static void GlobalStats ( )
221+ {
222+ String apiKey = Environment . GetEnvironmentVariable ( "SENDGRID_APIKEY" , EnvironmentVariableTarget . User ) ;
223+ var client = new SendGrid . Client ( apiKey ) ;
224+
225+ // Global Stats provide all of your user’s email statistics for a given date range.
226+ var startDate = "2015-11-01" ;
227+ HttpResponseMessage response = client . GlobalStats . Get ( startDate ) . Result ;
228+ Console . WriteLine ( response . StatusCode ) ;
229+ Console . WriteLine ( response . Content . ReadAsStringAsync ( ) . Result ) ;
230+ Console . WriteLine ( "Display global email stats, with start date " + startDate + "and no end date.\n \n Press any key to continue." ) ;
231+ Console . ReadKey ( ) ;
232+
233+ var endDate = "2015-12-01" ;
234+ response = client . GlobalStats . Get ( startDate , endDate ) . Result ;
235+ Console . WriteLine ( response . StatusCode ) ;
236+ Console . WriteLine ( response . Content . ReadAsStringAsync ( ) . Result ) ;
237+ Console . WriteLine ( "Display global email stats, with start date " + startDate + "and end date " + endDate + ".\n \n Press any key to continue." ) ;
238+ Console . ReadKey ( ) ;
239+
240+ var aggregatedBy = "day" ;
241+ response = client . GlobalStats . Get ( startDate , endDate , aggregatedBy ) . Result ;
242+ Console . WriteLine ( response . StatusCode ) ;
243+ Console . WriteLine ( response . Content . ReadAsStringAsync ( ) . Result ) ;
244+ Console . WriteLine ( "Display global email stats, with start date " + startDate + "and end date " + endDate + " and aggregated by " + aggregatedBy + ".\n \n Press any key to continue." ) ;
245+ Console . ReadKey ( ) ;
246+
247+ aggregatedBy = "week" ;
248+ response = client . GlobalStats . Get ( startDate , endDate , aggregatedBy ) . Result ;
249+ Console . WriteLine ( response . StatusCode ) ;
250+ Console . WriteLine ( response . Content . ReadAsStringAsync ( ) . Result ) ;
251+ Console . WriteLine ( "Display global email stats, with start date " + startDate + "and end date " + endDate + " and aggregated by " + aggregatedBy + ".\n \n Press any key to continue." ) ;
252+ Console . ReadKey ( ) ;
253+
254+ aggregatedBy = "month" ;
255+ response = client . GlobalStats . Get ( startDate , endDate , aggregatedBy ) . Result ;
256+ Console . WriteLine ( response . StatusCode ) ;
257+ Console . WriteLine ( response . Content . ReadAsStringAsync ( ) . Result ) ;
258+ Console . WriteLine ( "Display global email stats, with start date " + startDate + "and end date " + endDate + " and aggregated by " + aggregatedBy + ".\n \n Press any key to continue." ) ;
216259 Console . ReadKey ( ) ;
217260 }
218261
0 commit comments