|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Part of the Joomla Framework Github Package |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. |
|
6
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Joomla\Github\Package\Users; |
|
10
|
|
|
|
|
11
|
|
|
use Joomla\Github\AbstractPackage; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* GitHub API References class for the Joomla Framework. |
|
15
|
|
|
* |
|
16
|
|
|
* @link https://developer.github.com/v3/users/keys |
|
17
|
|
|
* |
|
18
|
|
|
* @since 1.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
class Keys extends AbstractPackage |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* List public keys for a user. |
|
24
|
|
|
* |
|
25
|
|
|
* Lists the verified public keys for a user. This is accessible by anyone. |
|
26
|
|
|
* |
|
27
|
|
|
* @param string $user The name of the user. |
|
28
|
|
|
* |
|
29
|
|
|
* @return object |
|
30
|
|
|
* |
|
31
|
|
|
* @since 1.0 |
|
32
|
|
|
*/ |
|
33
|
|
View Code Duplication |
public function getListUser($user) |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
// Build the request path. |
|
36
|
|
|
$path = '/users/' . $user . '/keys'; |
|
37
|
|
|
|
|
38
|
|
|
return $this->processResponse( |
|
39
|
|
|
$this->client->get($this->fetchUrl($path)) |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* List your public keys. |
|
45
|
|
|
* |
|
46
|
|
|
* Lists the current user’s keys. |
|
47
|
|
|
* Management of public keys via the API requires that you are authenticated |
|
48
|
|
|
* through basic auth, or OAuth with the ‘user’ scope. |
|
49
|
|
|
* |
|
50
|
|
|
* @return object |
|
51
|
|
|
* |
|
52
|
|
|
* @since 1.0 |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getList() |
|
55
|
|
|
{ |
|
56
|
|
|
// Build the request path. |
|
57
|
|
|
$path = '/users/keys'; |
|
58
|
|
|
|
|
59
|
|
|
return $this->processResponse( |
|
60
|
|
|
$this->client->get($this->fetchUrl($path)) |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get a single public key. |
|
66
|
|
|
* |
|
67
|
|
|
* @param integer $id The id of the key. |
|
68
|
|
|
* |
|
69
|
|
|
* @return object |
|
70
|
|
|
* |
|
71
|
|
|
* @since 1.0 |
|
72
|
|
|
*/ |
|
73
|
|
|
public function get($id) |
|
74
|
|
|
{ |
|
75
|
|
|
// Build the request path. |
|
76
|
|
|
$path = '/users/keys/' . $id; |
|
77
|
|
|
|
|
78
|
|
|
return $this->processResponse( |
|
79
|
|
|
$this->client->get($this->fetchUrl($path)) |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Create a public key |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $title The title of the key. |
|
87
|
|
|
* @param string $key The key. |
|
88
|
|
|
* |
|
89
|
|
|
* @return object |
|
90
|
|
|
* |
|
91
|
|
|
* @since 1.0 |
|
92
|
|
|
*/ |
|
93
|
|
View Code Duplication |
public function create($title, $key) |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
// Build the request path. |
|
96
|
|
|
$path = '/users/keys'; |
|
97
|
|
|
|
|
98
|
|
|
$data = array( |
|
99
|
|
|
'title' => $title, |
|
100
|
|
|
'key' => $key |
|
101
|
|
|
); |
|
102
|
|
|
|
|
103
|
|
|
return $this->processResponse( |
|
104
|
|
|
$this->client->post($this->fetchUrl($path), json_encode($data)), |
|
105
|
|
|
201 |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Update a public key. |
|
111
|
|
|
* |
|
112
|
|
|
* @param integer $id The id of the key. |
|
113
|
|
|
* @param string $title The title of the key. |
|
114
|
|
|
* @param string $key The key. |
|
115
|
|
|
* |
|
116
|
|
|
* @return object |
|
117
|
|
|
* |
|
118
|
|
|
* @since 1.0 |
|
119
|
|
|
*/ |
|
120
|
|
View Code Duplication |
public function edit($id, $title, $key) |
|
|
|
|
|
|
121
|
|
|
{ |
|
122
|
|
|
// Build the request path. |
|
123
|
|
|
$path = '/users/keys/' . $id; |
|
124
|
|
|
|
|
125
|
|
|
$data = array( |
|
126
|
|
|
'title' => $title, |
|
127
|
|
|
'key' => $key |
|
128
|
|
|
); |
|
129
|
|
|
|
|
130
|
|
|
return $this->processResponse( |
|
131
|
|
|
$this->client->patch($this->fetchUrl($path), json_encode($data)) |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Delete a public key. |
|
137
|
|
|
* |
|
138
|
|
|
* @param integer $id The id of the key. |
|
139
|
|
|
* |
|
140
|
|
|
* @return object |
|
141
|
|
|
* |
|
142
|
|
|
* @since 1.0 |
|
143
|
|
|
*/ |
|
144
|
|
View Code Duplication |
public function delete($id) |
|
|
|
|
|
|
145
|
|
|
{ |
|
146
|
|
|
// Build the request path. |
|
147
|
|
|
$path = '/users/keys/' . (int) $id; |
|
148
|
|
|
|
|
149
|
|
|
return $this->processResponse( |
|
150
|
|
|
$this->client->delete($this->fetchUrl($path)), |
|
151
|
|
|
204 |
|
152
|
|
|
); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.