-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.power
More file actions
110 lines (102 loc) · 2.88 KB
/
code.power
File metadata and controls
110 lines (102 loc) · 2.88 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
/**
* Get users who subscribed on an issue.
*
* @param string $owner The owner name.
* @param string $repo The repo name.
* @param int $index The issue index.
* @param int|null $page Optional. Page number of results to return (1-based).
* @param int|null $limit Optional. Page size of results.
*
* @return object|null
* @since 3.2.0
**/
public function get(
string $owner,
string $repo,
int $index,
?int $page = null,
?int $limit = null
): ?object
{
// Build the request path.
$path = "/repos/{$owner}/{$repo}/issues/{$index}/subscriptions";
// Set the query parameters.
$uri = $this->uri->get($path);
if ($page !== null)
{
$uri->setVar('page', $page);
}
if ($limit !== null)
{
$uri->setVar('limit', $limit);
}
// Send the get request.
return $this->response->get(
$this->http->get($uri)
);
}
/**
* Check if user is subscribed to an issue.
*
* @param string $owner The owner name.
* @param string $repo The repo name.
* @param int $index The issue index.
*
* @return object|null
* @since 3.2.0
**/
public function check(string $owner, string $repo, int $index): ?object
{
// Build the request path.
$path = "/repos/{$owner}/{$repo}/issues/{$index}/subscriptions/check";
// Send the get request.
return $this->response->get(
$this->http->get(
$this->uri->get($path)
)
);
}
/**
* Subscribe user to issue.
*
* @param string $owner The owner name.
* @param string $repo The repo name.
* @param int $index The issue index.
* @param string $user The username to subscribe.
*
* @return string
* @since 3.2.0
**/
public function subscribe(string $owner, string $repo, int $index, string $user): string
{
// Build the request path.
$path = "/repos/{$owner}/{$repo}/issues/{$index}/subscriptions/{$user}";
// Send the put request.
return $this->response->get_(
$this->http->put(
$this->uri->get($path), ''
), [200 => 'already subscribed', 201 => 'success']
);
}
/**
* Unsubscribe user from issue.
*
* @param string $owner The owner name.
* @param string $repo The repo name.
* @param int $index The issue index.
* @param string $user The username to unsubscribe.
*
* @return string
* @since 3.2.0
**/
public function unsubscribe(string $owner, string $repo, int $index, string $user): string
{
// Build the request path.
$path = "/repos/{$owner}/{$repo}/issues/{$index}/subscriptions/{$user}";
// Send the delete request.
return $this->response->get_(
$this->http->delete(
$this->uri->get($path)
), [200 => 'already unsubscribed', 201 => 'success']
);
}