-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
77 lines (54 loc) · 2.04 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
class GistsRemover
{
protected $baseUrl = 'https://api.github.com';
protected $basicAuth = [
'userName' => 'your_usename',
'password' => 'your_password'
];
protected $removedGistCounter = 0;
protected $removeTypeGist = 'all'; // Options: public, private, all
protected $privateIsEmpty = false;
public function curlWrapper($requestUri = '', $requestType = 'GET', $requestData = []) {
reSearchPrivateGist:
$requestUri = str_replace(':userName', $this->basicAuth['userName'], $requestUri);
$process = curl_init($this->baseUrl.$requestUri);
curl_setopt($process,CURLOPT_USERAGENT,$this->basicAuth['userName']);
curl_setopt($process, CURLOPT_USERPWD, $this->basicAuth['userName'] . ":" . $this->basicAuth['password']);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
if($requestType == 'POST') {
curl_setopt($process, CURLOPT_POST, 1);
} elseif($requestType == 'DELETE') {
curl_setopt($process, CURLOPT_CUSTOMREQUEST, "DELETE");
}
if(count($requestData) > 0) {
curl_setopt($process, CURLOPT_POSTFIELDS, $requestData);
}
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
if($requestType == 'DELETE') {
$this->removedGistCounter++;
return 'ok';
}
$decodedData = json_decode($return, true);
$removedIds = [];
foreach ($decodedData as $key => $value) {
if(($this->removeTypeGist == 'private' && $value['public'] != true) || ($this->removeTypeGist == 'public' && $value['public'] != false) || $this->removeTypeGist == 'all') {
$removedIds[] = $value['id'];
}
}
curl_close($process);
if(count($removedIds) > 0) {
foreach ($removedIds as $gistId) {
echo ( $this->removedGistCounter + 1 ) . ". DELETING: http://gist.github.com/". $this->basicAuth['userName'] . "/" . $gistId."\r\n";
self::curlWrapper('/gists/'.$gistId, 'DELETE');
}
goto reSearchPrivateGist;
} else {
$this->privateIsEmpty = true;
print_r("All private gists deleted.");
}
}
}
$gistsRemover = new GistsRemover();
$gistsRemover->curlWrapper('/users/:userName/gists');