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