Completed
Push — master ( 411610...16e812 )
by mains
02:55
created
php/Requests/AbstractRequest.php 3 patches
Indentation   +166 added lines, -166 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 = 'bJYlFZkrnLpLMVisrbstPDNsaYHPbzcKRSpqtjtt';
8
-    const USERAGENT = 'Jodel/4.42.4 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
-    const CLIENT_TYPE = 'android_4.42.4';
5
+	const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26';
6
+	const APIURL = 'https://api.go-tellm.com/api';
7
+	const SECRET = 'bJYlFZkrnLpLMVisrbstPDNsaYHPbzcKRSpqtjtt';
8
+	const USERAGENT = 'Jodel/4.42.4 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
+	const CLIENT_TYPE = 'android_4.42.4';
10 10
     
11
-    private $accessToken = null;
12
-    private $payLoad;
13
-    public $expects = '';
14
-    public $version = 'v2';
15
-    public $hasPayload = FALSE;
11
+	private $accessToken = null;
12
+	private $payLoad;
13
+	public $expects = '';
14
+	public $version = 'v2';
15
+	public $hasPayload = FALSE;
16 16
 
17
-    public function execute()
18
-    {
19
-        $result = new \stdClass();
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,124 +45,124 @@  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
-        }
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 73
 
74
-        http_response_code($result->status_code);
74
+		http_response_code($result->status_code);
75 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:
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 89
 
90
-                if($result == "Unauthorized")
91
-                {
92
-                    error_log("Error 401: Unauthorized");
93
-                }
94
-                else
95
-                {
96
-                    $result = json_decode($result->body, true);
90
+				if($result == "Unauthorized")
91
+				{
92
+					error_log("Error 401: Unauthorized");
93
+				}
94
+				else
95
+				{
96
+					$result = json_decode($result->body, true);
97 97
 
98
-                    if(is_array($result) && $result['error'] == 'length')
99
-                    {
98
+					if(is_array($result) && $result['error'] == 'length')
99
+					{
100 100
 
101
-                    }
102
-                    else
103
-                    {
104
-                        error_log('Error 401 - ' . print_r($result, true));
105
-                    }
106
-                }
101
+					}
102
+					else
103
+					{
104
+						error_log('Error 401 - ' . print_r($result, true));
105
+					}
106
+				}
107 107
 
108 108
 
109
-                break;
110
-            case 404:
111
-                error_log('Error 404 - ' . print_r($result, true));
112
-                $result = json_decode($result->body, true);
113
-                break;
109
+				break;
110
+			case 404:
111
+				error_log('Error 404 - ' . print_r($result, true));
112
+				$result = json_decode($result->body, true);
113
+				break;
114 114
 			case 477:
115
-                $result = json_decode($result->body, true);
116
-                error_log('Error 477 - ' . print_r($result, true));
117
-                break;
118
-            case 429:
119
-                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
120
-            	exit("Error 429: Too Many Requests");
121
-            	break;
122
-            case 403:
123
-                error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
124
-                $result = json_decode($result->body, true);
125
-                break;
126
-            case 502:
127
-                error_log('Error 502 - ' . print_r($result, true));
128
-                $result = json_decode($result->body, true);
129
-                header('location:'.$_SERVER['PHP_SELF']);
130
-                break;
131
-            case 503:
132
-                error_log('Error 503 - ' . print_r($result, true));
133
-                $result = json_decode($result->body, true);
115
+				$result = json_decode($result->body, true);
116
+				error_log('Error 477 - ' . print_r($result, true));
117
+				break;
118
+			case 429:
119
+				error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
120
+				exit("Error 429: Too Many Requests");
121
+				break;
122
+			case 403:
123
+				error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
124
+				$result = json_decode($result->body, true);
125
+				break;
126
+			case 502:
127
+				error_log('Error 502 - ' . print_r($result, true));
128
+				$result = json_decode($result->body, true);
129
+				header('location:'.$_SERVER['PHP_SELF']);
130
+				break;
131
+			case 503:
132
+				error_log('Error 503 - ' . print_r($result, true));
133
+				$result = json_decode($result->body, true);
134 134
 
