-
Notifications
You must be signed in to change notification settings - Fork 0
/
sgstats2phone.php
executable file
·88 lines (72 loc) · 2.92 KB
/
sgstats2phone.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/php
<?php
/******************************************************************************/
/* Module ..... sgstats2phone.php */
/* Author ..... Neil Simon */
/* Modified ... 06/07/2011 */
/* Desc ....... Delivers SendGrid account stats to a phone call */
/* Usage ...... sgstats2phone.php {phone} {username} {api_key} */
/******************************************************************************/
/******************************************************************************/
/* Include classes */
/******************************************************************************/
require_once ("CommandLine.php");
require_once ("SendGrid.php");
require_once ("SendGridCurl.php");
/******************************************************************************/
/* main */
/******************************************************************************/
main ($argc, $argv);
function main ($argc, $argv)
{
// Reset to 0 upon success
$rc = 1;
// 3 args (+progname) required
if ($argc != 4)
{
usage ();
printf ("ERROR: 3 args required.\n");
}
else
{
// Store args
$commandLine = new CommandLine_sgstats2phone ($argc, $argv);
// Extract args
$commandLine->extractArgs ();
// Validate args
if (($argStatus = $commandLine->validateArgs ()) != 0)
{
usage ();
$commandLine->printArgErrorMessage ($argStatus);
}
else
{
// Store the args in the sendGrid object
$sendGrid = new SendGrid ($commandLine->argPhone, // 3034029500
$commandLine->argUser, // nsimon@solidcode.com
$commandLine->argApiKey); // MySecretApiKey
// Get the SendGrid stats for the current day (via REST/XML)
if ($sendGrid->statsGet () != 0)
{
printf ("ERROR: sendGrid->statsGet()\n");
}
else
{
// Assemble the text-to-speech text, setup params to pass to curl
$sendGrid->assembleStats ();
// Send stats to phone
if (SendGridCurl::issueRequest ($sendGrid->get_statsParams()) == 0)
{
// Successful
$rc = 0;
}
}
}
}
exit ($rc);
}
function usage ()
{
printf ("Usage: sgstats2phone.php {phone} {username} {api_key}\n");
printf ("Ex: sgstats2phone.php 3034029500 nsimon@solidcode.com MySecretApiKey\n");
}