Completed
Push — master ( 83518f...4b3242 )
by mains
02:59
created
php/Requests/AbstractRequest.php 2 patches
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -2,20 +2,20 @@  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 = 'SDydTnTdqqaiAMfneLkqXYxamvNuUYOmkqpdiZTu';
8
-    const USERAGENT = 'Jodel/4.34.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
-    const CLIENT_TYPE = 'android_4.34.2';
5
+	const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26';
6
+	const APIURL = 'https://api.go-tellm.com/api';
7
+	const SECRET = 'SDydTnTdqqaiAMfneLkqXYxamvNuUYOmkqpdiZTu';
8
+	const USERAGENT = 'Jodel/4.34.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
+	const CLIENT_TYPE = 'android_4.34.2';
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
-    {
17
+	public function execute()
18
+	{
19 19
 		$result = new \stdClass();
20 20
 		        
21 21
 		$this->payLoad = $this->getPayload();
@@ -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,85 +45,85 @@  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
-        switch ($result->status_code) {
74
-            case 200:
75
-                $result = json_decode($result->body, true);
76
-                break;
77
-            case 204:
78
-                $result = "Success";
79
-                break;
80
-            case 400:
81
-                error_log('Error 400 - Fehlerhafte Anfrage');
82
-                $result = json_decode($result->body, true);
83
-                break;
84
-            case 401:
85
-                error_log('Error 401 - Unauthorized');
86
-                $result = json_decode($result->body, true);
87
-                break;
88
-            case 404:
89
-                error_log('Error 404 - Es wurde bereits gevoted');
90
-                $result = json_decode($result->body, true);
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
+		switch ($result->status_code) {
74
+			case 200:
75
+				$result = json_decode($result->body, true);
76
+				break;
77
+			case 204:
78
+				$result = "Success";
79
+				break;
80
+			case 400:
81
+				error_log('Error 400 - Fehlerhafte Anfrage');
82
+				$result = json_decode($result->body, true);
83
+				break;
84
+			case 401:
85
+				error_log('Error 401 - Unauthorized');
86
+				$result = json_decode($result->body, true);
87
+				break;
88
+			case 404:
89
+				error_log('Error 404 - Es wurde bereits gevoted');
90
+				$result = json_decode($result->body, true);
91 91
 			case 477:
92
-                error_log('Error 477 - Signing failed');
93
-                $result = json_decode($result->body, true);
94
-                break;
95
-            case 429:
96
-                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
97
-            	exit("Error 429: Too Many Requests");
98
-            	break;
99
-            case 403:
100
-                error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
101
-                exit("Error 403: Access denied");
102
-                break;
103
-            default:
104
-                error_log('Error '.$result->status_code.' - Unauthorized');
105
-                $result = json_decode($result->body, true);
106
-        }
92
+				error_log('Error 477 - Signing failed');
93
+				$result = json_decode($result->body, true);
94
+				break;
95
+			case 429:
96
+				error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
97
+				exit("Error 429: Too Many Requests");
98
+				break;
99
+			case 403:
100
+				error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
101
+				exit("Error 403: Access denied");
102
+				break;
103
+			default:
104
+				error_log('Error '.$result->status_code.' - Unauthorized');
105
+				$result = json_decode($result->body, true);
106
+		}
107 107
 
108
-        //important for account refresh
109
-        if($device_uid != '')
110
-        {
108
+		//important for account refresh
109
+		if($device_uid != '')
110
+		{
111 111
 			$result[0] = $result;
112 112
 			$result[1] = $device_uid;
113
-        }
113
+		}
114 114
 
115 115
         
116
-        /* var_dump($result); */
116
+		/* var_dump($result); */
117 117
         
118
-        return $result;
119
-    }
120
-    abstract function getPayload();
121
-    /**
122
-     * Gets Sign headers
123
-     * @return array headers
124
-     */
125
-    private function getSignHeaders()
126
-    {
118
+		return $result;
119
+	}
120
+	abstract function getPayload();
121
+	/**
122
+	 * Gets Sign headers
123
+	 * @return array headers
124
+	 */
125
+	private function getSignHeaders()
126
+	{
127 127
 			if($this->getAccessToken() == null) {
128 128
 				$payload_accessToken = "";
129 129
 			}
@@ -132,54 +132,54 @@  discard block
 block discarded – undo
132 132
 			}
133 133
 			
134 134
 			
135
-        $headers = array(
136
-            "Connection" => "keep-alive",
137
-            "Accept-Encoding" => "gzip",
138
-            "Content-Type" => "application/json; charset=UTF-8",
139
-            "User-Agent" => self::USERAGENT
140
-        );
141
-        $timestamp = new DateTime();
142
-        $timestamp = $timestamp->format(DateTime::ATOM);
143
-        $timestamp = substr($timestamp, 0, -6);
144
-        $timestamp .= "Z";
145
-        $urlParts = parse_url($this->getFullUrl());
146
-        $url2 = "";
147
-        $req = [$this->getMethod(),
148
-            $urlParts['host'],
149
-            "443",
150
-            $urlParts['path'],
151
-            $payload_accessToken,
152
-            $timestamp,
153
-            $url2,
154
-            $this->payLoad];
155
-        $reqString = implode("%", $req);
156
-        $secret = self::SECRET;
157
-        $signature = hash_hmac('sha1', $reqString, $secret);
158
-        $signature = strtoupper($signature);
159
-        $headers['X-Authorization'] = 'HMAC ' . $signature;
160
-        $headers['X-Client-Type'] = self::CLIENT_TYPE;
161
-        $headers['X-Timestamp'] = $timestamp;
162
-        $headers['X-Api-Version'] = '0.2';
163
-        return $headers;
164
-    }
165
-    private function getFullUrl()
166
-    {
167
-        return self::APIURL . $this->getApiEndPoint();
168
-    }
169
-    abstract function getApiEndPoint();
170
-    abstract function getMethod();
171
-    /**
172
-     * @return string
173
-     */
174
-    private function getAccessToken()
175
-    {
176
-        return $this->accessToken;
177
-    }
178
-    /**
179
-     * @param string $accessToken
180
-     */
181
-    public function setAccessToken($accessToken)
182
-    {
183
-        $this->accessToken = $accessToken;
184
-    }
135
+		$headers = array(
136
+			"Connection" => "keep-alive",
137
+			"Accept-Encoding" => "gzip",
138
+			"Content-Type" => "application/json; charset=UTF-8",
139
+			"User-Agent" => self::USERAGENT
140
+		);
141
+		$timestamp = new DateTime();
142
+		$timestamp = $timestamp->format(DateTime::ATOM);
143
+		$timestamp = substr($timestamp, 0, -6);
144
+		$timestamp .= "Z";
145
+		$urlParts = parse_url($this->getFullUrl());
146
+		$url2 = "";
147
+		$req = [$this->getMethod(),
148
+			$urlParts['host'],
149
+			"443",
150
+			$urlParts['path'],
151
+			$payload_accessToken,
152
+			$timestamp,
153
+			$url2,
154
+			$this->payLoad];
155
+		$reqString = implode("%", $req);
156
+		$secret = self::SECRET;
157
+		$signature = hash_hmac('sha1', $reqString, $secret);
158
+		$signature = strtoupper($signature);
159
+		$headers['X-Authorization'] = 'HMAC ' . $signature;
160
+		$headers['X-Client-Type'] = self::CLIENT_TYPE;
161
+		$headers['X-Timestamp'] = $timestamp;
162
+		$headers['X-Api-Version'] = '0.2';
163
+		return $headers;
164
+	}
165
+	private function getFullUrl()
166
+	{
167
+		return self::APIURL . $this->getApiEndPoint();
168
+	}
169
+	abstract function getApiEndPoint();
170
+	abstract function getMethod();
171
+	/**
172
+	 * @return string
173
+	 */
174
+	private function getAccessToken()
175
+	{
176
+		return $this->accessToken;
177
+	}
178
+	/**
179
+	 * @param string $accessToken
180
+	 */
181
+	public function setAccessToken($accessToken)
182
+	{
183
+		$this->accessToken = $accessToken;
184
+	}
185 185
 }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
     const USERAGENT = 'Jodel/4.34.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9 9
     const CLIENT_TYPE = 'android_4.34.2';