135
-                if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable')
136
-                {
137
-                    header('location:'.$_SERVER['PHP_SELF']); 
138
-                }
139
-                break;
140
-            default:
141
-                error_log('Error '.$result->status_code.' - unknown error');
142
-                $result = json_decode($result->body, true);
143
-        }
135
+				if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable')
136
+				{
137
+					header('location:'.$_SERVER['PHP_SELF']); 
138
+				}
139
+				break;
140
+			default:
141
+				error_log('Error '.$result->status_code.' - unknown error');
142
+				$result = json_decode($result->body, true);
143
+		}
144 144
 
145
-        //important for account refresh
146
-        if($device_uid != '')
147
-        {
145
+		//important for account refresh
146
+		if($device_uid != '')
147
+		{
148 148
 			$result[0] = $result;
149 149
 			$result[1] = $device_uid;
150
-        }
150
+		}
151 151
 
152 152
         
153
-        /*
153
+		/*
154 154
         var_dump($result);
155 155
         */
156 156
         
157
-        return $result;
158
-    }
159
-    abstract function getPayload();
160
-    /**
161
-     * Gets Sign headers
162
-     * @return array headers
163
-     */
164
-    private function getSignHeaders()
165
-    {
157
+		return $result;
158
+	}
159
+	abstract function getPayload();
160
+	/**
161
+	 * Gets Sign headers
162
+	 * @return array headers
163
+	 */
164
+	private function getSignHeaders()
165
+	{
166 166
 			if($this->getAccessToken() == null) {
167 167
 				$payload_accessToken = "";
168 168
 			}
@@ -171,54 +171,54 @@  discard block
 block discarded – undo
171 171
 			}
172 172
 			
173 173
 			
174
-        $headers = array(
175
-            "Connection" => "keep-alive",
176
-            "Accept-Encoding" => "gzip",
177
-            "Content-Type" => "application/json; charset=UTF-8",
178
-            "User-Agent" => self::USERAGENT
179
-        );
180
-        $timestamp = new DateTime();
181
-        $timestamp = $timestamp->format(DateTime::ATOM);
182
-        $timestamp = substr($timestamp, 0, -6);
183
-        $timestamp .= "Z";
184
-        $urlParts = parse_url($this->getFullUrl());
185
-        $url2 = "";
186
-        $req = [$this->getMethod(),
187
-            $urlParts['host'],
188
-            "443",
189
-            $urlParts['path'],
190
-            $payload_accessToken,
191
-            $timestamp,
192
-            $url2,
193
-            $this->payLoad];
194
-        $reqString = implode("%", $req);
195
-        $secret = self::SECRET;
196
-        $signature = hash_hmac('sha1', $reqString, $secret);
197
-        $signature = strtoupper($signature);
198
-        $headers['X-Authorization'] = 'HMAC ' . $signature;
199
-        $headers['X-Client-Type'] = self::CLIENT_TYPE;
200
-        $headers['X-Timestamp'] = $timestamp;
201
-        $headers['X-Api-Version'] = '0.2';
202
-        return $headers;
203
-    }
204
-    private function getFullUrl()
205
-    {
206
-        return self::APIURL . $this->getApiEndPoint();
207
-    }
208
-    abstract function getApiEndPoint();
209
-    abstract function getMethod();
210
-    /**
211
-     * @return string
212
-     */
213
-    private function getAccessToken()
214
-    {
215
-        return $this->accessToken;
216
-    }
217
-    /**
218
-     * @param string $accessToken
219
-     */
220
-    public function setAccessToken($accessToken)
221
-    {
222
-        $this->accessToken = $accessToken;
223
-    }
174
+		$headers = array(
175
+			"Connection" => "keep-alive",
176
+			"Accept-Encoding" => "gzip",
177
+			"Content-Type" => "application/json; charset=UTF-8",
178
+			"User-Agent" => self::USERAGENT
179
+		);
180
+		$timestamp = new DateTime();
181
+		$timestamp = $timestamp->format(DateTime::ATOM);
182
+		$timestamp = substr($timestamp, 0, -6);
183
+		$timestamp .= "Z";
184
+		$urlParts = parse_url($this->getFullUrl());
185
+		$url2 = "";
186
+		$req = [$this->getMethod(),
187
+			$urlParts['host'],
188
+			"443",
189
+			$urlParts['path'],
190
+			$payload_accessToken,
191
+			$timestamp,
192
+			$url2,
193
+			$this->payLoad];
194
+		$reqString = implode("%", $req);
195
+		$secret = self::SECRET;
196
+		$signature = hash_hmac('sha1', $reqString, $secret);
197
+		$signature = strtoupper($signature);
198
+		$headers['X-Authorization'] = 'HMAC ' . $signature;
199
+		$headers['X-Client-Type'] = self::CLIENT_TYPE;
200
+		$headers['X-Timestamp'] = $timestamp;
201
+		$headers['X-Api-Version'] = '0.2';
202
+		return $headers;
203
+	}
204
+	private function getFullUrl()
205
+	{
206
+		return self::APIURL . $this->getApiEndPoint();
207
+	}
208
+	abstract function getApiEndPoint();
209
+	abstract function getMethod();
210
+	/**
211
+	 * @return string
212
+	 */
213
+	private function getAccessToken()
214
+	{
215
+		return $this->accessToken;
216
+	}
217
+	/**
218
+	 * @param string $accessToken
219
+	 */
220
+	public function setAccessToken($accessToken)
221
+	{
222
+		$this->accessToken = $accessToken;
223
+	}
224 224
 }
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 = 'bJYlFZkrnLpLMVisrbstPDNsaYHPbzcKRSpqtjtt';
@@ -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;
@@ -163,10 +167,12 @@  discard block
 block discarded – undo
