Completed
Push — master ( 6cecc2...81a7e0 )
by mains
03:48 queued 01:16
created
php/Requests/AbstractRequest.php 2 patches
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -2,19 +2,19 @@  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 = 'plerFToqEdWlzShdZlTywaCHRuzlKIMsNmOJVDGE';
8
-    const USERAGENT = 'Jodel/4.31.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
-    const CLIENT_TYPE = 'android_4.31.1';
5
+	const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26';
6
+	const APIURL = 'https://api.go-tellm.com/api';
7
+	const SECRET = 'plerFToqEdWlzShdZlTywaCHRuzlKIMsNmOJVDGE';
8
+	const USERAGENT = 'Jodel/4.31.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
+	const CLIENT_TYPE = 'android_4.31.1';
10 10
     
11
-    private $accessToken = null;
12
-    private $payLoad;
13
-    public $expects = "";
14
-    public $version = 'v2';
11
+	private $accessToken = null;
12
+	private $payLoad;
13
+	public $expects = "";
14
+	public $version = 'v2';
15 15
 
16
-    public function execute()
17
-    {
16
+	public function execute()
17
+	{
18 18
 		$result = new \stdClass();
19 19
 		        
20 20
 		$this->payLoad = $this->getPayload();
@@ -24,96 +24,96 @@  discard block
 block discarded – undo
24 24
 		}
25 25
 				
26 26
 				
27
-        $this->payLoad = json_encode($this->payLoad);
28
-        $header = $this->getSignHeaders();
29
-        $url = $this->getFullUrl();
27
+		$this->payLoad = json_encode($this->payLoad);
28
+		$header = $this->getSignHeaders();
29
+		$url = $this->getFullUrl();
30 30
 
31
-        if ($this->getAccessToken()) {
32
-            $header['Authorization'] = "Bearer " . $this->getAccessToken();
33
-        }
34
-        //Comment out to debug the Request:
31
+		if ($this->getAccessToken()) {
32
+			$header['Authorization'] = "Bearer " . $this->getAccessToken();
33
+		}
34
+		//Comment out to debug the Request:
35 35
         
36
-        /*
36
+		/*
37 37
         var_dump($url);
38 38
         var_dump($header);
39 39
         var_dump($this->payLoad);
40 40
         */
41
-        /*
41
+		/*
42 42
         $options = array(
43 43
             'timeout' => 100,
44 44
             'connect_timeout' => 100,
45 45
             'proxy' => '186.103.169.165:8080',
46 46
         );*/
47 47
 
48
-        switch ($this->getMethod()) {
49
-            case 'POST':
50
-                $result = Requests::post($url, $header, $this->payLoad);
51
-                break;
52
-            case 'GET':
53
-                if($this->version == 'v3')
54
-                {
55
-                    $result = Requests::get($url, $header);
56
-                }
57
-                else
58
-                {
59
-                    $result = Requests::get($url, $header);
60
-                }
61
-                break;
62
-            case 'PUT':
63
-                $result = Requests::put($url, $header, $this->payLoad);
64
-                break;
65
-        }
66
-        switch ($result->status_code) {
67
-            case 200:
68
-                $result = json_decode($result->body, true);
69
-                break;
70
-            case 204:
71
-                $result = "Success";
72
-                break;
73
-            case 401:
48
+		switch ($this->getMethod()) {
49
+			case 'POST':
50
+				$result = Requests::post($url, $header, $this->payLoad);
51
+				break;
52
+			case 'GET':
53
+				if($this->version == 'v3')
54
+				{
55
+					$result = Requests::get($url, $header);
56
+				}
57
+				else
58
+				{
59
+					$result = Requests::get($url, $header);
60
+				}
61
+				break;
62
+			case 'PUT':
63
+				$result = Requests::put($url, $header, $this->payLoad);
64
+				break;
65
+		}
66
+		switch ($result->status_code) {
67
+			case 200:
68
+				$result = json_decode($result->body, true);
69
+				break;
70
+			case 204:
71
+				$result = "Success";
72
+				break;
73
+			case 401:
74 74
 				//throw new \Exception('Unauthorized');
75
-                error_log('Error 401 - Unauthorized - JodelDeviceId:' . $deviceUid);
76
-                break;
77
-            case 404:
78
-                //echo "Es wurde bereits gevoted";
79
-                error_log('Error 404 - Es wurde bereits gevoted - JodelDeviceId:' . $deviceUid);
75
+				error_log('Error 401 - Unauthorized - JodelDeviceId:' . $deviceUid);
76
+				break;
77
+			case 404:
78
+				//echo "Es wurde bereits gevoted";
79
+				error_log('Error 404 - Es wurde bereits gevoted - JodelDeviceId:' . $deviceUid);
80 80
 			case 477:
81
-                //echo "Es wurde bereits gevoted";
82
-                //throw  new \Exception('Signing failed!');
83
-                error_log('Error 477 - Signing failed - JodelDeviceId:' . $deviceUid);
84
-                break;
85
-            case 429:
86
-                error_log('Error 429 - Too Many Requests - JodelDeviceId:' . $deviceUid);
87
-            	exit("Error 429: Too Many Requests");
88
-            	break;
89
-            case 403:
90
-                error_log('Error 403 - Access denied - JodelDeviceId:' . $deviceUid);
91
-                exit("Error 403: Access denied");
92
-                break;
93
-            default:
94
-                error_log('Error '.$result->status_code.' - Unauthorized - JodelDeviceId:' . $deviceUid);
95
-                throw  new \Exception('Unknown Error: '.$result->status_code);
96
-        }
81
+				//echo "Es wurde bereits gevoted";
82
+				//throw  new \Exception('Signing failed!');
83
+				error_log('Error 477 - Signing failed - JodelDeviceId:' . $deviceUid);
84
+				break;
85
+			case 429:
86
+				error_log('Error 429 - Too Many Requests - JodelDeviceId:' . $deviceUid);
87
+				exit("Error 429: Too Many Requests");
88
+				break;
89
+			case 403:
90
+				error_log('Error 403 - Access denied - JodelDeviceId:' . $deviceUid);
91
+				exit("Error 403: Access denied");
92
+				break;
93
+			default:
94
+				error_log('Error '.$result->status_code.' - Unauthorized - JodelDeviceId:' . $deviceUid);
95
+				throw  new \Exception('Unknown Error: '.$result->status_code);
96
+		}
97 97
 
98
-        if($device_uid != "")
99
-        {
98
+		if($device_uid != "")
99
+		{
100 100
 			$result[0] = $result;
101 101
 			$result[1] = $device_uid;
102 102
 		}
103 103
 
104 104
         
105
-        /*var_dump($result);*/
105
+		/*var_dump($result);*/
106 106
         
107 107
 
108
-        return $result;
109
-    }
110
-    abstract function getPayload();
111
-    /**
112
-     * Gets Sign headers
113
-     * @return array headers
114
-     */
115
-    private function getSignHeaders()
116
-    {
108
+		return $result;
109
+	}
110
+	abstract function getPayload();
111
+	/**
112
+	 * Gets Sign headers
113
+	 * @return array headers
114
+	 */
115
+	private function getSignHeaders()
116
+	{
117 117
 			if($this->getAccessToken() == null) {
118 118
 				$payload_accessToken = "";
119 119
 			}
@@ -122,54 +122,54 @@  discard block
 block discarded – undo
122 122
 			}
123 123
 			
124 124
 			
125
-        $headers = array(
126
-            "Connection" => "keep-alive",
127
-            "Accept-Encoding" => "gzip",
128
-            "Content-Type" => "application/json; charset=UTF-8",
129
-            "User-Agent" => self::USERAGENT
130
-        );
131
-        $timestamp = new DateTime();
132
-        $timestamp = $timestamp->format(DateTime::ATOM);
133
-        $timestamp = substr($timestamp, 0, -6);
134
-        $timestamp .= "Z";
135
-        $urlParts = parse_url($this->getFullUrl());
136
-        $url2 = "";
137
-        $req = [$this->getMethod(),
138
-            $urlParts['host'],
139
-            "443",
140
-            $urlParts['path'],
141
-            $payload_accessToken,
142
-            $timestamp,
143
-            $url2,
144
-            $this->payLoad];
145
-        $reqString = implode("%", $req);
146
-        $secret = self::SECRET;
147
-        $signature = hash_hmac('sha1', $reqString, $secret);
148
-        $signature = strtoupper($signature);
149
-        $headers['X-Authorization'] = 'HMAC ' . $signature;
150
-        $headers['X-Client-Type'] = self::CLIENT_TYPE;
151
-        $headers['X-Timestamp'] = $timestamp;
152
-        $headers['X-Api-Version'] = '0.2';
153
-        return $headers;
154
-    }
155
-    private function getFullUrl()
156
-    {
157
-        return self::APIURL . $this->getApiEndPoint();
158
-    }
159
-    abstract function getApiEndPoint();
160
-    abstract function getMethod();
161
-    /**
162
-     * @return string
163
-     */
164
-    private function getAccessToken()
165
-    {
166
-        return $this->accessToken;
167
-    }
168
-    /**
169
-     * @param string $accessToken
170
-     */
171
-    public function setAccessToken($accessToken)
172
-    {
173
-        $this->accessToken = $accessToken;
174
-    }
125
+		$headers = array(
126
+			"Connection" => "keep-alive",
127
+			"Accept-Encoding" => "gzip",
128
+			"Content-Type" => "application/json; charset=UTF-8",
129
+			"User-Agent" => self::USERAGENT
130
+		);
131
+		$timestamp = new DateTime();
132
+		$timestamp = $timestamp->format(DateTime::ATOM);
133
+		$timestamp = substr($timestamp, 0, -6);
134
+		$timestamp .= "Z";
135
+		$urlParts = parse_url($this->getFullUrl());
136
+		$url2 = "";
137
+		$req = [$this->getMethod(),
138
+			$urlParts['host'],
139
+			"443",
140
+			$urlParts['path'],
141
+			$payload_accessToken,
142
+			$timestamp,
143
+			$url2,
144
+			$this->payLoad];
145
+		$reqString = implode("%", $req);
146
+		$secret = self::SECRET;
147
+		$signature = hash_hmac('sha1', $reqString, $secret);
148
+		$signature = strtoupper($signature);
149
+		$headers['X-Authorization'] = 'HMAC ' . $signature;
150
+		$headers['X-Client-Type'] = self::CLIENT_TYPE;
151
+		$headers['X-Timestamp'] = $timestamp;
152
+		$headers['X-Api-Version'] = '0.2';
153
+		return $headers;
154
+	}
155
+	private function getFullUrl()
156
+	{
157
+		return self::APIURL . $this->getApiEndPoint();
158
+	}
159
+	abstract function getApiEndPoint();
160
+	abstract function getMethod();
161
+	/**
162
+	 * @return string
163
+	 */
164
+	private function getAccessToken()
165
+	{
166
+		return $this->accessToken;
167
+	}
168
+	/**
169
+	 * @param string $accessToken
170
+	 */
171
+	public function setAccessToken($accessToken)
172
+	{
173
+		$this->accessToken = $accessToken;
174
+	}
175 175
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
         $header = $this->getSignHeaders();