10 10
     
11
-    private $accessToken = null;
11
+    private $accessToken = NULL;
12 12
     private $payLoad;
13 13
     public $expects = '';
14 14
     public $version = 'v2';
@@ -72,37 +72,37 @@  discard block
 block discarded – undo
72 72
         }
73 73
         switch ($result->status_code) {
74 74
             case 200:
75
-                $result = json_decode($result->body, true);
75
+                $result = json_decode($result->body, TRUE);
76 76
                 break;
77 77
             case 204:
78 78
                 $result = "Success";
79 79
                 break;
80 80
             case 400:
81 81
                 error_log('Error 400 - Fehlerhafte Anfrage');
82
-                $result = json_decode($result->body, true);
82
+                $result = json_decode($result->body, TRUE);
83 83
                 break;
84 84
             case 401:
85 85
                 error_log('Error 401 - Unauthorized');
86
-                $result = json_decode($result->body, true);
86
+                $result = json_decode($result->body, TRUE);
87 87
                 break;
88 88
             case 404:
89 89
                 error_log('Error 404 - Es wurde bereits gevoted');
90
-                $result = json_decode($result->body, true);
90
+                $result = json_decode($result->body, TRUE);
91 91
 			case 477:
92 92
                 error_log('Error 477 - Signing failed');
93
-                $result = json_decode($result->body, true);
93
+                $result = json_decode($result->body, TRUE);
94 94
                 break;
95 95
             case 429:
96
-                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
96
+                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, TRUE), TRUE));
97 97
             	exit("Error 429: Too Many Requests");
98 98
             	break;
99 99
             case 403:
100
-                error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
100
+                error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, TRUE), TRUE));
101 101
                 exit("Error 403: Access denied");
102 102
                 break;
103 103
             default:
104 104
                 error_log('Error '.$result->status_code.' - Unauthorized');
105
-                $result = json_decode($result->body, true);
105
+                $result = json_decode($result->body, TRUE);
106 106
         }
107 107
 
108 108
         //important for account refresh
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     private function getSignHeaders()
126 126
     {
127
-			if($this->getAccessToken() == null) {
127
+			if($this->getAccessToken() == NULL) {
128 128
 				$payload_accessToken = "";
129 129
 			}
130 130
 			else {
Please login to merge, or discard this patch.