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