29 29
         $url = $this->getFullUrl();
30 30
 
31
-        if ($this->getAccessToken()) {
31
+        if($this->getAccessToken()) {
32 32
             $header['Authorization'] = "Bearer " . $this->getAccessToken();
33 33
         }
34 34
         //Comment out to debug the Request:
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
             'proxy' => '186.103.169.165:8080',
46 46
         );*/
47 47
 
48
-        switch ($this->getMethod()) {
48
+        switch($this->getMethod()) {
49 49
             case 'POST':
50 50
                 $result = Requests::post($url, $header, $this->payLoad);
51 51
                 break;
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
                 $result = Requests::put($url, $header, $this->payLoad);
64 64
                 break;
65 65
         }
66
-        switch ($result->status_code) {
66
+        switch($result->status_code) {
67 67
             case 200:
68 68
                 $result = json_decode($result->body, true);
69 69
                 break;
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
                 exit("Error 403: Access denied");
92 92
                 break;
93 93
             default:
94
-                error_log('Error '.$result->status_code.' - Unauthorized - JodelDeviceId:' . $deviceUid);
95
-                throw  new \Exception('Unknown Error: '.$result->status_code);
94
+                error_log('Error ' . $result->status_code . ' - Unauthorized - JodelDeviceId:' . $deviceUid);
95
+                throw  new \Exception('Unknown Error: ' . $result->status_code);
96 96
         }
97 97
 
98 98
         if($device_uid != "")
Please login to merge, or discard this patch.