@@ -40,6 +40,6 @@ |
||
| 40 | 40 | ) DEFAULT CHARSET=utf8"; |
| 41 | 41 | if(!$db->query($query)) |
| 42 | 42 | { |
| 43 | - throw new Exception($db->error($mysqli)); |
|
| 43 | + throw new Exception($db->error($mysqli)); |
|
| 44 | 44 | } |
| 45 | 45 | |
@@ -12,7 +12,8 @@ |
||
| 12 | 12 | |
| 13 | 13 | } |
| 14 | 14 | $db = new DatabaseConnect(); |
| 15 | -if ($db->connect_errno) { |
|
| 15 | +if ($db->connect_errno) |
|
| 16 | +{ |
|
| 16 | 17 | echo 'Sorry, die Verbindung zu unserem superfetten endgeilen |
| 17 | 18 | Server ist hops gegangen. Wegen '.$db -> connect_error; |
| 18 | 19 | } |
@@ -3,18 +3,18 @@ |
||
| 3 | 3 | |
| 4 | 4 | class GetKarma extends AbstractRequest { |
| 5 | 5 | |
| 6 | - function getApiEndPoint() |
|
| 7 | - { |
|
| 8 | - return '/v2/users/karma'; |
|
| 9 | - } |
|
| 10 | - function getPayload() |
|
| 11 | - { |
|
| 12 | - return array( |
|
| 13 | - ); |
|
| 14 | - } |
|
| 15 | - function getMethod() |
|
| 16 | - { |
|
| 17 | - return 'GET'; |
|
| 18 | - } |
|
| 6 | + function getApiEndPoint() |
|
| 7 | + { |
|
| 8 | + return '/v2/users/karma'; |
|
| 9 | + } |
|
| 10 | + function getPayload() |
|
| 11 | + { |
|
| 12 | + return array( |
|
| 13 | + ); |
|
| 14 | + } |
|
| 15 | + function getMethod() |
|
| 16 | + { |
|
| 17 | + return 'GET'; |
|
| 18 | + } |
|
| 19 | 19 | } |
| 20 | 20 | |
@@ -1,7 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -class GetKarma extends AbstractRequest { |
|
| 4 | +class GetKarma extends AbstractRequest |
|
| 5 | +{ |
|
| 5 | 6 | |
| 6 | 7 | function getApiEndPoint() |
| 7 | 8 | { |
@@ -3,19 +3,19 @@ |
||
| 3 | 3 | |
| 4 | 4 | class Upvote extends AbstractRequest { |
| 5 | 5 | |
| 6 | - function getApiEndPoint() |
|
| 7 | - { |
|
| 8 | - return '/v2/posts/' . $_GET['postID'] . '/upvote'; |
|
| 9 | - } |
|
| 10 | - function getPayload() |
|
| 11 | - { |
|
| 12 | - return array( |
|
| 6 | + function getApiEndPoint() |
|
| 7 | + { |
|
| 8 | + return '/v2/posts/' . $_GET['postID'] . '/upvote'; |
|
| 9 | + } |
|
| 10 | + function getPayload() |
|
| 11 | + { |
|
| 12 | + return array( |
|
| 13 | 13 | "reason_code" => -1, |
| 14 | - ); |
|
| 15 | - } |
|
| 16 | - function getMethod() |
|
| 17 | - { |
|
| 18 | - return 'PUT'; |
|
| 19 | - } |
|
| 14 | + ); |
|
| 15 | + } |
|
| 16 | + function getMethod() |
|
| 17 | + { |
|
| 18 | + return 'PUT'; |
|
| 19 | + } |
|
| 20 | 20 | } |
| 21 | 21 | |
@@ -1,7 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -class Upvote extends AbstractRequest { |
|
| 4 | +class Upvote extends AbstractRequest |
|
| 5 | +{ |
|
| 5 | 6 | |
| 6 | 7 | function getApiEndPoint() |
| 7 | 8 | { |
@@ -3,18 +3,18 @@ |
||
| 3 | 3 | |
| 4 | 4 | class GetPostDetails extends AbstractRequest { |
| 5 | 5 | |
| 6 | - function getApiEndPoint() |
|
| 7 | - { |
|
| 8 | - return '/v2/posts/' . $_GET['postID']; |
|
| 9 | - } |
|
| 10 | - function getPayload() |
|
| 11 | - { |
|
| 12 | - return array( |
|
| 13 | - ); |
|
| 14 | - } |
|
| 15 | - function getMethod() |
|
| 16 | - { |
|
| 17 | - return 'GET'; |
|
| 18 | - } |
|
| 6 | + function getApiEndPoint() |
|
| 7 | + { |
|
| 8 | + return '/v2/posts/' . $_GET['postID']; |
|
| 9 | + } |
|
| 10 | + function getPayload() |
|
| 11 | + { |
|
| 12 | + return array( |
|
| 13 | + ); |
|
| 14 | + } |
|
| 15 | + function getMethod() |
|
| 16 | + { |
|
| 17 | + return 'GET'; |
|
| 18 | + } |
|
| 19 | 19 | } |
| 20 | 20 | |
@@ -1,7 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -class GetPostDetails extends AbstractRequest { |
|
| 4 | +class GetPostDetails extends AbstractRequest |
|
| 5 | +{ |
|
| 5 | 6 | |
| 6 | 7 | function getApiEndPoint() |
| 7 | 8 | { |
@@ -3,18 +3,18 @@ |
||
| 3 | 3 | |
| 4 | 4 | class Downvote extends AbstractRequest { |
| 5 | 5 | |
| 6 | - function getApiEndPoint() |
|
| 7 | - { |
|
| 8 | - return '/v2/posts/' . $_GET['postID'] . '/downvote'; |
|
| 9 | - } |
|
| 10 | - function getPayload() |
|
| 11 | - { |
|
| 12 | - return array( |
|
| 13 | - ); |
|
| 14 | - } |
|
| 15 | - function getMethod() |
|
| 16 | - { |
|
| 17 | - return 'PUT'; |
|
| 18 | - } |
|
| 6 | + function getApiEndPoint() |
|
| 7 | + { |
|
| 8 | + return '/v2/posts/' . $_GET['postID'] . '/downvote'; |
|
| 9 | + } |
|
| 10 | + function getPayload() |
|
| 11 | + { |
|
| 12 | + return array( |
|
| 13 | + ); |
|
| 14 | + } |
|
| 15 | + function getMethod() |
|
| 16 | + { |
|
| 17 | + return 'PUT'; |
|
| 18 | + } |
|
| 19 | 19 | } |
| 20 | 20 | |
@@ -1,7 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -class Downvote extends AbstractRequest { |
|
| 4 | +class Downvote extends AbstractRequest |
|
| 5 | +{ |
|
| 5 | 6 | |
| 6 | 7 | function getApiEndPoint() |
| 7 | 8 | { |
@@ -1,7 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -class SetLocation extends AbstractRequest { |
|
| 4 | +class SetLocation extends AbstractRequest |
|
| 5 | +{ |
|
| 5 | 6 | /** |
| 6 | 7 | * @var Location |
| 7 | 8 | */ |
@@ -3,37 +3,37 @@ |
||
| 3 | 3 | |
| 4 | 4 | class UpdateLocation extends AbstractRequest { |
| 5 | 5 | /** |
| 6 | - * @var Location |
|
| 7 | - */ |
|
| 8 | - public $location; |
|
| 9 | - /** |
|
| 10 | - * @return Location |
|
| 11 | - */ |
|
| 12 | - public function getLocation() |
|
| 13 | - { |
|
| 14 | - return $this->location; |
|
| 15 | - } |
|
| 16 | - /** |
|
| 17 | - * @param Location $location |
|
| 18 | - */ |
|
| 19 | - public function setLocation($location) |
|
| 20 | - { |
|
| 21 | - $this->location = $location; |
|
| 22 | - } |
|
| 6 | + * @var Location |
|
| 7 | + */ |
|
| 8 | + public $location; |
|
| 9 | + /** |
|
| 10 | + * @return Location |
|
| 11 | + */ |
|
| 12 | + public function getLocation() |
|
| 13 | + { |
|
| 14 | + return $this->location; |
|
| 15 | + } |
|
| 16 | + /** |
|
| 17 | + * @param Location $location |
|
| 18 | + */ |
|
| 19 | + public function setLocation($location) |
|
| 20 | + { |
|
| 21 | + $this->location = $location; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - function getApiEndPoint() |
|
| 25 | - { |
|
| 26 | - return '/v2/users/location'; |
|
| 27 | - } |
|
| 28 | - function getPayload() |
|
| 29 | - { |
|
| 30 | - return array( |
|
| 24 | + function getApiEndPoint() |
|
| 25 | + { |
|
| 26 | + return '/v2/users/location'; |
|
| 27 | + } |
|
| 28 | + function getPayload() |
|
| 29 | + { |
|
| 30 | + return array( |
|
| 31 | 31 | "location" => $this->getLocation()->toArray(), |
| 32 | - ); |
|
| 33 | - } |
|
| 34 | - function getMethod() |
|
| 35 | - { |
|
| 36 | - return 'PUT'; |
|
| 37 | - } |
|
| 32 | + ); |
|
| 33 | + } |
|
| 34 | + function getMethod() |
|
| 35 | + { |
|
| 36 | + return 'PUT'; |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | |
@@ -1,6 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -class CreateUser extends AbstractRequest { |
|
| 3 | +class CreateUser extends AbstractRequest |
|
| 4 | +{ |
|
| 4 | 5 | /** |
| 5 | 6 | * @var Location |
| 6 | 7 | */ |
@@ -25,7 +26,7 @@ discard block |
||
| 25 | 26 | return $this->deviceUid; |
| 26 | 27 | } |
| 27 | 28 | public function setDeviceUid($deviceUid) |
| 28 | - { |
|
| 29 | + { |
|
| 29 | 30 | $this->deviceUid = $deviceUid; |
| 30 | 31 | } |
| 31 | 32 | public function generateDeviceUid() |
@@ -36,7 +37,8 @@ discard block |
||
| 36 | 37 | { |
| 37 | 38 | $str = ''; |
| 38 | 39 | $max = mb_strlen($keyspace, '8bit') - 1; |
| 39 | - for ($i = 0; $i < $length; ++$i) { |
|
| 40 | + for ($i = 0; $i < $length; ++$i) |
|
| 41 | + { |
|
| 40 | 42 | $str .= $keyspace[random_int(0, $max)]; |
| 41 | 43 | } |
| 42 | 44 | return $str; |
@@ -1,53 +1,53 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class CreateUser extends AbstractRequest { |
| 4 | - /** |
|
| 5 | - * @var Location |
|
| 6 | - */ |
|
| 7 | - private $location; |
|
| 8 | - private $deviceUid; |
|
| 9 | - /** |
|
| 10 | - * @return Location |
|
| 11 | - */ |
|
| 12 | - private function getLocation() |
|
| 13 | - { |
|
| 14 | - return $this->location; |
|
| 15 | - } |
|
| 16 | - /** |
|
| 17 | - * @param Location $location |
|
| 18 | - */ |
|
| 19 | - public function setLocation(Location $location) |
|
| 20 | - { |
|
| 21 | - $this->location = $location; |
|
| 22 | - } |
|
| 23 | - private function getDeviceUid() |
|
| 24 | - { |
|
| 4 | + /** |
|
| 5 | + * @var Location |
|
| 6 | + */ |
|
| 7 | + private $location; |
|
| 8 | + private $deviceUid; |
|
| 9 | + /** |
|
| 10 | + * @return Location |
|
| 11 | + */ |
|
| 12 | + private function getLocation() |
|
| 13 | + { |
|
| 14 | + return $this->location; |
|
| 15 | + } |
|
| 16 | + /** |
|
| 17 | + * @param Location $location |
|
| 18 | + */ |
|
| 19 | + public function setLocation(Location $location) |
|
| 20 | + { |
|
| 21 | + $this->location = $location; |
|
| 22 | + } |
|
| 23 | + private function getDeviceUid() |
|
| 24 | + { |
|
| 25 | 25 | return $this->deviceUid; |
| 26 | 26 | } |
| 27 | 27 | public function setDeviceUid($deviceUid) |
| 28 | - { |
|
| 28 | + { |
|
| 29 | 29 | $this->deviceUid = $deviceUid; |
| 30 | 30 | } |
| 31 | - private function generateDeviceUid() |
|
| 32 | - { |
|
| 33 | - return $this->random_str(64, 'abcdef0123456789'); |
|
| 34 | - } |
|
| 31 | + private function generateDeviceUid() |
|
| 32 | + { |
|
| 33 | + return $this->random_str(64, 'abcdef0123456789'); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - private function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
|
| 37 | - { |
|
| 38 | - $str = ''; |
|
| 39 | - $max = mb_strlen($keyspace, '8bit') - 1; |
|
| 40 | - for ($i = 0; $i < $length; ++$i) { |
|
| 41 | - $str .= $keyspace[random_int(0, $max)]; |
|
| 42 | - } |
|
| 43 | - return $str; |
|
| 44 | - } |
|
| 45 | - public function getApiEndPoint() |
|
| 46 | - { |
|
| 47 | - return '/v2/users'; |
|
| 48 | - } |
|
| 49 | - public function getPayload() |
|
| 50 | - { |
|
| 36 | + private function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
|
| 37 | + { |
|
| 38 | + $str = ''; |
|
| 39 | + $max = mb_strlen($keyspace, '8bit') - 1; |
|
| 40 | + for ($i = 0; $i < $length; ++$i) { |
|
| 41 | + $str .= $keyspace[random_int(0, $max)]; |
|
| 42 | + } |
|
| 43 | + return $str; |
|
| 44 | + } |
|
| 45 | + public function getApiEndPoint() |
|
| 46 | + { |
|
| 47 | + return '/v2/users'; |
|
| 48 | + } |
|
| 49 | + public function getPayload() |
|
| 50 | + { |
|
| 51 | 51 | if(!isset($this->deviceUid)) |
| 52 | 52 | { |
| 53 | 53 | $this->setDeviceUid($this->generateDeviceUid()); |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | "client_id" => self::CLIENTID, |
| 59 | 59 | "device_uid" => $this->getDeviceUid(), |
| 60 | 60 | ); |
| 61 | - } |
|
| 62 | - public function getMethod() |
|
| 63 | - { |
|
| 64 | - return 'POST'; |
|
| 65 | - } |
|
| 61 | + } |
|
| 62 | + public function getMethod() |
|
| 63 | + { |
|
| 64 | + return 'POST'; |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -31,7 +31,8 @@ |
||
| 31 | 31 | { |
| 32 | 32 | $apiEndPoint = $this->getUrl(); |
| 33 | 33 | //echo $GLOBALS['lastPostId']; |
| 34 | - if ($this->getLastPostId() != "") { |
|
| 34 | + if ($this->getLastPostId() != "") |
|
| 35 | + { |
|
| 35 | 36 | $apiEndPoint = $this->getUrl() . '/location/?after=' . $this->getLastPostId(); |
| 36 | 37 | } |
| 37 | 38 | return $apiEndPoint; |
@@ -5,20 +5,20 @@ discard block |
||
| 5 | 5 | { |
| 6 | 6 | public $lastPostId; |
| 7 | 7 | |
| 8 | - public $url; |
|
| 8 | + public $url; |
|
| 9 | 9 | |
| 10 | - function setUrl ($url) |
|
| 11 | - { |
|
| 12 | - $this->url = $url; |
|
| 13 | - } |
|
| 10 | + function setUrl ($url) |
|
| 11 | + { |
|
| 12 | + $this->url = $url; |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - function getUrl () |
|
| 16 | - { |
|
| 17 | - return $this->url; |
|
| 18 | - } |
|
| 15 | + function getUrl () |
|
| 16 | + { |
|
| 17 | + return $this->url; |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - function setLastPostId ($lastPostId) |
|
| 21 | - { |
|
| 20 | + function setLastPostId ($lastPostId) |
|
| 21 | + { |
|
| 22 | 22 | $this->lastPostId = $lastPostId; |
| 23 | 23 | } |
| 24 | 24 | |
@@ -27,22 +27,22 @@ discard block |
||
| 27 | 27 | return $this->lastPostId; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - function getApiEndPoint() |
|
| 31 | - { |
|
| 32 | - $apiEndPoint = $this->getUrl(); |
|
| 30 | + function getApiEndPoint() |
|
| 31 | + { |
|
| 32 | + $apiEndPoint = $this->getUrl(); |
|
| 33 | 33 | |
| 34 | - if ($this->getLastPostId() != "") { |
|
| 34 | + if ($this->getLastPostId() != "") { |
|
| 35 | 35 | $apiEndPoint = $this->getUrl() . '?after=' . $this->getLastPostId(); |
| 36 | 36 | } |
| 37 | - return $apiEndPoint; |
|
| 38 | - } |
|
| 39 | - function getPayload() |
|
| 40 | - { |
|
| 41 | - return array( |
|
| 42 | - ); |
|
| 43 | - } |
|
| 44 | - function getMethod() |
|
| 45 | - { |
|
| 46 | - return 'GET'; |
|
| 47 | - } |
|
| 37 | + return $apiEndPoint; |
|
| 38 | + } |
|
| 39 | + function getPayload() |
|
| 40 | + { |
|
| 41 | + return array( |
|
| 42 | + ); |
|
| 43 | + } |
|
| 44 | + function getMethod() |
|
| 45 | + { |
|
| 46 | + return 'GET'; |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | abstract class AbstractRequest |
| 4 | -{ |
|
| 4 | +{ |
|
| 5 | 5 | CONST CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
| 6 | 6 | CONST APIURL = 'https://api.go-tellm.com/api'; |
| 7 | 7 | const SECRET = "VwJHzYUbPjGiXWauoVNaHoCWsaacTmnkGwNtHhjy"; |
@@ -19,7 +19,8 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | $this->payLoad = $this->getPayload(); |
| 21 | 21 | $device_uid = ""; |
| 22 | - if(isset($this->payLoad["device_uid"])) { |
|
| 22 | + if(isset($this->payLoad["device_uid"])) |
|
| 23 | + { |
|
| 23 | 24 | $device_uid = $this->payLoad["device_uid"]; |
| 24 | 25 | } |
| 25 | 26 | |
@@ -28,7 +29,8 @@ discard block |
||
| 28 | 29 | $header = $this->getSignHeaders(); |
| 29 | 30 | $url = $this->getFullUrl(); |
| 30 | 31 | |
| 31 | - if ($this->getAccessToken()) { |
|
| 32 | + if ($this->getAccessToken()) |
|
| 33 | + { |
|
| 32 | 34 | $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
| 33 | 35 | } |
| 34 | 36 | //Comment out to debug the Request: |
@@ -39,7 +41,8 @@ discard block |
||
| 39 | 41 | */ |
| 40 | 42 | |
| 41 | 43 | |
| 42 | - switch ($this->getMethod()) { |
|
| 44 | + switch ($this->getMethod()) |
|
| 45 | + { |
|
| 43 | 46 | case 'POST': |
| 44 | 47 | $result = Requests::post($url, $header, $this->payLoad); |
| 45 | 48 | break; |
@@ -50,7 +53,8 @@ discard block |
||
| 50 | 53 | $result = Requests::put($url, $header, $this->payLoad); |
| 51 | 54 | break; |
| 52 | 55 | } |
| 53 | - switch ($result->status_code) { |
|
| 56 | + switch ($result->status_code) |
|
| 57 | + { |
|
| 54 | 58 | case 200: |
| 55 | 59 | $result = json_decode($result->body, true); |
| 56 | 60 | break; |
@@ -90,10 +94,12 @@ discard block |
||
| 90 | 94 | public function getSignHeaders() |
| 91 | 95 | { |
| 92 | 96 | $payload_accessToken; |
| 93 | - if($this->getAccessToken() == null) { |
|
| 97 | + if($this->getAccessToken() == null) |
|
| 98 | + { |
|
| 94 | 99 | $payload_accessToken = ""; |
| 95 | 100 | } |
| 96 | - else { |
|
| 101 | + else |
|
| 102 | + { |
|
| 97 | 103 | $payload_accessToken = $this->getAccessToken(); |
| 98 | 104 | } |
| 99 | 105 | |
@@ -2,18 +2,18 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | abstract class AbstractRequest |
| 4 | 4 | { |
| 5 | - CONST CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
| 6 | - CONST APIURL = 'https://api.go-tellm.com/api'; |
|
| 7 | - const SECRET = "dIHNtHWOxFmoFouufSflpTKYjPmCIhWUCQHgbNzR"; |
|
| 8 | - const USERAGENT = "Jodel/4.28.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
|
| 9 | - const CLIENT_TYPE = 'android_4.29.1'; |
|
| 5 | + CONST CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
| 6 | + CONST APIURL = 'https://api.go-tellm.com/api'; |
|
| 7 | + const SECRET = "dIHNtHWOxFmoFouufSflpTKYjPmCIhWUCQHgbNzR"; |
|
| 8 | + const USERAGENT = "Jodel/4.28.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
|
| 9 | + const CLIENT_TYPE = 'android_4.29.1'; |
|
| 10 | 10 | |
| 11 | - private $accessToken = null; |
|
| 12 | - private $payLoad; |
|
| 13 | - public $expects = ""; |
|
| 11 | + private $accessToken = null; |
|
| 12 | + private $payLoad; |
|
| 13 | + public $expects = ""; |
|
| 14 | 14 | |
| 15 | - public function execute() |
|
| 16 | - { |
|
| 15 | + public function execute() |
|
| 16 | + { |
|
| 17 | 17 | $result = new \stdClass(); |
| 18 | 18 | |
| 19 | 19 | $this->payLoad = $this->getPayload(); |
@@ -23,71 +23,71 @@ discard block |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
| 26 | - $this->payLoad = json_encode($this->payLoad); |
|
| 27 | - $header = $this->getSignHeaders(); |
|
| 28 | - $url = $this->getFullUrl(); |
|
| 26 | + $this->payLoad = json_encode($this->payLoad); |
|
| 27 | + $header = $this->getSignHeaders(); |
|
| 28 | + $url = $this->getFullUrl(); |
|
| 29 | 29 | |
| 30 | - if ($this->getAccessToken()) { |
|
| 31 | - $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
| 32 | - } |
|
| 33 | - //Comment out to debug the Request: |
|
| 34 | - /* |
|
| 30 | + if ($this->getAccessToken()) { |
|
| 31 | + $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
| 32 | + } |
|
| 33 | + //Comment out to debug the Request: |
|
| 34 | + /* |
|
| 35 | 35 | var_dump($url); |
| 36 | 36 | var_dump($header); |
| 37 | 37 | var_dump($this->payLoad); |
| 38 | 38 | */ |
| 39 | 39 | |
| 40 | 40 | |
| 41 | - switch ($this->getMethod()) { |
|
| 42 | - case 'POST': |
|
| 43 | - $result = Requests::post($url, $header, $this->payLoad); |
|
| 44 | - break; |
|
| 45 | - case 'GET': |
|
| 46 | - $result = Requests::get($url, $header); |
|
| 47 | - break; |
|
| 48 | - case 'PUT': |
|
| 49 | - $result = Requests::put($url, $header, $this->payLoad); |
|
| 50 | - break; |
|
| 51 | - } |
|
| 52 | - switch ($result->status_code) { |
|
| 53 | - case 200: |
|
| 54 | - $result = json_decode($result->body, true); |
|
| 55 | - break; |
|
| 56 | - case 204: |
|
| 57 | - $result = "Success"; |
|
| 58 | - break; |
|
| 59 | - case 401: |
|
| 41 | + switch ($this->getMethod()) { |
|
| 42 | + case 'POST': |
|
| 43 | + $result = Requests::post($url, $header, $this->payLoad); |
|
| 44 | + break; |
|
| 45 | + case 'GET': |
|
| 46 | + $result = Requests::get($url, $header); |
|
| 47 | + break; |
|
| 48 | + case 'PUT': |
|
| 49 | + $result = Requests::put($url, $header, $this->payLoad); |
|
| 50 | + break; |
|
| 51 | + } |
|
| 52 | + switch ($result->status_code) { |
|
| 53 | + case 200: |
|
| 54 | + $result = json_decode($result->body, true); |
|
| 55 | + break; |
|
| 56 | + case 204: |
|
| 57 | + $result = "Success"; |
|
| 58 | + break; |
|
| 59 | + case 401: |
|
| 60 | 60 | throw new \Exception('Unauthorized'); |
| 61 | - break; |
|
| 62 | - case 404: |
|
| 63 | - //echo "Es wurde bereits gevoted"; |
|
| 61 | + break; |
|
| 62 | + case 404: |
|
| 63 | + //echo "Es wurde bereits gevoted"; |
|
| 64 | 64 | case 477: |
| 65 | - //echo "Es wurde bereits gevoted"; |
|
| 66 | - //throw new \Exception('Signing failed!'); |
|
| 67 | - break; |
|
| 68 | - default: |
|
| 69 | - throw new \Exception('Unknown Error: '.$result->status_code); |
|
| 70 | - } |
|
| 65 | + //echo "Es wurde bereits gevoted"; |
|
| 66 | + //throw new \Exception('Signing failed!'); |
|
| 67 | + break; |
|
| 68 | + default: |
|
| 69 | + throw new \Exception('Unknown Error: '.$result->status_code); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - if($device_uid != "") |
|
| 73 | - { |
|
| 72 | + if($device_uid != "") |
|
| 73 | + { |
|
| 74 | 74 | $result[0] = $result; |
| 75 | 75 | $result[1] = $device_uid; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /* |
|
| 78 | + /* |
|
| 79 | 79 | var_dump($result); |
| 80 | 80 | */ |
| 81 | 81 | |
| 82 | - return $result; |
|
| 83 | - } |
|
| 84 | - abstract function getPayload(); |
|
| 85 | - /** |
|
| 86 | - * Gets Sign headers |
|
| 87 | - * @return array headers |
|
| 88 | - */ |
|
| 89 | - private function getSignHeaders() |
|
| 90 | - { |
|
| 82 | + return $result; |
|
| 83 | + } |
|
| 84 | + abstract function getPayload(); |
|
| 85 | + /** |
|
| 86 | + * Gets Sign headers |
|
| 87 | + * @return array headers |
|
| 88 | + */ |
|
| 89 | + private function getSignHeaders() |
|
| 90 | + { |
|
| 91 | 91 | if($this->getAccessToken() == null) { |
| 92 | 92 | $payload_accessToken = ""; |
| 93 | 93 | } |
@@ -96,54 +96,54 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
| 99 | - $headers = array( |
|
| 100 | - "Connection" => "keep-alive", |
|
| 101 | - "Accept-Encoding" => "gzip", |
|
| 102 | - "Content-Type" => "application/json; charset=UTF-8", |
|
| 103 | - "User-Agent" => self::USERAGENT |
|
| 104 | - ); |
|
| 105 | - $timestamp = new DateTime(); |
|
| 106 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
| 107 | - $timestamp = substr($timestamp, 0, -6); |
|
| 108 | - $timestamp .= "Z"; |
|
| 109 | - $urlParts = parse_url($this->getFullUrl()); |
|
| 110 | - $url2 = ""; |
|
| 111 | - $req = [$this->getMethod(), |
|
| 112 | - $urlParts['host'], |
|
| 113 | - "443", |
|
| 114 | - $urlParts['path'], |
|
| 115 | - $payload_accessToken, |
|
| 116 | - $timestamp, |
|
| 117 | - $url2, |
|
| 118 | - $this->payLoad]; |
|
| 119 | - $reqString = implode("%", $req); |
|
| 120 | - $secret = self::SECRET; |
|
| 121 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
| 122 | - $signature = strtoupper($signature); |
|
| 123 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
| 124 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
| 125 | - $headers['X-Timestamp'] = $timestamp; |
|
| 126 | - $headers['X-Api-Version'] = '0.2'; |
|
| 127 | - return $headers; |
|
| 128 | - } |
|
| 129 | - private function getFullUrl() |
|
| 130 | - { |
|
| 131 | - return self::APIURL . $this->getApiEndPoint(); |
|
| 132 | - } |
|
| 133 | - abstract function getApiEndPoint(); |
|
| 134 | - abstract function getMethod(); |
|
| 135 | - /** |
|
| 136 | - * @return string |
|
| 137 | - */ |
|
| 138 | - private function getAccessToken() |
|
| 139 | - { |
|
| 140 | - return $this->accessToken; |
|
| 141 | - } |
|
| 142 | - /** |
|
| 143 | - * @param string $accessToken |
|
| 144 | - */ |
|
| 145 | - public function setAccessToken($accessToken) |
|
| 146 | - { |
|
| 147 | - $this->accessToken = $accessToken; |
|
| 148 | - } |
|
| 99 | + $headers = array( |
|
| 100 | + "Connection" => "keep-alive", |
|
| 101 | + "Accept-Encoding" => "gzip", |
|
| 102 | + "Content-Type" => "application/json; charset=UTF-8", |
|
| 103 | + "User-Agent" => self::USERAGENT |
|
| 104 | + ); |
|
| 105 | + $timestamp = new DateTime(); |
|
| 106 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
| 107 | + $timestamp = substr($timestamp, 0, -6); |
|
| 108 | + $timestamp .= "Z"; |
|
| 109 | + $urlParts = parse_url($this->getFullUrl()); |
|
| 110 | + $url2 = ""; |
|
| 111 | + $req = [$this->getMethod(), |
|
| 112 | + $urlParts['host'], |
|
| 113 | + "443", |
|
| 114 | + $urlParts['path'], |
|
| 115 | + $payload_accessToken, |
|
| 116 | + $timestamp, |
|
| 117 | + $url2, |
|
| 118 | + $this->payLoad]; |
|
| 119 | + $reqString = implode("%", $req); |
|
| 120 | + $secret = self::SECRET; |
|
| 121 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
| 122 | + $signature = strtoupper($signature); |
|
| 123 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
| 124 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
| 125 | + $headers['X-Timestamp'] = $timestamp; |
|
| 126 | + $headers['X-Api-Version'] = '0.2'; |
|
| 127 | + return $headers; |
|
| 128 | + } |
|
| 129 | + private function getFullUrl() |
|
| 130 | + { |
|
| 131 | + return self::APIURL . $this->getApiEndPoint(); |
|
| 132 | + } |
|
| 133 | + abstract function getApiEndPoint(); |
|
| 134 | + abstract function getMethod(); |
|
| 135 | + /** |
|
| 136 | + * @return string |
|
| 137 | + */ |
|
| 138 | + private function getAccessToken() |
|
| 139 | + { |
|
| 140 | + return $this->accessToken; |
|
| 141 | + } |
|
| 142 | + /** |
|
| 143 | + * @param string $accessToken |
|
| 144 | + */ |
|
| 145 | + public function setAccessToken($accessToken) |
|
| 146 | + { |
|
| 147 | + $this->accessToken = $accessToken; |
|
| 148 | + } |
|
| 149 | 149 | } |