forked from SurveyGizmoOfficial/PHP_SurveyGizmo_Api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SurveyGizmo.php
executable file
·59 lines (51 loc) · 1.24 KB
/
SurveyGizmo.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
<?php
namespace SurveyGizmo;
use SurveyGizmo\Helpers\SurveyGizmoException;
use SurveyGizmo\Resources\Account;
/**
* Simple class to store auth credentials for SG API and authorize API use.
*/
class SurveyGizmoAPI
{
/**
* API AuthToken
*/
static $AuthToken;
/**
* API AuthSecret
*/
static $AuthSecret;
/**
* Authorizes API use for all calls and performes a test to verify creds are still good
* @access public
* @param string $api_key api key from SurveyGizmo
* @param string $api_secret api secret from SurveyGizmo
* @return void
*/
public static function auth($api_key, $api_secret)
{
self::$AuthToken = $api_key;
self::$AuthSecret = $api_secret;
return self::testCredentials();
}
/**
* Get authorization credentials for subsequent api calls
* @access public
* @return Array - AuthToken and AuthSecret
*/
public static function getAuth()
{
return array("AuthToken" => self::$AuthToken, "AuthSecret" => self::$AuthSecret);
}
/**
* Test call to verify AuthToken and AuthSecret
* @access private
* @return void
*/
private static function testCredentials()
{
if (!Account::get() || !Account::get()->exists()) {
throw new SurveyGizmoException('', SurveyGizmoException::NOT_AUTHORIZED);
}
}
}