Completed
Push — master ( d48616...cb18b3 )
by mains
02:24
created
php/Requests/AbstractRequest.php 1 patch
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -2,22 +2,22 @@  discard block
 block discarded – undo
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';
5
+	const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26';
6
+	const APIURL = 'https://api.go-tellm.com/api';
7 7
 
8
-    const SECRET = 'FYRQOjgJpZHvfbuseuJHLGPCZxzCreTTjekmUdsT';
9
-    const USERAGENT = 'Jodel/4.48.0 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
10
-    const CLIENT_TYPE = 'android_4.48.0';
8
+	const SECRET = 'FYRQOjgJpZHvfbuseuJHLGPCZxzCreTTjekmUdsT';
9
+	const USERAGENT = 'Jodel/4.48.0 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
10
+	const CLIENT_TYPE = 'android_4.48.0';
11 11
     
12
-    private $accessToken = null;
13
-    private $payLoad;
14
-    public $expects = '';
15
-    public $version = 'v2';
16
-    public $hasPayload = FALSE;
17
-
18
-    public function execute()
19
-    {
20
-        $result = new \stdClass();
12
+	private $accessToken = null;
13
+	private $payLoad;
14
+	public $expects = '';
15
+	public $version = 'v2';
16
+	public $hasPayload = FALSE;
17
+
18
+	public function execute()
19
+	{
20
+		$result = new \stdClass();
21 21
 		        
22 22
 		$this->payLoad = $this->getPayload();
23 23
 		$device_uid = '';
@@ -26,16 +26,16 @@  discard block
 block discarded – undo
26 26
 		}
27 27
 				
28 28
 				
29
-        $this->payLoad = json_encode($this->payLoad);
30
-        $header = $this->getSignHeaders();
31
-        $url = $this->getFullUrl();
29
+		$this->payLoad = json_encode($this->payLoad);
30
+		$header = $this->getSignHeaders();
31
+		$url = $this->getFullUrl();
32 32
 
33
-        if ($this->getAccessToken()) {
34
-            $header['Authorization'] = "Bearer " . $this->getAccessToken();
35
-        }
36
-        //Comment out to debug the Request:
33
+		if ($this->getAccessToken()) {
34
+			$header['Authorization'] = "Bearer " . $this->getAccessToken();
35
+		}
36
+		//Comment out to debug the Request:
37 37
 
38
-        /*
38
+		/*
39 39
         printf("URL: ");
40 40
         var_dump($url);
41 41
         echo "<br />";
@@ -46,134 +46,134 @@  discard block
 block discarded – undo
46 46
         var_dump($this->payLoad);
47 47
         echo "<br />";
48 48
         */
49
-        /*
49
+		/*
50 50
         $options = array(
51 51
             'timeout' => 100,
52 52
             'connect_timeout' => 100,
53 53
             'proxy' => '186.103.169.165:8080',
54 54
         );*/
55 55
 
56
-        switch ($this->getMethod()) {
57
-            case 'POST':
58
-                $result = Requests::post($url, $header, $this->payLoad);
59
-                break;
60
-            case 'GET':
61
-                if($this->hasPayload)
62
-                {
63
-                    $result = Requests::get($url, $header, $this->payLoad);
64
-                }
65
-                else
66
-                {
67
-                    $result = Requests::get($url, $header);
68
-                }
69
-                break;
70
-            case 'PUT':
71
-                $result = Requests::put($url, $header, $this->payLoad);
72
-                break;
73
-        }
74
-
75
-        http_response_code($result->status_code);
76
-
77
-        switch ($result->status_code) {
78
-            case 200:
79
-                $result = json_decode($result->body, true);
80
-                break;
81
-            case 204:
82
-                $result = 'Success';
83
-                http_response_code(200);
84
-                break;
85
-            case 400:
86
-                $result = json_decode($result->body, true);
87
-                error_log('Error 400 - ' . print_r($result, true));
88
-                break;
89
-            case 401:
90
-
91
-                if($result == "Unauthorized")
92
-                {
93
-                    error_log("Error 401: Unauthorized");
94
-                }
95
-                else
96
-                {
97
-                    $result = json_decode($result->body, true);
98
-
99
-                    if(is_array($result) && $result['error'] == 'length')
100
-                    {
101
-
102
-                    }
103
-                    else
104
-                    {
105
-                        error_log('Error 401 - ' . print_r($result, true));
106
-                    }
107
-                }
108
-
109
-
110
-                break;
111
-            case 404:
112
-
113
-
114
-                error_log('Error 404 - ' . print_r($result, true));
115
-                $result = json_decode($result->body, true);
116
-
117
-                if(array_key_exists('error', $result) && $result['error'] == 'post_blocked')
118
-                {
119
-                    header('HTTP/1.0 404 Not Found');
120
-                    include('error-pages/404.php');
121
-                    exit();
122
-                }
123
-
124
-                break;
56
+		switch ($this->getMethod()) {
57
+			case 'POST':
58
+				$result = Requests::post($url, $header, $this->payLoad);
59
+				break;
60
+			case 'GET':
61
+				if($this->hasPayload)
62
+				{
63
+					$result = Requests::get($url, $header, $this->payLoad);
64
+				}
65
+				else
66
+				{
67
+					$result = Requests::get($url, $header);
68
+				}
69
+				break;
70
+			case 'PUT':
71
+				$result = Requests::put($url, $header, $this->payLoad);
72
+				break;
73
+		}
74
+
75
+		http_response_code($result->status_code);
76
+
77
+		switch ($result->status_code) {
78
+			case 200:
79
+				$result = json_decode($result->body, true);
80
+				break;
81
+			case 204:
82
+				$result = 'Success';
83
+				http_response_code(200);
84
+				break;
85
+			case 400:
86
+				$result = json_decode($result->body, true);
87
+				error_log('Error 400 - ' . print_r($result, true));
88
+				break;
89
+			case 401:
90
+
91
+				if($result == "Unauthorized")
92
+				{
93
+					error_log("Error 401: Unauthorized");
94
+				}
95
+				else
96
+				{
97
+					$result = json_decode($result->body, true);
98
+
99
+					if(is_array($result) && $result['error'] == 'length')
100
+					{
101
+
102
+					}
103
+					else
104
+					{
105
+						error_log('Error 401 - ' . print_r($result, true));
106
+					}
107
+				}
108
+
109
+
110
+				break;
111
+			case 404:
112
+
113
+
114
+				error_log('Error 404 - ' . print_r($result, true));
115
+				$result = json_decode($result->body, true);
116
+
117
+				if(array_key_exists('error', $result) && $result['error'] == 'post_blocked')
118
+				{
119
+					header('HTTP/1.0 404 Not Found');
120
+					include('error-pages/404.php');
121
+					exit();
122
+				}
123
+
124
+				break;
125 125
 			case 477:
126
-                $result = json_decode($result->body, true);
127
-                error_log('Error 477 - ' . print_r($result, true));
128
-                break;
129
-            case 429:
130
-                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
131
-            	exit("Error 429: Too Many Requests");
132
-            	break;
133
-            case 403:
134
-                error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
135
-                $result = json_decode($result->body, true);
136
-                break;
137
-            case 502:
138
-                error_log('Error 502 - ' . print_r($result, true));
139
-                $result = json_decode($result->body, true);
140
-                header('location:'.$_SERVER['PHP_SELF']);
141
-                break;
142
-            case 503:
143
-                error_log('Error 503 - ' . print_r($result, true));
144
-                $result = json_decode($result->body, true);
145
-
146
-                if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable')
147
-                {
148
-                    header('location:'.$_SERVER['PHP_SELF']); 
149
-                }
150
-                break;
151
-            default:
152
-                error_log('Error '.$result->status_code.' - unknown error');
153
-                $result = json_decode($result->body, true);
154
-        }
155
-
156
-        //important for account refresh
157
-        if($device_uid != '')
158
-        {
126
+				$result = json_decode($result->body, true);
127
+				error_log('Error 477 - ' . print_r($result, true));
128
+				break;
129
+			case 429:
130
+				error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
131
+				exit("Error 429: Too Many Requests");
132
+				break;
133
+			case 403:
134
+				error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
135
+				$result = json_decode($result->body, true);
136
+				break;
137
+			case 502:
138
+				error_log('Error 502 - ' . print_r($result, true));
139
+				$result = json_decode($result->body, true);
140
+				header('location:'.$_SERVER['PHP_SELF']);
141
+				break;
142
+			case 503:
143
+				error_log('Error 503 - ' . print_r($result, true));
144
+				$result = json_decode($result->body, true);
145
+
146
+				if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable')
147
+				{
148
+					header('location:'.$_SERVER['PHP_SELF']); 
149
+				}
150
+				break;
151
+			default:
152
+				error_log('Error '.$result->status_code.' - unknown error');
153
+				$result = json_decode($result->body, true);
154
+		}
155
+
156
+		//important for account refresh
157
+		if($device_uid != '')
158
+		{
159 159
 			$result[0] = $result;
160 160
 			$result[1] = $device_uid;
161
-        }
161
+		}
162 162
 
163 163
         
164
-        /*
164
+		/*
165 165
         var_dump($result);
166 166
         */
167 167
         
168
-        return $result;
169
-    }
170
-    abstract function getPayload();
171
-    /**
172
-     * Gets Sign headers
173
-     * @return array headers
174
-     */
175
-    private function getSignHeaders()
176
-    {
168
+		return $result;
169
+	}
170
+	abstract function getPayload();
171
+	/**
172
+	 * Gets Sign headers
173
+	 * @return array headers
174
+	 */
175
+	private function getSignHeaders()
176
+	{
177 177
 			if($this->getAccessToken() == null) {
178 178
 				$payload_accessToken = "";
179 179
 			}
@@ -182,54 +182,54 @@  discard block
 block discarded – undo
182 182
 			}
