Completed
Push — master ( d139d3...e39583 )
by mains
02:48
created
php/Requests/AbstractRequest.php 1 patch
Indentation   +125 added lines, -125 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,88 +24,88 @@  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
-        $options = array(
43
-            'proxy' => '186.103.169.165:8080'
44
-        );
42
+		$options = array(
43
+			'proxy' => '186.103.169.165:8080'
44
+		);
45 45
 
46
-        switch ($this->getMethod()) {
47
-            case 'POST':
48
-                $result = Requests::post($url, $header, $this->payLoad, $options);
49
-                break;
50
-            case 'GET':
51
-                if($this->version == 'v3')
52
-                {
53
-                    $result = Requests::get($url, $header);
54
-                }
55
-                else
56
-                {
57
-                    $result = Requests::get($url, $header);
58
-                }
59
-                break;
60
-            case 'PUT':
61
-                $result = Requests::put($url, $header, $this->payLoad);
62
-                break;
63
-        }
64
-        switch ($result->status_code) {
65
-            case 200:
66
-                $result = json_decode($result->body, true);
67
-                break;
68
-            case 204:
69
-                $result = "Success";
70
-                break;
71
-            case 401:
46
+		switch ($this->getMethod()) {
47
+			case 'POST':
48
+				$result = Requests::post($url, $header, $this->payLoad, $options);
49
+				break;
50
+			case 'GET':
51
+				if($this->version == 'v3')
52
+				{
53
+					$result = Requests::get($url, $header);
54
+				}
55
+				else
56
+				{
57
+					$result = Requests::get($url, $header);
58
+				}
59
+				break;
60
+			case 'PUT':
61
+				$result = Requests::put($url, $header, $this->payLoad);
62
+				break;
63
+		}
64
+		switch ($result->status_code) {
65
+			case 200:
66
+				$result = json_decode($result->body, true);
67
+				break;
68
+			case 204:
69
+				$result = "Success";
70
+				break;
71
+			case 401:
72 72
 				//throw new \Exception('Unauthorized');
73
-                break;
74
-            case 404:
75
-                //echo "Es wurde bereits gevoted";
73
+				break;
74
+			case 404:
75
+				//echo "Es wurde bereits gevoted";
76 76
 			case 477:
77
-                //echo "Es wurde bereits gevoted";
78
-                //throw  new \Exception('Signing failed!');
79
-                break;
80
-            case 429:
81
-            	exit("Error 429: Too Many Requests");
82
-            	break;
83
-            case 403:
84
-                exit("Error 403: Access denied");
85
-                break;
86
-            default:
87
-                throw  new \Exception('Unknown Error: '.$result->status_code);
88
-        }
77
+				//echo "Es wurde bereits gevoted";
78
+				//throw  new \Exception('Signing failed!');
79
+				break;
80
+			case 429:
81
+				exit("Error 429: Too Many Requests");
82
+				break;
83
+			case 403:
84
+				exit("Error 403: Access denied");
85
+				break;
86
+			default:
87
+				throw  new \Exception('Unknown Error: '.$result->status_code);
88
+		}
89 89
 
90
-        if($device_uid != "")
91
-        {
90
+		if($device_uid != "")
91
+		{
92 92
 			$result[0] = $result;
93 93
 			$result[1] = $device_uid;
94 94
 		}
95 95
 
96 96
         
97
-        /*var_dump($result);*/
97
+		/*var_dump($result);*/
98 98
         
99 99
 
100
-        return $result;
101
-    }
102
-    abstract function getPayload();
103
-    /**
104
-     * Gets Sign headers
105
-     * @return array headers
106
-     */
107
-    private function getSignHeaders()
108
-    {
100
+		return $result;
101
+	}
102
+	abstract function getPayload();
103
+	/**
104
+	 * Gets Sign headers
105
+	 * @return array headers
106
+	 */
107
+	private function getSignHeaders()
108
+	{
109 109
 			if($this->getAccessToken() == null) {
110 110
 				$payload_accessToken = "";
111 111
 			}
@@ -114,54 +114,54 @@  discard block
 block discarded – undo
114 114
 			}
