Completed
Push — master ( ad03c5...4bc4e3 )
by mains
02:50
created
php/Requests/AbstractRequest.php 1 patch
Indentation   +123 added lines, -123 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,90 +24,90 @@  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
-                break;
76
-            case 404:
77
-                //echo "Es wurde bereits gevoted";
75
+				break;
76
+			case 404:
77
+				//echo "Es wurde bereits gevoted";
78 78
 			case 477:
79
-                //echo "Es wurde bereits gevoted";
80
-                //throw  new \Exception('Signing failed!');
81
-                break;
82
-            case 429:
83
-            	exit("Error 429: Too Many Requests");
84
-            	break;
85
-            case 403:
86
-                exit("Error 403: Access denied");
87
-                break;
88
-            default:
89
-                throw  new \Exception('Unknown Error: '.$result->status_code);
90
-        }
79
+				//echo "Es wurde bereits gevoted";
80
+				//throw  new \Exception('Signing failed!');
81
+				break;
82
+			case 429:
83
+				exit("Error 429: Too Many Requests");
84
+				break;
85
+			case 403:
86
+				exit("Error 403: Access denied");
87
+				break;
88
+			default:
89
+				throw  new \Exception('Unknown Error: '.$result->status_code);
90
+		}
91 91
 
92
-        if($device_uid != "")
93
-        {
92
+		if($device_uid != "")
93
+		{
94 94
 			$result[0] = $result;
95 95
 			$result[1] = $device_uid;
96 96
 		}
97 97
 
98 98
         
99
-        /*var_dump($result);*/
99
+		/*var_dump($result);*/
100 100
         
101 101
 
102
-        return $result;
103
-    }
104
-    abstract function getPayload();
105
-    /**
106
-     * Gets Sign headers
107
-     * @return array headers
108
-     */
109
-    private function getSignHeaders()
110
-    {
102
+		return $result;
103
+	}
104
+	abstract function getPayload();
105
+	/**
106
+	 * Gets Sign headers
107
+	 * @return array headers
108
+	 */
109
+	private function getSignHeaders()
110
+	{
111 111
 			if($this->getAccessToken() == null) {
112 112
 				$payload_accessToken = "";
113 113
 			}
@@ -116,54 +116,54 @@  discard block
 block discarded – undo
116 116
 			}
117 117
 			
118 118
 			
119
-        $headers = array(
120
-            "Connection" => "keep-alive",
121
-            "Accept-Encoding" => "gzip",
122
-            "Content-Type" => "application/json; charset=UTF-8",
123
-            "User-Agent" => self::USERAGENT
124
-        );
125
-        $timestamp = new DateTime();
126
-        $timestamp = $timestamp->format(DateTime::ATOM);
127
-        $timestamp = substr($timestamp, 0, -6);
128
-        $timestamp .= "Z";
129
-        $urlParts = parse_url($this->getFullUrl());
130
-        $url2 = "";
131
-        $req = [$this->getMethod(),
132
-            $urlParts['host'],
133
-            "443",
134
-            $urlParts['path'],
135
-            $payload_accessToken,
136
-            $timestamp,
137
-            $url2,
138
-            $this->payLoad];
139
-        $reqString = implode("%", $req);
140
-        $secret = self::SECRET;
141
-        $signature = hash_hmac('sha1', $reqString, $secret);
142
-        $signature = strtoupper($signature);
143
-        $headers['X-Authorization'] = 'HMAC ' . $signature;
144
-        $headers['X-Client-Type'] = self::CLIENT_TYPE;
145
-        $headers['X-Timestamp'] = $timestamp;
146
-        $headers['X-Api-Version'] = '0.2';
147
-        return $headers;
148
-    }
149
-    private function getFullUrl()
150
-    {
151
-        return self::APIURL . $this->getApiEndPoint();
152
-    }
153
-    abstract function getApiEndPoint();
154
-    abstract function getMethod();
155
-    /**
156
-     * @return string
157
-     */
158
-    private function getAccessToken()
159
-    {
160
-        return $this->accessToken;
161
-    }
162
-    /**
163
-     * @param string $accessToken
164
-     */
165
-    public function setAccessToken($accessToken)
166
-    {
167
-        $this->accessToken = $accessToken;
168
-    }
119
+		$headers = array(
120
+			"Connection" => "keep-alive",
121
+			"Accept-Encoding" => "gzip",
122
+			"Content-Type" => "application/json; charset=UTF-8",
123
+			"User-Agent" => self::USERAGENT
124
+		);
125
+		$timestamp = new DateTime();
126
+		$timestamp = $timestamp->format(DateTime::ATOM);
127
+		$timestamp = substr($timestamp, 0, -6);
128
+		$timestamp .= "Z";
129
+		$urlParts = parse_url($this->getFullUrl());
130
+		$url2 = "";
131
+		$req = [$this->getMethod(),
132
+			$urlParts['host'],
133
+			"443",
134
+			$urlParts['path'],
135
+			$payload_accessToken,
136
+			$timestamp,
137
+			$url2,
138
+			$this->payLoad];
139
+		$reqString = implode("%", $req);
140
+		$secret = self::SECRET;
141
+		$signature = hash_hmac('sha1', $reqString, $secret);
142
+		$signature = strtoupper($signature);
143
+		$headers['X-Authorization'] = 'HMAC ' . $signature;
144
+		$headers['X-Client-Type'] = self::CLIENT_TYPE;
145
+		$headers['X-Timestamp'] = $timestamp;
146
+		$headers['X-Api-Version'] = '0.2';
147
+		return $headers;
148
+	}
149
+	private function getFullUrl()
150
+	{
151
+		return self::APIURL . $this->getApiEndPoint();
152
+	}
153
+	abstract function getApiEndPoint();
154
+	abstract function getMethod();
155
+	/**
156
+	 * @return string
157
+	 */
158
+	private function getAccessToken()
159
+	{
160
+		return $this->accessToken;
161
+	}
162
+	/**
163
+	 * @param string $accessToken
164
+	 */
165
+	public function setAccessToken($accessToken)
166
+	{
167
+		$this->accessToken = $accessToken;
168
+	}
169 169
 }
Please login to merge, or discard this patch.