183 183
 			
184 184
 			
185
-        $headers = array(
186
-            "Connection" => "keep-alive",
187
-            "Accept-Encoding" => "gzip",
188
-            "Content-Type" => "application/json; charset=UTF-8",
189
-            "User-Agent" => self::USERAGENT
190
-        );
191
-        $timestamp = new DateTime();
192
-        $timestamp = $timestamp->format(DateTime::ATOM);
193
-        $timestamp = substr($timestamp, 0, -6);
194
-        $timestamp .= "Z";
195
-        $urlParts = parse_url($this->getFullUrl());
196
-        $url2 = "";
197
-        $req = [$this->getMethod(),
198
-            $urlParts['host'],
199
-            "443",
200
-            $urlParts['path'],
201
-            $payload_accessToken,
202
-            $timestamp,
203
-            $url2,
204
-            $this->payLoad];
205
-        $reqString = implode("%", $req);
206
-        $secret = self::SECRET;
207
-        $signature = hash_hmac('sha1', $reqString, $secret);
208
-        $signature = strtoupper($signature);
209
-        $headers['X-Authorization'] = 'HMAC ' . $signature;
210
-        $headers['X-Client-Type'] = self::CLIENT_TYPE;
211
-        $headers['X-Timestamp'] = $timestamp;
212
-        $headers['X-Api-Version'] = '0.2';
213
-        return $headers;
214
-    }
215
-    private function getFullUrl()
216
-    {
217
-        return self::APIURL . $this->getApiEndPoint();
218
-    }
219
-    abstract function getApiEndPoint();
220
-    abstract function getMethod();
221
-    /**
222
-     * @return string
223
-     */
224
-    private function getAccessToken()
225
-    {
226
-        return $this->accessToken;
227
-    }
228
-    /**
229
-     * @param string $accessToken
230
-     */
231
-    public function setAccessToken($accessToken)
232
-    {
233
-        $this->accessToken = $accessToken;
234
-    }
185
+		$headers = array(
186
+			"Connection" => "keep-alive",
187
+			"Accept-Encoding" => "gzip",
188
+			"Content-Type" => "application/json; charset=UTF-8",
189
+			"User-Agent" => self::USERAGENT
190
+		);
191
+		$timestamp = new DateTime();
192
+		$timestamp = $timestamp->format(DateTime::ATOM);
193
+		$timestamp = substr($timestamp, 0, -6);
194
+		$timestamp .= "Z";
195
+		$urlParts = parse_url($this->getFullUrl());
196
+		$url2 = "";
197
+		$req = [$this->getMethod(),
198
+			$urlParts['host'],
199
+			"443",
200
+			$urlParts['path'],
201
+			$payload_accessToken,
202
+			$timestamp,
203
+			$url2,
204
+			$this->payLoad];
205
+		$reqString = implode("%", $req);
206
+		$secret = self::SECRET;
207
+		$signature = hash_hmac('sha1', $reqString, $secret);
208
+		$signature = strtoupper($signature);
209
+		$headers['X-Authorization'] = 'HMAC ' . $signature;
210
+		$headers['X-Client-Type'] = self::CLIENT_TYPE;
211
+		$headers['X-Timestamp'] = $timestamp;
212
+		$headers['X-Api-Version'] = '0.2';
213
+		return $headers;
214
+	}
215
+	private function getFullUrl()
216
+	{
217
+		return self::APIURL . $this->getApiEndPoint();
218
+	}
219
+	abstract function getApiEndPoint();
220
+	abstract function getMethod();
221
+	/**
222
+	 * @return string
223
+	 */
224
+	private function getAccessToken()
225
+	{
226
+		return $this->accessToken;
227
+	}
228
+	/**
229
+	 * @param string $accessToken
230
+	 */
231
+	public function setAccessToken($accessToken)
232
+	{
233
+		$this->accessToken = $accessToken;
234
+	}
235 235
 }
Please login to merge, or discard this patch.