@@ -10,7 +10,8 @@ discard block |
||
10 | 10 | * |
11 | 11 | * @package Requests |
12 | 12 | */ |
13 | -class Requests_Exception extends Exception { |
|
13 | +class Requests_Exception extends Exception |
|
14 | +{ |
|
14 | 15 | /** |
15 | 16 | * Type of exception |
16 | 17 | * |
@@ -33,7 +34,8 @@ discard block |
||
33 | 34 | * @param mixed $data Associated data |
34 | 35 | * @param integer $code Exception numerical code, if applicable |
35 | 36 | */ |
36 | - public function __construct($message, $type, $data = null, $code = 0) { |
|
37 | + public function __construct($message, $type, $data = null, $code = 0) |
|
38 | + { |
|
37 | 39 | parent::__construct($message, $code); |
38 | 40 | |
39 | 41 | $this->type = $type; |
@@ -46,7 +48,8 @@ discard block |
||
46 | 48 | * @codeCoverageIgnore |
47 | 49 | * @return string |
48 | 50 | */ |
49 | - public function getType() { |
|
51 | + public function getType() |
|
52 | + { |
|
50 | 53 | return $this->type; |
51 | 54 | } |
52 | 55 | |
@@ -56,7 +59,8 @@ discard block |
||
56 | 59 | * @codeCoverageIgnore |
57 | 60 | * @return mixed |
58 | 61 | */ |
59 | - public function getData() { |
|
62 | + public function getData() |
|
63 | + { |
|
60 | 64 | return $this->data; |
61 | 65 | } |
62 | 66 | } |
63 | 67 | \ No newline at end of file |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * @param mixed $data Associated data |
34 | 34 | * @param integer $code Exception numerical code, if applicable |
35 | 35 | */ |
36 | - public function __construct($message, $type, $data = null, $code = 0) { |
|
36 | + public function __construct($message, $type, $data = NULL, $code = 0) { |
|
37 | 37 | parent::__construct($message, $code); |
38 | 38 | |
39 | 39 | $this->type = $type; |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * @param array|null $args Array of user and password. Must have exactly two elements |
38 | 38 | */ |
39 | 39 | public function __construct($args = null) { |
40 | - if (is_array($args)) { |
|
41 | - if (count($args) !== 2) { |
|
40 | + if(is_array($args)) { |
|
41 | + if(count($args) !== 2) { |
|
42 | 42 | throw new Requests_Exception('Invalid number of arguments', 'authbasicbadargs'); |
43 | 43 | } |
44 | 44 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @see fsockopen_header |
54 | 54 | * @param Requests_Hooks $hooks Hook system |
55 | 55 | */ |
56 | - public function register(Requests_Hooks &$hooks) { |
|
56 | + public function register(Requests_Hooks&$hooks) { |
|
57 | 57 | $hooks->register('curl.before_send', array(&$this, 'curl_before_send')); |
58 | 58 | $hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header')); |
59 | 59 | } |
@@ -15,7 +15,8 @@ discard block |
||
15 | 15 | * @package Requests |
16 | 16 | * @subpackage Authentication |
17 | 17 | */ |
18 | -class Requests_Auth_Basic implements Requests_Auth { |
|
18 | +class Requests_Auth_Basic implements Requests_Auth |
|
19 | +{ |
|
19 | 20 | /** |
20 | 21 | * Username |
21 | 22 | * |
@@ -36,9 +37,12 @@ discard block |
||
36 | 37 | * @throws Requests_Exception On incorrect number of arguments (`authbasicbadargs`) |
37 | 38 | * @param array|null $args Array of user and password. Must have exactly two elements |
38 | 39 | */ |
39 | - public function __construct($args = null) { |
|
40 | - if (is_array($args)) { |
|
41 | - if (count($args) !== 2) { |
|
40 | + public function __construct($args = null) |
|
41 | + { |
|
42 | + if (is_array($args)) |
|
43 | + { |
|
44 | + if (count($args) !== 2) |
|
45 | + { |
|
42 | 46 | throw new Requests_Exception('Invalid number of arguments', 'authbasicbadargs'); |
43 | 47 | } |
44 | 48 | |
@@ -53,7 +57,8 @@ discard block |
||
53 | 57 | * @see fsockopen_header |
54 | 58 | * @param Requests_Hooks $hooks Hook system |
55 | 59 | */ |
56 | - public function register(Requests_Hooks &$hooks) { |
|
60 | + public function register(Requests_Hooks &$hooks) |
|
61 | + { |
|
57 | 62 | $hooks->register('curl.before_send', array(&$this, 'curl_before_send')); |
58 | 63 | $hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header')); |
59 | 64 | } |
@@ -63,7 +68,8 @@ discard block |
||
63 | 68 | * |
64 | 69 | * @param resource $handle cURL resource |
65 | 70 | */ |
66 | - public function curl_before_send(&$handle) { |
|
71 | + public function curl_before_send(&$handle) |
|
72 | + { |
|
67 | 73 | curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); |
68 | 74 | curl_setopt($handle, CURLOPT_USERPWD, $this->getAuthString()); |
69 | 75 | } |
@@ -73,7 +79,8 @@ discard block |
||
73 | 79 | * |
74 | 80 | * @param string $out HTTP header string |
75 | 81 | */ |
76 | - public function fsockopen_header(&$out) { |
|
82 | + public function fsockopen_header(&$out) |
|
83 | + { |
|
77 | 84 | $out .= sprintf("Authorization: Basic %s\r\n", base64_encode($this->getAuthString())); |
78 | 85 | } |
79 | 86 | |
@@ -82,7 +89,8 @@ discard block |
||
82 | 89 | * |
83 | 90 | * @return string |
84 | 91 | */ |
85 | - public function getAuthString() { |
|
92 | + public function getAuthString() |
|
93 | + { |
|
86 | 94 | return $this->user . ':' . $this->pass; |
87 | 95 | } |
88 | 96 | } |
89 | 97 | \ No newline at end of file |
@@ -36,7 +36,7 @@ |
||
36 | 36 | * @throws Requests_Exception On incorrect number of arguments (`authbasicbadargs`) |
37 | 37 | * @param array|null $args Array of user and password. Must have exactly two elements |
38 | 38 | */ |
39 | - public function __construct($args = null) { |
|
39 | + public function __construct($args = NULL) { |
|
40 | 40 | if (is_array($args)) { |
41 | 41 | if (count($args) !== 2) { |
42 | 42 | throw new Requests_Exception('Invalid number of arguments', 'authbasicbadargs'); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | $expiration_date; |
27 | 27 | $deviceUid; |
28 | 28 | |
29 | - if ($result->num_rows > 0) |
|
29 | + if($result->num_rows > 0) |
|
30 | 30 | { |
31 | 31 | // output data of each row |
32 | 32 | while($row = $result->fetch_assoc()) { |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | |
44 | 44 | if($expiration_date <= time()) { |
45 | 45 | $accountCreator = new CreateUser(); |
46 | - $accountCreator->setAccessToken($access_token);//$accountData->getAccessToken()); |
|
46 | + $accountCreator->setAccessToken($access_token); //$accountData->getAccessToken()); |
|
47 | 47 | $accountCreator->setDeviceUid($deviceUid); |
48 | 48 | $accountCreator->setLocation($location); |
49 | 49 | $data = $accountCreator->execute(); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | WHERE device_uid='" . $device_uid . "'"); |
64 | 64 | |
65 | 65 | $success = TRUE; |
66 | - if($result === false){ |
|
66 | + if($result === false) { |
|
67 | 67 | echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
68 | 68 | $success = FALSE; |
69 | 69 | } |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | $result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type, |
103 | 103 | expires_in, expiration_date, distinct_id, device_uid) |
104 | 104 | VALUES ('" . $access_token . "','" . $refresh_token . "','" . $token_type . |
105 | - "','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
|
105 | + "','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
|
106 | 106 | "','" . $device_uid . "') "); |
107 | 107 | |
108 | 108 | $success = TRUE; |
109 | - if($result === false){ |
|
109 | + if($result === false) { |
|
110 | 110 | $error = db_error(); |
111 | 111 | echo $error; |
112 | 112 | echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
@@ -18,7 +18,8 @@ discard block |
||
18 | 18 | |
19 | 19 | $lastPostId = ""; |
20 | 20 | |
21 | -function isTokenFresh(Location $location) { |
|
21 | +function isTokenFresh(Location $location) |
|
22 | +{ |
|
22 | 23 | $db = new DatabaseConnect(); |
23 | 24 | $result = $db->query("SELECT * FROM accounts WHERE id='1'"); |
24 | 25 | |
@@ -29,7 +30,8 @@ discard block |
||
29 | 30 | if ($result->num_rows > 0) |
30 | 31 | { |
31 | 32 | // output data of each row |
32 | - while($row = $result->fetch_assoc()) { |
|
33 | + while($row = $result->fetch_assoc()) |
|
34 | + { |
|
33 | 35 | //$access_token = $row["access_token"]; |
34 | 36 | $expiration_date = $row["expiration_date"]; |
35 | 37 | $deviceUid = $row["device_uid"]; |
@@ -41,7 +43,8 @@ discard block |
||
41 | 43 | echo "0 results"; |
42 | 44 | } |
43 | 45 | |
44 | - if($expiration_date <= time()) { |
|
46 | + if($expiration_date <= time()) |
|
47 | + { |
|
45 | 48 | $accountCreator = new CreateUser(); |
46 | 49 | $accountCreator->setAccessToken($access_token);//$accountData->getAccessToken()); |
47 | 50 | $accountCreator->setDeviceUid($deviceUid); |
@@ -63,7 +66,8 @@ discard block |
||
63 | 66 | WHERE device_uid='" . $device_uid . "'"); |
64 | 67 | |
65 | 68 | $success = TRUE; |
66 | - if($result === false){ |
|
69 | + if($result === false) |
|
70 | + { |
|
67 | 71 | echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
68 | 72 | $success = FALSE; |
69 | 73 | } |
@@ -85,7 +89,8 @@ discard block |
||
85 | 89 | return $data["karma"]; |
86 | 90 | } |
87 | 91 | |
88 | -function registerAccount(Location $location) { |
|
92 | +function registerAccount(Location $location) |
|
93 | +{ |
|
89 | 94 | $accountCreator = new CreateUser(); |
90 | 95 | $accountCreator->setLocation($location); |
91 | 96 | $data = $accountCreator->execute(); |
@@ -106,7 +111,8 @@ discard block |
||
106 | 111 | "','" . $device_uid . "') "); |
107 | 112 | |
108 | 113 | $success = TRUE; |
109 | - if($result === false){ |
|
114 | + if($result === false) |
|
115 | + { |
|
110 | 116 | $error = db_error(); |
111 | 117 | echo $error; |
112 | 118 | echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
@@ -117,7 +123,7 @@ discard block |
||
117 | 123 | } |
118 | 124 | |
119 | 125 | function getPosts($lastPostId, $accessToken, $url) |
120 | -{ |
|
126 | +{ |
|
121 | 127 | $accountCreator = new GetPosts(); |
122 | 128 | $accountCreator->setLastPostId($lastPostId); |
123 | 129 | $accountCreator->setAccessToken($accessToken); |
@@ -127,7 +133,8 @@ discard block |
||
127 | 133 | return $data; |
128 | 134 | } |
129 | 135 | |
130 | -function createAccount() { |
|
136 | +function createAccount() |
|
137 | +{ |
|
131 | 138 | $location = new Location(); |
132 | 139 | $location->setLat(50.690399); |
133 | 140 | $location->setLng(10.918175); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | WHERE device_uid='" . $device_uid . "'"); |
64 | 64 | |
65 | 65 | $success = TRUE; |
66 | - if($result === false){ |
|
66 | + if($result === FALSE){ |
|
67 | 67 | echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
68 | 68 | $success = FALSE; |
69 | 69 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | "','" . $device_uid . "') "); |
107 | 107 | |
108 | 108 | $success = TRUE; |
109 | - if($result === false){ |
|
109 | + if($result === FALSE){ |
|
110 | 110 | $error = db_error(); |
111 | 111 | echo $error; |
112 | 112 | echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
@@ -2,94 +2,94 @@ |
||
2 | 2 | |
3 | 3 | class AccountData |
4 | 4 | { |
5 | - /** |
|
6 | - * @var string |
|
7 | - */ |
|
8 | - public $accessToken; |
|
9 | - /** |
|
10 | - * @var string |
|
11 | - */ |
|
12 | - public $expirationDate; |
|
13 | - /** |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - public $refreshToken; |
|
17 | - /** |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - public $distinctId; |
|
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - public $deviceUid; |
|
25 | - /** |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function getAccessToken() |
|
29 | - { |
|
30 | - return $this->accessToken; |
|
31 | - } |
|
32 | - /** |
|
33 | - * @param string $accessToken |
|
34 | - */ |
|
35 | - public function setAccessToken(string $accessToken) |
|
36 | - { |
|
37 | - $this->accessToken = $accessToken; |
|
38 | - } |
|
39 | - /** |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function getExpirationDate() |
|
43 | - { |
|
44 | - return $this->expirationDate; |
|
45 | - } |
|
46 | - /** |
|
47 | - * @param string $expirationDate |
|
48 | - */ |
|
49 | - public function setExpirationDate(string $expirationDate) |
|
50 | - { |
|
51 | - $this->expirationDate = $expirationDate; |
|
52 | - } |
|
53 | - /** |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function getRefreshToken() |
|
57 | - { |
|
58 | - return $this->refreshToken; |
|
59 | - } |
|
60 | - /** |
|
61 | - * @param string $refreshToken |
|
62 | - */ |
|
63 | - public function setRefreshToken(string $refreshToken) |
|
64 | - { |
|
65 | - $this->refreshToken = $refreshToken; |
|
66 | - } |
|
67 | - /** |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function getDistinctId() |
|
71 | - { |
|
72 | - return $this->distinctId; |
|
73 | - } |
|
74 | - /** |
|
75 | - * @param string $distinctId |
|
76 | - */ |
|
77 | - public function setDistinctId(string $distinctId) |
|
78 | - { |
|
79 | - $this->distinctId = $distinctId; |
|
80 | - } |
|
81 | - /** |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function getDeviceUid() |
|
85 | - { |
|
86 | - return $this->deviceUid; |
|
87 | - } |
|
88 | - /** |
|
89 | - * @param string $deviceUid |
|
90 | - */ |
|
91 | - public function setDeviceUid(string $deviceUid) |
|
92 | - { |
|
93 | - $this->deviceUid = $deviceUid; |
|
94 | - } |
|
5 | + /** |
|
6 | + * @var string |
|
7 | + */ |
|
8 | + public $accessToken; |
|
9 | + /** |
|
10 | + * @var string |
|
11 | + */ |
|
12 | + public $expirationDate; |
|
13 | + /** |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + public $refreshToken; |
|
17 | + /** |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + public $distinctId; |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + public $deviceUid; |
|
25 | + /** |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function getAccessToken() |
|
29 | + { |
|
30 | + return $this->accessToken; |
|
31 | + } |
|
32 | + /** |
|
33 | + * @param string $accessToken |
|
34 | + */ |
|
35 | + public function setAccessToken(string $accessToken) |
|
36 | + { |
|
37 | + $this->accessToken = $accessToken; |
|
38 | + } |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function getExpirationDate() |
|
43 | + { |
|
44 | + return $this->expirationDate; |
|
45 | + } |
|
46 | + /** |
|
47 | + * @param string $expirationDate |
|
48 | + */ |
|
49 | + public function setExpirationDate(string $expirationDate) |
|
50 | + { |
|
51 | + $this->expirationDate = $expirationDate; |
|
52 | + } |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function getRefreshToken() |
|
57 | + { |
|
58 | + return $this->refreshToken; |
|
59 | + } |
|
60 | + /** |
|
61 | + * @param string $refreshToken |
|
62 | + */ |
|
63 | + public function setRefreshToken(string $refreshToken) |
|
64 | + { |
|
65 | + $this->refreshToken = $refreshToken; |
|
66 | + } |
|
67 | + /** |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function getDistinctId() |
|
71 | + { |
|
72 | + return $this->distinctId; |
|
73 | + } |
|
74 | + /** |
|
75 | + * @param string $distinctId |
|
76 | + */ |
|
77 | + public function setDistinctId(string $distinctId) |
|
78 | + { |
|
79 | + $this->distinctId = $distinctId; |
|
80 | + } |
|
81 | + /** |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function getDeviceUid() |
|
85 | + { |
|
86 | + return $this->deviceUid; |
|
87 | + } |
|
88 | + /** |
|
89 | + * @param string $deviceUid |
|
90 | + */ |
|
91 | + public function setDeviceUid(string $deviceUid) |
|
92 | + { |
|
93 | + $this->deviceUid = $deviceUid; |
|
94 | + } |
|
95 | 95 | } |