Completed
Push — master ( 3c0e9a...ccb03a )
by mains
02:54
created
vote-ajax.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,8 +6,8 @@
 block discarded – undo
6 6
 {
7 7
 	error_log('test');
8 8
 	header('Content-Type: application/json');
9
-    echo json_encode($jodelAccountForKarma->votePostId($_GET['postId'], $_GET['vote']));
10
-    die();
9
+	echo json_encode($jodelAccountForKarma->votePostId($_GET['postId'], $_GET['vote']));
10
+	die();
11 11
 }
12 12
 
13 13
 if(isset($_GET['solution']) && isset($_POST['deviceUid']))
Please login to merge, or discard this patch.
php/View.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -2,98 +2,98 @@  discard block
 block discarded – undo
2 2
 
3 3
 class View
4 4
 {
5
-    public $country;
6
-    public $city;
7
-    public $hashtag;
5
+	public $country;
6
+	public $city;
7
+	public $hashtag;
8 8
 	public $view;
9
-    public $postId;
10
-    public $isDetailedView;
11
-    public $baseUrl;
9
+	public $postId;
10
+	public $isDetailedView;
11
+	public $baseUrl;
12 12
 
13 13
 	public $lastPostId = '';
14 14
 
15
-    function __construct($baseUrl, $country, $city, $hashtag = '%23all', $view = 'time', $postId = '')
16
-    {
17
-        $this->baseUrl = $baseUrl;
18
-        $this->country = $country;
19
-        $this->city = $city;
20
-        $this->hashtag = urldecode($hashtag);
21
-        $this->view = $view;
22
-        $this->postId = $postId;
15
+	function __construct($baseUrl, $country, $city, $hashtag = '%23all', $view = 'time', $postId = '')
16
+	{
17
+		$this->baseUrl = $baseUrl;
18
+		$this->country = $country;
19
+		$this->city = $city;
20
+		$this->hashtag = urldecode($hashtag);
21
+		$this->view = $view;
22
+		$this->postId = $postId;
23 23
 
24
-        if($postId == '')
25
-        {
26
-            $this->isDetailedView = FALSE;
27
-        }
28
-        else
29
-        {
30
-            $this->isDetailedView = TRUE;
31
-        }
32
-    }
24
+		if($postId == '')
25
+		{
26
+			$this->isDetailedView = FALSE;
27
+		}
28
+		else
29
+		{
30
+			$this->isDetailedView = TRUE;
31
+		}
32
+	}
33 33
 	/**
34 34
 	 * Compute HTML Code
35 35
 	 */
36 36
  	function jodelToHtml($post)
37
-    {   //ToDO
38
-        //Replace # with link
39
-        //preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text);
37
+	{   //ToDO
38
+		//Replace # with link
39
+		//preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text);
40 40
 
41
-        //Time to time difference
42
-        $now = new DateTime();
43
-        $d = new DateTime($post['created_at']);
44
-        $timediff = $now->diff($d);
41
+		//Time to time difference
42
+		$now = new DateTime();
43
+		$d = new DateTime($post['created_at']);
44
+		$timediff = $now->diff($d);
45 45
 
46
-        $timediff_inSeconds = (string)$timediff->format('%s');
47
-        $timediff_inMinutes = (string)$timediff->format('%i');
48
-        $timediff_inHours = (string)$timediff->format('%h');
49
-        $timediff_inDays = (string)$timediff->format('%d');
50
-        $timediff_inMonth = (string)$timediff->format('%m');
46
+		$timediff_inSeconds = (string)$timediff->format('%s');
47
+		$timediff_inMinutes = (string)$timediff->format('%i');
48
+		$timediff_inHours = (string)$timediff->format('%h');
49
+		$timediff_inDays = (string)$timediff->format('%d');
50
+		$timediff_inMonth = (string)$timediff->format('%m');
51 51
 
52
-        if($timediff_inMonth!=0)
53
-        {
54
-                $timediff = $timediff_inMonth . "m";
55
-        }
56
-        else
57
-        {
58
-            if($timediff_inDays!=0)
59
-            {
60
-                $timediff = $timediff_inDays . "d";
61
-            }
62
-            else
63
-            {
64
-                if($timediff_inHours!=0)
65
-                {
66
-                    $timediff = $timediff_inHours . "h";
67
-                }
68
-                else
69
-                {
70
-                    if($timediff_inMinutes!=0)
71
-                    {
72
-                        $timediff = $timediff_inMinutes . "m";
73
-                    }
74
-                    else
75
-                    {
76
-                        $timediff = $timediff_inSeconds . "s";
77
-                    }
78
-                }
79
-            }
80
-        }
52
+		if($timediff_inMonth!=0)
53
+		{
54
+				$timediff = $timediff_inMonth . "m";
55
+		}
56
+		else
57
+		{
58
+			if($timediff_inDays!=0)
59
+			{
60
+				$timediff = $timediff_inDays . "d";
61
+			}
62
+			else
63
+			{
64
+				if($timediff_inHours!=0)
65
+				{
66
+					$timediff = $timediff_inHours . "h";
67
+				}
68
+				else
69
+				{
70
+					if($timediff_inMinutes!=0)
71
+					{
72
+						$timediff = $timediff_inMinutes . "m";
73
+					}
74
+					else
75
+					{
76
+						$timediff = $timediff_inSeconds . "s";
77
+					}
78
+				}
79
+			}
80
+		}
81 81
 
82 82
 
83
-        ?>
83
+		?>
84 84
         <article id ="postId-<?php echo $post['post_id']; ?>" class="jodel" style="background-color: #<?php echo $post['color'];?>;">
85 85
             <content>
86 86
                 <?php 
87
-                if(isset($post['image_url']))
88
-                {
89
-                    $regexRest = '/[^\w$ .!?-]+/u';
87
+				if(isset($post['image_url']))
88
+				{
89
+					$regexRest = '/[^\w$ .!?-]+/u';
90 90
 
91
-                    echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">';
92
-                }
93
-                else {
94
-                    echo str_replace('  ', ' &nbsp;', nl2br(htmlspecialchars($post['message'])));
95
-                }
96
-                ?>
91
+					echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">';
92
+				}
93
+				else {
94
+					echo str_replace('  ', ' &nbsp;', nl2br(htmlspecialchars($post['message'])));
95
+				}
96
+				?>
97 97
             </content>
98 98
             <aside>                    
99 99
                 <button onclick="vote('<?php echo $post['post_id'];?>', 'up', this)">
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
                                 <a href="<?php echo $this->changePostId($post['post_id'])->toUrl();?>">
123 123
                                     <i class="fa fa-commenting-o"></i>
124 124
                                     <?php if(array_key_exists("child_count", $post))
125
-                                    {
126
-                                        echo $post["child_count"];
127
-                                    } else echo "0";
128
-                                    ?>
125
+									{
126
+										echo $post["child_count"];
127
+									} else echo "0";
128
+									?>
129 129
                                 </a>
130 130
                             </span>
131 131
                             
@@ -145,30 +145,30 @@  discard block
 block discarded – undo
145 145
 						?>
146 146
                         <span class="distance">
147 147
                             <?php
148
-                                if($this->isDetailedView)
149
-                                {
150
-                                    if(isset($post['user_handle']) && $post['user_handle'] == 'OJ')
151
-                                    {
152
-                                        ?>
148
+								if($this->isDetailedView)
149
+								{
150
+									if(isset($post['user_handle']) && $post['user_handle'] == 'OJ')
151
+									{
152
+										?>
153 153
                                         <span data-tooltip="Author">
154 154
                                             <i class="fa fa-user-o"></i> OJ |
155 155
                                         </span>
156 156
                                         <?php 
157
-                                    }
158
-                                    else
159
-                                    {
160
-                                        //Is not parent Jodel in detailed View
161
-                                        if(!array_key_exists('child_count', $post))
162
-                                        {
163
-                                            ?>
157
+									}
158
+									else
159
+									{
160
+										//Is not parent Jodel in detailed View
161
+										if(!array_key_exists('child_count', $post))
162
+										{
163
+											?>
164 164
                                             <span data-tooltip="Author">
165 165
                                                 <i class="fa fa-user-o"></i> #<?php echo $post['user_handle'];?> |
166 166
                                             </span>
167 167
                                             <?php
168
-                                        }
169
-                                    }
170
-                                }
171
-                                ?>
168
+										}
169
+									}
170
+								}
171
+								?>
172 172
 
173 173
                             <span class="tip" data-tooltip="Distance">
174 174
                                 <i class="fa fa-map-marker"></i>
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
             </footer>
182 182
         </article>
183 183
     <?php
184
-    }
184
+	}
185 185
 
186 186
 
187 187
 	/**
@@ -218,142 +218,142 @@  discard block
 block discarded – undo
218 218
 		return $description;
219 219
 	}
220 220
 
221
-    function toUrl()
222
-    {
223
-        $url = $this->baseUrl . 'index.php?country=DE' .
224
-                            '&city=' . urlencode($this->city) .
225
-                            '&hashtag=' . urlencode($this->hashtag) . 
226
-                            '&view=' . $this->view;
227
-        if($this->postId != '')
228
-        {
229
-            $url .= '&postId=' . $this->postId . 
230
-                    '&getPostDetails=TRUE';
231
-        }
221
+	function toUrl()
222
+	{
223
+		$url = $this->baseUrl . 'index.php?country=DE' .
224
+							'&city=' . urlencode($this->city) .
225
+							'&hashtag=' . urlencode($this->hashtag) . 
226
+							'&view=' . $this->view;
227
+		if($this->postId != '')
228
+		{
229
+			$url .= '&postId=' . $this->postId . 
230
+					'&getPostDetails=TRUE';
231
+		}
232 232
 
233
-        return $url;
234
-    }
233
+		return $url;
234
+	}
235 235
 
236
-    function changePostId($postId)
237
-    {
238
-        $tempView = clone $this;
239
-        $tempView->postId = $postId;
240
-        $tempView->isDetailedView = TRUE;
241
-        return $tempView;
242
-    }
236
+	function changePostId($postId)
237
+	{
238
+		$tempView = clone $this;
239
+		$tempView->postId = $postId;
240
+		$tempView->isDetailedView = TRUE;
241
+		return $tempView;
242
+	}
243 243
 
244
-    function back()
245
-    {
246
-        $tempView = clone $this;
247
-        $tempView->postId = '';
248
-        return $tempView;
249
-    }
244
+	function back()
245
+	{
246
+		$tempView = clone $this;
247
+		$tempView->postId = '';
248
+		return $tempView;
249
+	}
250 250
 
251
-    function changeView($view)
252
-    {
253
-        $tempView = clone $this;
254
-        $tempView->view = $view;
255
-        return $tempView;
256
-    }
251
+	function changeView($view)
252
+	{
253
+		$tempView = clone $this;
254
+		$tempView->view = $view;
255
+		return $tempView;
256
+	}
257 257
 
258 258
 	function getPosts($jodelAccount)
259 259
 	{
260
-        if($this->hashtag != '#all' && $this->hashtag != '' && $this->hashtag != NULL)
261
-        {
262
-            $accountCreator = new GetChannel();
263
-            $accountCreator->view = $this->view;
264
-            $accountCreator->setAccessToken($jodelAccount->accessToken);
265
-            $accountCreator->channel = $this->hashtag;
266
-            $accountCreator->lastPostId = $this->lastPostId;
267
-            $data = $accountCreator->execute();
268
-        }
269
-        else
270
-        {
271
-            if($this->lastPostId == '' && $this->view == 'combo')
272
-            {
273
-                $url = "/v3/posts/location/combo";
274
-            }
275
-            else
276
-            {
277
-                if($this->view == 'discussed')
278
-                {
279
-                    $url = "/v2/posts/location/discussed/";
280
-                }
281
-                else
282
-                {
283
-                    if($this->view == 'popular')
284
-                    {
285
-                        $url = "/v2/posts/location/popular/";
286
-                    }
287
-                    else
288
-                    {
289
-                        $url = "/v2/posts/location/";
290
-                    }
291
-                }
292
-            }
260
+		if($this->hashtag != '#all' && $this->hashtag != '' && $this->hashtag != NULL)
261
+		{
262
+			$accountCreator = new GetChannel();
263
+			$accountCreator->view = $this->view;
264
+			$accountCreator->setAccessToken($jodelAccount->accessToken);
265
+			$accountCreator->channel = $this->hashtag;
266
+			$accountCreator->lastPostId = $this->lastPostId;
267
+			$data = $accountCreator->execute();
268
+		}
269
+		else
270
+		{
271
+			if($this->lastPostId == '' && $this->view == 'combo')
272
+			{
273
+				$url = "/v3/posts/location/combo";
274
+			}
275
+			else
276
+			{
277
+				if($this->view == 'discussed')
278
+				{
279
+					$url = "/v2/posts/location/discussed/";
280
+				}
281
+				else
282
+				{
283
+					if($this->view == 'popular')
284
+					{
285
+						$url = "/v2/posts/location/popular/";
286
+					}
287
+					else
288
+					{
289
+						$url = "/v2/posts/location/";
290
+					}
291
+				}
292
+			}
293 293
 
294
-            $accountCreator = new GetPosts();
295
-            $accountCreator->setLastPostId($this->lastPostId);
296
-            $accountCreator->setAccessToken($jodelAccount->accessToken);
297
-            $accountCreator->setUrl($url);
298
-            $accountCreator->version = 'v3';
294
+			$accountCreator = new GetPosts();
295
+			$accountCreator->setLastPostId($this->lastPostId);
296
+			$accountCreator->setAccessToken($jodelAccount->accessToken);
297
+			$accountCreator->setUrl($url);
298
+			$accountCreator->version = 'v3';
299 299
 
300
-            $config = parse_ini_file('config/config.ini.php');
301
-            $location = new Location();
302
-            $location->setLat($config['default_lat']);
303
-            $location->setLng($config['default_lng']);
304
-            $location->setCityName($config['default_location']);
305
-            $accountCreator->location = $location;
306
-            $data = $accountCreator->execute();
307
-        }
308
-    	if(array_key_exists('recent', $data) && array_key_exists(0, $data['recent']))
309
-        {
310
-            return $data['recent'];
311
-        }
312
-        else if(array_key_exists('posts', $data)&& array_key_exists(0, $data['posts']))
313
-        {
314
-            return $data['posts'];
315
-        }
316
-        else
317
-        {
318
-            if($this->lastPostId == '')
319
-            {
320
-                error_log('Could not find Posts in: ' . $this->city . ' Error: ' . print_r($data, true));
321
-                //error_log(print_r($data, true));
300
+			$config = parse_ini_file('config/config.ini.php');
301
+			$location = new Location();
302
+			$location->setLat($config['default_lat']);
303
+			$location->setLng($config['default_lng']);
304
+			$location->setCityName($config['default_location']);
305
+			$accountCreator->location = $location;
306
+			$data = $accountCreator->execute();
307
+		}
308
+		if(array_key_exists('recent', $data) && array_key_exists(0, $data['recent']))
309
+		{
310
+			return $data['recent'];
311
+		}
312
+		else if(array_key_exists('posts', $data)&& array_key_exists(0, $data['posts']))
313
+		{
314
+			return $data['posts'];
315
+		}
316
+		else
317
+		{
318
+			if($this->lastPostId == '')
319
+			{
320
+				error_log('Could not find Posts in: ' . $this->city . ' Error: ' . print_r($data, true));
321
+				//error_log(print_r($data, true));
322 322
 
323
-                $notFound[0] = array(
324
-                    "post_id" => "0",
325
-                    "discovered_by" => 0,
326
-                    "message" => "No more Posts found",
327
-                    "created_at" => "2017-02-11T16:44:50.385Z",
328
-                    "updated_at" => "2017-02-11T16:44:50.385Z",
329
-                    "pin_count" => 0,
330
-                    "color" => "5682a3",
331
-                    "got_thanks" => FALSE,
332
-                    "post_own" => "friend",
333
-                    "discovered" => 0,
334
-                    "distance" => 9,
335
-                    "vote_count" => 0,
336
-                    "location" =>
337
-                    array("name" => "Berlin",
338
-                      "loc_coordinates" =>
339
-                      array(
340
-                        "lat" => 0,
341
-                        "lng" => 0
342
-                      ),
343
-                      "loc_accuracy" => 0,
344
-                      "country" => "",
345
-                      "city" => "",
346
-                    ),
347
-                    "tags" =>
348
-                    array(),
349
-                    "user_handle" => "0"
350
-                );
351
-                return $notFound;
352
-            }
353
-            else
354
-            {
355
-                return FALSE;
356
-            }
357
-        }
323
+				$notFound[0] = array(
324
+					"post_id" => "0",
325
+					"discovered_by" => 0,
326
+					"message" => "No more Posts found",
327
+					"created_at" => "2017-02-11T16:44:50.385Z",
328
+					"updated_at" => "2017-02-11T16:44:50.385Z",
329
+					"pin_count" => 0,
330
+					"color" => "5682a3",
331
+					"got_thanks" => FALSE,
332
+					"post_own" => "friend",
333
+					"discovered" => 0,
334
+					"distance" => 9,
335
+					"vote_count" => 0,
336
+					"location" =>
337
+					array("name" => "Berlin",
338
+					  "loc_coordinates" =>
339
+					  array(
340
+						"lat" => 0,
341
+						"lng" => 0
342
+					  ),
343
+					  "loc_accuracy" => 0,
344
+					  "country" => "",
345
+					  "city" => "",
346
+					),
347
+					"tags" =>
348
+					array(),
349
+					"user_handle" => "0"
350
+				);
351
+				return $notFound;
352
+			}
353
+			else
354
+			{
355
+				return FALSE;
356
+			}
357
+		}
358 358
 	}
359 359
 }
Please login to merge, or discard this patch.
php/Requests/AbstractRequest.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -2,20 +2,20 @@  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 = 'SDydTnTdqqaiAMfneLkqXYxamvNuUYOmkqpdiZTu';
8
-    const USERAGENT = 'Jodel/4.34.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
-    const CLIENT_TYPE = 'android_4.34.2';
5
+	const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26';
6
+	const APIURL = 'https://api.go-tellm.com/api';
7
+	const SECRET = 'SDydTnTdqqaiAMfneLkqXYxamvNuUYOmkqpdiZTu';
8
+	const USERAGENT = 'Jodel/4.34.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
+	const CLIENT_TYPE = 'android_4.34.2';
10 10
     
11
-    private $accessToken = null;
12
-    private $payLoad;
13
-    public $expects = '';
14
-    public $version = 'v2';
15
-    public $hasPayload = FALSE;
11
+	private $accessToken = null;
12
+	private $payLoad;
13
+	public $expects = '';
14
+	public $version = 'v2';
15
+	public $hasPayload = FALSE;
16 16
 
17
-    public function execute()
18
-    {
17
+	public function execute()
18
+	{
19 19
 		$result = new \stdClass();
20 20
 		        
21 21
 		$this->payLoad = $this->getPayload();
@@ -25,16 +25,16 @@  discard block
 block discarded – undo
25 25
 		}
26 26
 				
27 27
 				
28
-        $this->payLoad = json_encode($this->payLoad);
29
-        $header = $this->getSignHeaders();
30
-        $url = $this->getFullUrl();
28
+		$this->payLoad = json_encode($this->payLoad);
29
+		$header = $this->getSignHeaders();
30
+		$url = $this->getFullUrl();
31 31
 
32
-        if ($this->getAccessToken()) {
33
-            $header['Authorization'] = "Bearer " . $this->getAccessToken();
34
-        }
35
-        //Comment out to debug the Request:
32
+		if ($this->getAccessToken()) {
33
+			$header['Authorization'] = "Bearer " . $this->getAccessToken();
34
+		}
35
+		//Comment out to debug the Request:
36 36
 
37
-        /*
37
+		/*
38 38
         printf("URL: ");
39 39
         var_dump($url);
40 40
         echo "<br />";
@@ -45,99 +45,99 @@  discard block
 block discarded – undo
45 45
         var_dump($this->payLoad);
46 46
         echo "<br />";
47 47
         */
48
-        /*
48
+		/*
49 49
         $options = array(
50 50
             'timeout' => 100,
51 51
             'connect_timeout' => 100,
52 52
             'proxy' => '186.103.169.165:8080',
53 53
         );*/
54 54
 
55
-        switch ($this->getMethod()) {
56
-            case 'POST':
57
-                $result = Requests::post($url, $header, $this->payLoad);
58
-                break;
59
-            case 'GET':
60
-                if($this->hasPayload)
61
-                {
62
-                    $result = Requests::get($url, $header, $this->payLoad);
63
-                }
64
-                else
65
-                {
66
-                    $result = Requests::get($url, $header);
67
-                }
68
-                break;
69
-            case 'PUT':
70
-                $result = Requests::put($url, $header, $this->payLoad);
71
-                break;
72
-        }
73
-        switch ($result->status_code) {
74
-            case 200:
75
-                $result = json_decode($result->body, true);
76
-                break;
77
-            case 204:
78
-                $result = 'Success';
79
-                break;
80
-            case 400:
81
-                $result = json_decode($result->body, true);
82
-                error_log('Error 400 - ' . print_r($result, true));
83
-                break;
84
-            case 401:
85
-                $result = json_decode($result->body, true);
86
-                error_log('Error 401 - ' . print_r($result, true));
87
-                break;
88
-            case 404:
89
-                error_log('Error 404 - ' . print_r($result, true));
90
-                $result = json_decode($result->body, true);
91
-                break;
55
+		switch ($this->getMethod()) {
56
+			case 'POST':
57
+				$result = Requests::post($url, $header, $this->payLoad);
58
+				break;
59
+			case 'GET':
60
+				if($this->hasPayload)
61
+				{
62
+					$result = Requests::get($url, $header, $this->payLoad);
63
+				}
64
+				else
65
+				{
66
+					$result = Requests::get($url, $header);
67
+				}
68
+				break;
69
+			case 'PUT':
70
+				$result = Requests::put($url, $header, $this->payLoad);
71
+				break;
72
+		}
73
+		switch ($result->status_code) {
74
+			case 200:
75
+				$result = json_decode($result->body, true);
76
+				break;
77
+			case 204:
78
+				$result = 'Success';
79
+				break;
80
+			case 400:
81
+				$result = json_decode($result->body, true);
82
+				error_log('Error 400 - ' . print_r($result, true));
83
+				break;
84
+			case 401:
85
+				$result = json_decode($result->body, true);
86
+				error_log('Error 401 - ' . print_r($result, true));
87
+				break;
88
+			case 404:
89
+				error_log('Error 404 - ' . print_r($result, true));
90
+				$result = json_decode($result->body, true);
91
+				break;
92 92
 			case 477:
93
-                $result = json_decode($result->body, true);
94
-                error_log('Error 477 - ' . print_r($result, true));
95
-                break;
96
-            case 429:
97
-                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
98
-            	exit("Error 429: Too Many Requests");
99
-            	break;
100
-            case 403:
101
-                error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
102
-                $result = json_decode($result->body, true);
103
-                break;
104
-            case 502:
105
-                error_log('Error 502 - ' . print_r($result, true));
106
-                $result = json_decode($result->body, true);
107
-                break;
108
-            case 503:
109
-                error_log('Error 503 - ' . print_r($result, true));
110
-                $result = json_decode($result->body, true);
93
+				$result = json_decode($result->body, true);
94
+				error_log('Error 477 - ' . print_r($result, true));
95
+				break;
96
+			case 429:
97
+				error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
98
+				exit("Error 429: Too Many Requests");
99
+				break;
100
+			case 403:
101
+				error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
102
+				$result = json_decode($result->body, true);
103
+				break;
104
+			case 502:
105
+				error_log('Error 502 - ' . print_r($result, true));
106
+				$result = json_decode($result->body, true);
107
+				break;
108
+			case 503:
109
+				error_log('Error 503 - ' . print_r($result, true));
110
+				$result = json_decode($result->body, true);
111 111
 
112
-                if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable"')
113
-                {
114
-                    header('location:'.$_SERVER['PHP_SELF']); 
115
-                }
116
-                break;
117
-            default:
118
-                error_log('Error '.$result->status_code.' - unknown error');
119
-                $result = json_decode($result->body, true);
120
-        }
112
+				if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable"')
113
+				{
114
+					header('location:'.$_SERVER['PHP_SELF']); 
115
+				}
116
+				break;
117
+			default:
118
+				error_log('Error '.$result->status_code.' - unknown error');
119
+				$result = json_decode($result->body, true);
120
+		}
121 121
 
122
-        //important for account refresh
123
-        if($device_uid != '')
124
-        {
122
+		//important for account refresh
123
+		if($device_uid != '')
124
+		{
125 125
 			$result[0] = $result;
126 126
 			$result[1] = $device_uid;
127
-        }
127
+		}
128 128
 
129 129
         
130
-        /* var_dump($result); */
130
+		/* var_dump($result); */
131 131
         
132
-        return $result;
133
-    }
134
-    abstract function getPayload();
135
-    /**
136
-     * Gets Sign headers
137
-     * @return array headers
138
-     */
139
-    private function getSignHeaders()
140
-    {
132
+		return $result;
133
+	}
134
+	abstract function getPayload();
135
+	/**
136
+	 * Gets Sign headers
137
+	 * @return array headers
138
+	 */
139
+	private function getSignHeaders()
140
+	{
141 141
 			if($this->getAccessToken() == null) {
142 142
 				$payload_accessToken = "";
143 143
 			}
@@ -146,54 +146,54 @@  discard block
 block discarded – undo
146 146
 			}
