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