@@ -2,19 +2,19 @@ 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.29.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.29.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 = ""; |
|
14 | - public $version = 'v2'; |
|
11 | + private $accessToken = null; |
|
12 | + private $payLoad; |
|
13 | + public $expects = ""; |
|
14 | + public $version = 'v2'; |
|
15 | 15 | |
16 | - public function execute() |
|
17 | - { |
|
16 | + public function execute() |
|
17 | + { |
|
18 | 18 | $result = new \stdClass(); |
19 | 19 | |
20 | 20 | $this->payLoad = $this->getPayload(); |
@@ -24,78 +24,78 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | |
27 | - $this->payLoad = json_encode($this->payLoad); |
|
28 | - $header = $this->getSignHeaders(); |
|
29 | - $url = $this->getFullUrl(); |
|
27 | + $this->payLoad = json_encode($this->payLoad); |
|
28 | + $header = $this->getSignHeaders(); |
|
29 | + $url = $this->getFullUrl(); |
|
30 | 30 | |
31 | - if ($this->getAccessToken()) { |
|
32 | - $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
33 | - } |
|
34 | - //Comment out to debug the Request: |
|
35 | - /* |
|
31 | + if ($this->getAccessToken()) { |
|
32 | + $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
33 | + } |
|
34 | + //Comment out to debug the Request: |
|
35 | + /* |
|
36 | 36 | var_dump($url); |
37 | 37 | var_dump($header); |
38 | 38 | var_dump($this->payLoad); |
39 | 39 | */ |
40 | 40 | |
41 | 41 | |
42 | - switch ($this->getMethod()) { |
|
43 | - case 'POST': |
|
44 | - $result = Requests::post($url, $header, $this->payLoad); |
|
45 | - break; |
|
46 | - case 'GET': |
|
47 | - if($this->version == 'v3') |
|
48 | - { |
|
49 | - $result = Requests::get($url, $header); |
|
50 | - } |
|
51 | - else |
|
52 | - { |
|
53 | - $result = Requests::get($url, $header); |
|
54 | - } |
|
55 | - break; |
|
56 | - case 'PUT': |
|
57 | - $result = Requests::put($url, $header, $this->payLoad); |
|
58 | - break; |
|
59 | - } |
|
60 | - switch ($result->status_code) { |
|
61 | - case 200: |
|
62 | - $result = json_decode($result->body, true); |
|
63 | - break; |
|
64 | - case 204: |
|
65 | - $result = "Success"; |
|
66 | - break; |
|
67 | - case 401: |
|
42 | + switch ($this->getMethod()) { |
|
43 | + case 'POST': |
|
44 | + $result = Requests::post($url, $header, $this->payLoad); |
|
45 | + break; |
|
46 | + case 'GET': |
|
47 | + if($this->version == 'v3') |
|
48 | + { |
|
49 | + $result = Requests::get($url, $header); |
|
50 | + } |
|
51 | + else |
|
52 | + { |
|
53 | + $result = Requests::get($url, $header); |
|
54 | + } |
|
55 | + break; |
|
56 | + case 'PUT': |
|
57 | + $result = Requests::put($url, $header, $this->payLoad); |
|
58 | + break; |
|
59 | + } |
|
60 | + switch ($result->status_code) { |
|
61 | + case 200: |
|
62 | + $result = json_decode($result->body, true); |
|
63 | + break; |
|
64 | + case 204: |
|
65 | + $result = "Success"; |
|
66 | + break; |
|
67 | + case 401: |
|
68 | 68 | throw new \Exception('Unauthorized'); |
69 | - break; |
|
70 | - case 404: |
|
71 | - //echo "Es wurde bereits gevoted"; |
|
69 | + break; |
|
70 | + case 404: |
|
71 | + //echo "Es wurde bereits gevoted"; |
|
72 | 72 | case 477: |
73 | - //echo "Es wurde bereits gevoted"; |
|
74 | - //throw new \Exception('Signing failed!'); |
|
75 | - break; |
|
76 | - default: |
|
77 | - throw new \Exception('Unknown Error: '.$result->status_code); |
|
78 | - } |
|
73 | + //echo "Es wurde bereits gevoted"; |
|
74 | + //throw new \Exception('Signing failed!'); |
|
75 | + break; |
|
76 | + default: |
|
77 | + throw new \Exception('Unknown Error: '.$result->status_code); |
|
78 | + } |
|
79 | 79 | |
80 | - if($device_uid != "") |
|
81 | - { |
|
80 | + if($device_uid != "") |
|
81 | + { |
|
82 | 82 | $result[0] = $result; |
83 | 83 | $result[1] = $device_uid; |
84 | 84 | } |
85 | 85 | |
86 | - /* |
|
86 | + /* |
|
87 | 87 | var_dump($result); |
88 | 88 | */ |
89 | 89 | |
90 | - return $result; |
|
91 | - } |
|
92 | - abstract function getPayload(); |
|
93 | - /** |
|
94 | - * Gets Sign headers |
|
95 | - * @return array headers |
|
96 | - */ |
|
97 | - private function getSignHeaders() |
|
98 | - { |
|
90 | + return $result; |
|
91 | + } |
|
92 | + abstract function getPayload(); |
|
93 | + /** |
|
94 | + * Gets Sign headers |
|
95 | + * @return array headers |
|
96 | + */ |
|
97 | + private function getSignHeaders() |
|
98 | + { |
|
99 | 99 | if($this->getAccessToken() == null) { |
100 | 100 | $payload_accessToken = ""; |
101 | 101 | } |
@@ -104,54 +104,54 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | |
107 | - $headers = array( |
|
108 | - "Connection" => "keep-alive", |
|
109 | - "Accept-Encoding" => "gzip", |
|
110 | - "Content-Type" => "application/json; charset=UTF-8", |
|
111 | - "User-Agent" => self::USERAGENT |
|
112 | - ); |
|
113 | - $timestamp = new DateTime(); |
|
114 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
115 | - $timestamp = substr($timestamp, 0, -6); |
|
116 | - $timestamp .= "Z"; |
|
117 | - $urlParts = parse_url($this->getFullUrl()); |
|
118 | - $url2 = ""; |
|
119 | - $req = [$this->getMethod(), |
|
120 | - $urlParts['host'], |
|
121 | - "443", |
|
122 | - $urlParts['path'], |
|
123 | - $payload_accessToken, |
|
124 | - $timestamp, |
|
125 | - $url2, |
|
126 | - $this->payLoad]; |
|
127 | - $reqString = implode("%", $req); |
|
128 | - $secret = self::SECRET; |
|
129 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
130 | - $signature = strtoupper($signature); |
|
131 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
132 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
133 | - $headers['X-Timestamp'] = $timestamp; |
|
134 | - $headers['X-Api-Version'] = '0.2'; |
|
135 | - return $headers; |
|
136 | - } |
|
137 | - private function getFullUrl() |
|
138 | - { |
|
139 | - return self::APIURL . $this->getApiEndPoint(); |
|
140 | - } |
|
141 | - abstract function getApiEndPoint(); |
|
142 | - abstract function getMethod(); |
|
143 | - /** |
|
144 | - * @return string |
|
145 | - */ |
|
146 | - private function getAccessToken() |
|
147 | - { |
|
148 | - return $this->accessToken; |
|
149 | - } |
|
150 | - /** |
|
151 | - * @param string $accessToken |
|
152 | - */ |
|
153 | - public function setAccessToken($accessToken) |
|
154 | - { |
|
155 | - $this->accessToken = $accessToken; |
|
156 | - } |
|
107 | + $headers = array( |
|
108 | + "Connection" => "keep-alive", |
|
109 | + "Accept-Encoding" => "gzip", |
|
110 | + "Content-Type" => "application/json; charset=UTF-8", |
|
111 | + "User-Agent" => self::USERAGENT |
|
112 | + ); |
|
113 | + $timestamp = new DateTime(); |
|
114 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
115 | + $timestamp = substr($timestamp, 0, -6); |
|
116 | + $timestamp .= "Z"; |
|
117 | + $urlParts = parse_url($this->getFullUrl()); |
|
118 | + $url2 = ""; |
|
119 | + $req = [$this->getMethod(), |
|
120 | + $urlParts['host'], |
|
121 | + "443", |
|
122 | + $urlParts['path'], |
|
123 | + $payload_accessToken, |
|
124 | + $timestamp, |
|
125 | + $url2, |
|
126 | + $this->payLoad]; |
|
127 | + $reqString = implode("%", $req); |
|
128 | + $secret = self::SECRET; |
|
129 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
130 | + $signature = strtoupper($signature); |
|
131 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
132 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
133 | + $headers['X-Timestamp'] = $timestamp; |
|
134 | + $headers['X-Api-Version'] = '0.2'; |
|
135 | + return $headers; |
|
136 | + } |
|
137 | + private function getFullUrl() |
|
138 | + { |
|
139 | + return self::APIURL . $this->getApiEndPoint(); |
|
140 | + } |
|
141 | + abstract function getApiEndPoint(); |
|
142 | + abstract function getMethod(); |
|
143 | + /** |
|
144 | + * @return string |
|
145 | + */ |
|
146 | + private function getAccessToken() |
|
147 | + { |
|
148 | + return $this->accessToken; |
|
149 | + } |
|
150 | + /** |
|
151 | + * @param string $accessToken |
|
152 | + */ |
|
153 | + public function setAccessToken($accessToken) |
|
154 | + { |
|
155 | + $this->accessToken = $accessToken; |
|
156 | + } |
|
157 | 157 | } |
@@ -4,25 +4,25 @@ discard block |
||
4 | 4 | { |
5 | 5 | public $lastPostId; |
6 | 6 | |
7 | - /** |
|
8 | - * @var Location |
|
9 | - */ |
|
10 | - public $location; |
|
11 | - public $url; |
|
7 | + /** |
|
8 | + * @var Location |
|
9 | + */ |
|
10 | + public $location; |
|
11 | + public $url; |
|
12 | 12 | |
13 | 13 | |
14 | - function setUrl ($url) |
|
15 | - { |
|
16 | - $this->url = $url; |
|
17 | - } |
|
14 | + function setUrl ($url) |
|
15 | + { |
|
16 | + $this->url = $url; |
|
17 | + } |
|
18 | 18 | |
19 | - function getUrl () |
|
20 | - { |
|
21 | - return $this->url; |
|
22 | - } |
|
19 | + function getUrl () |
|
20 | + { |
|
21 | + return $this->url; |
|
22 | + } |
|
23 | 23 | |
24 | - function setLastPostId ($lastPostId) |
|
25 | - { |
|
24 | + function setLastPostId ($lastPostId) |
|
25 | + { |
|
26 | 26 | $this->lastPostId = $lastPostId; |
27 | 27 | } |
28 | 28 | |
@@ -31,38 +31,38 @@ discard block |
||
31 | 31 | return $this->lastPostId; |
32 | 32 | } |
33 | 33 | |
34 | - function getApiEndPoint() |
|
35 | - { |
|
36 | - $apiEndPoint = $this->getUrl(); |
|
34 | + function getApiEndPoint() |
|
35 | + { |
|
36 | + $apiEndPoint = $this->getUrl(); |
|
37 | 37 | |
38 | - if ($this->getLastPostId() != "") { |
|
38 | + if ($this->getLastPostId() != "") { |
|
39 | 39 | $apiEndPoint = $this->getUrl() . '?after=' . $this->getLastPostId(); |
40 | 40 | } |
41 | - return $apiEndPoint; |
|
42 | - } |
|
43 | - function getPayload() |
|
44 | - { |
|
45 | - if($this->version == 'v3') |
|
46 | - { |
|
47 | - $this->location = new Location(); |
|
48 | - $this->location->setLat(52.520006); |
|
49 | - $this->location->setLng(13.404954); |
|
50 | - $this->location->setCityName('Berlin'); |
|
41 | + return $apiEndPoint; |
|
42 | + } |
|
43 | + function getPayload() |
|
44 | + { |
|
45 | + if($this->version == 'v3') |
|
46 | + { |
|
47 | + $this->location = new Location(); |
|
48 | + $this->location->setLat(52.520006); |
|
49 | + $this->location->setLng(13.404954); |
|
50 | + $this->location->setCityName('Berlin'); |
|
51 | 51 | |
52 | 52 | |
53 | - return array( |
|
54 | - "location" => $this->location->toArray(), |
|
55 | - "stickies" => 'false', |
|
56 | - ); |
|
57 | - } |
|
58 | - else |
|
59 | - { |
|
60 | - return array( |
|
61 | - ); |
|
62 | - } |
|
63 | - } |
|
64 | - function getMethod() |
|
65 | - { |
|
66 | - return 'GET'; |
|
67 | - } |
|
53 | + return array( |
|
54 | + "location" => $this->location->toArray(), |
|
55 | + "stickies" => 'false', |
|
56 | + ); |
|
57 | + } |
|
58 | + else |
|
59 | + { |
|
60 | + return array( |
|
61 | + ); |
|
62 | + } |
|
63 | + } |
|
64 | + function getMethod() |
|
65 | + { |
|
66 | + return 'GET'; |
|
67 | + } |
|
68 | 68 | } |