147 147
 			
148 148
 			
149
-        $headers = array(
150
-            "Connection" => "keep-alive",
151
-            "Accept-Encoding" => "gzip",
152
-            "Content-Type" => "application/json; charset=UTF-8",
153
-            "User-Agent" => self::USERAGENT
154
-        );
155
-        $timestamp = new DateTime();
156
-        $timestamp = $timestamp->format(DateTime::ATOM);
157
-        $timestamp = substr($timestamp, 0, -6);
158
-        $timestamp .= "Z";
159
-        $urlParts = parse_url($this->getFullUrl());
160
-        $url2 = "";
161
-        $req = [$this->getMethod(),
162
-            $urlParts['host'],
163
-            "443",
164
-            $urlParts['path'],
165
-            $payload_accessToken,
166
-            $timestamp,
167
-            $url2,
168
-            $this->payLoad];
169
-        $reqString = implode("%", $req);
170
-        $secret = self::SECRET;
171
-        $signature = hash_hmac('sha1', $reqString, $secret);
172
-        $signature = strtoupper($signature);
173
-        $headers['X-Authorization'] = 'HMAC ' . $signature;
174
-        $headers['X-Client-Type'] = self::CLIENT_TYPE;
175
-        $headers['X-Timestamp'] = $timestamp;
176
-        $headers['X-Api-Version'] = '0.2';
177
-        return $headers;
178
-    }
179
-    private function getFullUrl()
180
-    {
181
-        return self::APIURL . $this->getApiEndPoint();
182
-    }
183
-    abstract function getApiEndPoint();
184
-    abstract function getMethod();
185
-    /**
186
-     * @return string
187
-     */
188
-    private function getAccessToken()
189
-    {
190
-        return $this->accessToken;
191
-    }
192
-    /**
193
-     * @param string $accessToken
194
-     */
195
-    public function setAccessToken($accessToken)
196
-    {
197
-        $this->accessToken = $accessToken;
198
-    }
149
+		$headers = array(
150
+			"Connection" => "keep-alive",
151
+			"Accept-Encoding" => "gzip",
152
+			"Content-Type" => "application/json; charset=UTF-8",
153
+			"User-Agent" => self::USERAGENT
154
+		);
155
+		$timestamp = new DateTime();
156
+		$timestamp = $timestamp->format(DateTime::ATOM);
157
+		$timestamp = substr($timestamp, 0, -6);
158
+		$timestamp .= "Z";
159
+		$urlParts = parse_url($this->getFullUrl());
160
+		$url2 = "";
161
+		$req = [$this->getMethod(),
162
+			$urlParts['host'],
163
+			"443",
164
+			$urlParts['path'],
165
+			$payload_accessToken,
166
+			$timestamp,
167
+			$url2,
168
+			$this->payLoad];
169
+		$reqString = implode("%", $req);
170
+		$secret = self::SECRET;
171
+		$signature = hash_hmac('sha1', $reqString, $secret);
172
+		$signature = strtoupper($signature);
173
+		$headers['X-Authorization'] = 'HMAC ' . $signature;
174
+		$headers['X-Client-Type'] = self::CLIENT_TYPE;
175
+		$headers['X-Timestamp'] = $timestamp;
176
+		$headers['X-Api-Version'] = '0.2';
177
+		return $headers;
178
+	}
179
+	private function getFullUrl()
180
+	{
181
+		return self::APIURL . $this->getApiEndPoint();
182
+	}
183
+	abstract function getApiEndPoint();
184
+	abstract function getMethod();
185
+	/**
186
+	 * @return string
187
+	 */
188
+	private function getAccessToken()
189
+	{
190
+		return $this->accessToken;
191
+	}
192
+	/**
193
+	 * @param string $accessToken
194
+	 */
195
+	public function setAccessToken($accessToken)
196
+	{
197
+		$this->accessToken = $accessToken;
198
+	}
199 199
 }
Please login to merge, or discard this patch.