-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.power
More file actions
113 lines (101 loc) · 2.75 KB
/
code.power
File metadata and controls
113 lines (101 loc) · 2.75 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* List a repo's watchers.
*
* @param string $ownerName The owner name.
* @param string $repoName The repository name.
* @param int $page Page number of results to return (1-based).
* @param int $limit Page size of results.
*
* @return array|null
* @since 3.2.0
**/
public function list(
string $ownerName,
string $repoName,
int $page = 1,
int $limit = 10
): ?array
{
// Build the request path.
$path = "/repos/{$ownerName}/{$repoName}/subscribers";
// Prepare the URI with the path.
$uri = $this->uri->get($path);
// Set the page and limit query parameters.
$uri->setVar('page', $page);
$uri->setVar('limit', $limit);
// Send the get request.
return $this->response->get(
$this->http->get($uri)
);
}
/**
* Check if the current user is watching a repo.
*
* @param string $ownerName The owner name.
* @param string $repoName The repository name.
*
* @return object|null
* @since 3.2.0
**/
public function check(string $ownerName, string $repoName): ?object
{
// Build the request path.
$path = "/repos/{$ownerName}/{$repoName}/subscription";
// Prepare the URI with the path.
$uri = $this->uri->get($path);
// Send the get request.
return $this->response->get(
$this->http->get($uri)
);
}
/**
* Watch a repo.
*
* @param string $ownerName The owner name.
* @param string $repoName The repository name.
* @param bool $subscribed Determine if notifications should be received from this repository.
* @param bool $ignored Determine if all notifications should be blocked from this repository.
*
* @return object|null
* @since 3.2.0
**/
public function watch(
string $ownerName,
string $repoName,
bool $subscribed = true,
bool $ignored = false
): ?object
{
// Build the request path.
$path = "/repos/{$ownerName}/{$repoName}/subscription";
// Set the subscription data
$data = new \stdClass();
$data->subscribed = $subscribed;
$data->ignored = $ignored;
// Send the put request.
return $this->response->get(
$this->http->put(
$this->uri->get($path), json_encode($data)
)
);
}
/**
* Unwatch a repo.
*
* @param string $ownerName The owner name.
* @param string $repoName The repository name.
*
* @return string
* @since 3.2.0
**/
public function unwatch(string $ownerName, string $repoName): string
{
// Build the request path.
$path = "/repos/{$ownerName}/{$repoName}/subscription";
// Prepare the URI with the path.
$uri = $this->uri->get($path);
// Send the delete request.
return $this->response->get(
$this->http->delete($uri), 204, 'success'
);
}