Completed
Push — master ( d48616...cb18b3 )
by mains
02:24
created
php/Requests/AbstractRequest.php 3 patches
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.
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
 
@@ -21,7 +21,8 @@  discard block
 block discarded – undo
21 21
 		        
22 22
 		$this->payLoad = $this->getPayload();
23 23
 		$device_uid = '';
24
-		if(isset($this->payLoad['device_uid'])) {
24
+		if(isset($this->payLoad['device_uid']))
25
+		{
25 26
 			$device_uid = $this->payLoad['device_uid'];
26 27
 		}
27 28
 				
@@ -30,7 +31,8 @@  discard block
 block discarded – undo
30 31
         $header = $this->getSignHeaders();
31 32
         $url = $this->getFullUrl();
32 33
 
33
-        if ($this->getAccessToken()) {
34
+        if ($this->getAccessToken())
35
+        {
34 36
             $header['Authorization'] = "Bearer " . $this->getAccessToken();
35 37
         }
36 38
         //Comment out to debug the Request:
@@ -53,7 +55,8 @@  discard block
 block discarded – undo
53 55
             'proxy' => '186.103.169.165:8080',
54 56
         );*/
55 57
 
56
-        switch ($this->getMethod()) {
58
+        switch ($this->getMethod())
59
+        {
57 60
             case 'POST':
58 61
                 $result = Requests::post($url, $header, $this->payLoad);
59 62
                 break;
@@ -74,7 +77,8 @@  discard block
 block discarded – undo
74 77
 
75 78
         http_response_code($result->status_code);
76 79
 
77
-        switch ($result->status_code) {
80
+        switch ($result->status_code)
81
+        {
78 82
             case 200:
79 83
                 $result = json_decode($result->body, true);
80 84
                 break;
@@ -174,10 +178,12 @@  discard block
 block discarded – undo
174 178
      */
175 179
     private function getSignHeaders()
176 180
     {
177
-			if($this->getAccessToken() == null) {
181
+			if($this->getAccessToken() == null)
182
+			{
178 183
 				$payload_accessToken = "";
179 184
 			}
180
-			else {
185
+			else
186
+			{
181 187
 				$payload_accessToken = $this->getAccessToken();
182 188
 			}
183 189
 			
Please login to merge, or discard this patch.
Upper-Lower-Casing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
     const USERAGENT = 'Jodel/4.48.0 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
10 10
     const CLIENT_TYPE = 'android_4.48.0';
11 11
     
12
-    private $accessToken = null;
12
+    private $accessToken = NULL;
13 13
     private $payLoad;
14 14
     public $expects = '';
15 15
     public $version = 'v2';
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
 
77 77
         switch ($result->status_code) {
78 78
             case 200:
79
-                $result = json_decode($result->body, true);
79
+                $result = json_decode($result->body, TRUE);
80 80
                 break;
81 81
             case 204:
82 82
                 $result = 'Success';
83 83
                 http_response_code(200);
84 84
                 break;
85 85
             case 400:
86
-                $result = json_decode($result->body, true);
87
-                error_log('Error 400 - ' . print_r($result, true));
86
+                $result = json_decode($result->body, TRUE);
87
+                error_log('Error 400 - ' . print_r($result, TRUE));
88 88
                 break;
89 89
             case 401:
90 90
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
                 }
95 95
                 else
96 96
                 {
97
-                    $result = json_decode($result->body, true);
97
+                    $result = json_decode($result->body, TRUE);
98 98
 
99 99
                     if(is_array($result) && $result['error'] == 'length')
100 100
                     {
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
                     }
103 103
                     else
104 104
                     {
105
-                        error_log('Error 401 - ' . print_r($result, true));
105
+                        error_log('Error 401 - ' . print_r($result, TRUE));
106 106
                     }
107 107
                 }
108 108
 
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
             case 404:
112 112
 
113 113
 
114
-                error_log('Error 404 - ' . print_r($result, true));
115
-                $result = json_decode($result->body, true);
114
+                error_log('Error 404 - ' . print_r($result, TRUE));
115
+                $result = json_decode($result->body, TRUE);
116 116
 
117 117
                 if(array_key_exists('error', $result) && $result['error'] == 'post_blocked')
118 118
                 {
@@ -123,25 +123,25 @@  discard block
 block discarded – undo
123 123
 
124 124
                 break;
125 125
 			case 477:
126
-                $result = json_decode($result->body, true);
127
-                error_log('Error 477 - ' . print_r($result, true));
126
+                $result = json_decode($result->body, TRUE);
127
+                error_log('Error 477 - ' . print_r($result, TRUE));
128 128
                 break;
129 129
             case 429:
130
-                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
130
+                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, TRUE), TRUE));
131 131
             	exit("Error 429: Too Many Requests");
132 132
             	break;
133 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);
134
+                error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, TRUE), TRUE));
135
+                $result = json_decode($result->body, TRUE);
136 136
                 break;
137 137
             case 502:
138
-                error_log('Error 502 - ' . print_r($result, true));
139
-                $result = json_decode($result->body, true);
138
+                error_log('Error 502 - ' . print_r($result, TRUE));
139
+                $result = json_decode($result->body, TRUE);
140 140
                 header('location:'.$_SERVER['PHP_SELF']);
141 141
                 break;
142 142
             case 503:
143
-                error_log('Error 503 - ' . print_r($result, true));
144
-                $result = json_decode($result->body, true);
143
+                error_log('Error 503 - ' . print_r($result, TRUE));
144
+                $result = json_decode($result->body, TRUE);
145 145
 
146 146
                 if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable')
147 147
                 {
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
                 break;
151 151
             default:
152 152
                 error_log('Error '.$result->status_code.' - unknown error');
153
-                $result = json_decode($result->body, true);
153
+                $result = json_decode($result->body, TRUE);
154 154
         }
155 155
 
156 156
         //important for account refresh
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      */
175 175
     private function getSignHeaders()
176 176
     {
177
-			if($this->getAccessToken() == null) {
177
+			if($this->getAccessToken() == NULL) {
178 178
 				$payload_accessToken = "";
179 179
 			}
180 180
 			else {
Please login to merge, or discard this patch.