163 167
      */
164 168
     private function getSignHeaders()
165 169
     {
166
-			if($this->getAccessToken() == null) {
170
+			if($this->getAccessToken() == null)
171
+			{
167 172
 				$payload_accessToken = "";
168 173
 			}
169
-			else {
174
+			else
175
+			{
170 176
 				$payload_accessToken = $this->getAccessToken();
171 177
 			}
172 178
 			
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.42.4 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9 9
     const CLIENT_TYPE = 'android_4.42.4';
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,36 +101,36 @@  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
 
108 108
 
109 109
                 break;
110 110
             case 404:
111
-                error_log('Error 404 - ' . print_r($result, true));
112
-                $result = json_decode($result->body, true);
111
+                error_log('Error 404 - ' . print_r($result, TRUE));
112
+                $result = json_decode($result->body, TRUE);
113 113
                 break;
114 114
 			case 477:
115
-                $result = json_decode($result->body, true);
116
-                error_log('Error 477 - ' . print_r($result, true));
115
+                $result = json_decode($result->body, TRUE);
116
+                error_log('Error 477 - ' . print_r($result, TRUE));
117 117
                 break;
118 118
             case 429:
119
-                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
119
+                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, TRUE), TRUE));
120 120
             	exit("Error 429: Too Many Requests");
121 121
             	break;
122 122
             case 403:
123
-                error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
124
-                $result = json_decode($result->body, true);
123
+                error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, TRUE), TRUE));
124
+                $result = json_decode($result->body, TRUE);
125 125
                 break;
126 126
             case 502:
127
-                error_log('Error 502 - ' . print_r($result, true));
128
-                $result = json_decode($result->body, true);
127
+                error_log('Error 502 - ' . print_r($result, TRUE));
128
+                $result = json_decode($result->body, TRUE);
129 129
                 header('location:'.$_SERVER['PHP_SELF']);
130 130
                 break;
131 131
             case 503:
132
-                error_log('Error 503 - ' . print_r($result, true));
133
-                $result = json_decode($result->body, true);
132
+                error_log('Error 503 - ' . print_r($result, TRUE));
133
+                $result = json_decode($result->body, TRUE);
134 134
 
135 135
                 if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable')
136 136
                 {
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
                 break;
140 140
             default:
141 141
                 error_log('Error '.$result->status_code.' - unknown error');
142
-                $result = json_decode($result->body, true);
142
+                $result = json_decode($result->body, TRUE);
143 143
         }
144 144
 
145 145
         //important for account refresh
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      */
164 164
     private function getSignHeaders()
165 165
     {
166
-			if($this->getAccessToken() == null) {
166
+			if($this->getAccessToken() == NULL) {
167 167
 				$payload_accessToken = "";
168 168
 			}
169 169
 			else {
Please login to merge, or discard this patch.