115 115
 			
116 116
 			
117
-        $headers = array(
118
-            "Connection" => "keep-alive",
119
-            "Accept-Encoding" => "gzip",
120
-            "Content-Type" => "application/json; charset=UTF-8",
121
-            "User-Agent" => self::USERAGENT
122
-        );
123
-        $timestamp = new DateTime();
124
-        $timestamp = $timestamp->format(DateTime::ATOM);
125
-        $timestamp = substr($timestamp, 0, -6);
126
-        $timestamp .= "Z";
127
-        $urlParts = parse_url($this->getFullUrl());
128
-        $url2 = "";
129
-        $req = [$this->getMethod(),
130
-            $urlParts['host'],
131
-            "443",
132
-            $urlParts['path'],
133
-            $payload_accessToken,
134
-            $timestamp,
135
-            $url2,
136
-            $this->payLoad];
137
-        $reqString = implode("%", $req);
138
-        $secret = self::SECRET;
139
-        $signature = hash_hmac('sha1', $reqString, $secret);
140
-        $signature = strtoupper($signature);
141
-        $headers['X-Authorization'] = 'HMAC ' . $signature;
142
-        $headers['X-Client-Type'] = self::CLIENT_TYPE;
143
-        $headers['X-Timestamp'] = $timestamp;
144
-        $headers['X-Api-Version'] = '0.2';
145
-        return $headers;
146
-    }
147
-    private function getFullUrl()
148
-    {
149
-        return self::APIURL . $this->getApiEndPoint();
150
-    }
151
-    abstract function getApiEndPoint();
152
-    abstract function getMethod();
153
-    /**
154
-     * @return string
155
-     */
156
-    private function getAccessToken()
157
-    {
158
-        return $this->accessToken;
159
-    }
160
-    /**
161
-     * @param string $accessToken
162
-     */
163
-    public function setAccessToken($accessToken)
164
-    {
165
-        $this->accessToken = $accessToken;
166
-    }
117
+		$headers = array(
118
+			"Connection" => "keep-alive",
119
+			"Accept-Encoding" => "gzip",
120
+			"Content-Type" => "application/json; charset=UTF-8",
121
+			"User-Agent" => self::USERAGENT
122
+		);
123
+		$timestamp = new DateTime();
124
+		$timestamp = $timestamp->format(DateTime::ATOM);
125
+		$timestamp = substr($timestamp, 0, -6);
126
+		$timestamp .= "Z";
127
+		$urlParts = parse_url($this->getFullUrl());
128
+		$url2 = "";
129
+		$req = [$this->getMethod(),
130
+			$urlParts['host'],
131
+			"443",
132
+			$urlParts['path'],
133
+			$payload_accessToken,
134
+			$timestamp,
135
+			$url2,
136
+			$this->payLoad];
137
+		$reqString = implode("%", $req);
138
+		$secret = self::SECRET;
139
+		$signature = hash_hmac('sha1', $reqString, $secret);
140
+		$signature = strtoupper($signature);
141
+		$headers['X-Authorization'] = 'HMAC ' . $signature;
142
+		$headers['X-Client-Type'] = self::CLIENT_TYPE;
143
+		$headers['X-Timestamp'] = $timestamp;
144
+		$headers['X-Api-Version'] = '0.2';
145
+		return $headers;
146
+	}
147
+	private function getFullUrl()
148
+	{
149
+		return self::APIURL . $this->getApiEndPoint();
150
+	}
151
+	abstract function getApiEndPoint();
152
+	abstract function getMethod();
153
+	/**
154
+	 * @return string
155
+	 */
156
+	private function getAccessToken()
157
+	{
158
+		return $this->accessToken;
159
+	}
160
+	/**
161
+	 * @param string $accessToken
162
+	 */
163
+	public function setAccessToken($accessToken)
164
+	{
165
+		$this->accessToken = $accessToken;
166
+	}
167 167
 }
Please login to merge, or discard this patch.