1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage GitHub
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * GitHub API References class for the Joomla Platform.
14 *
15 * @documentation https://developer.github.com/v3/repos/users/keys
16 *
17 * @since 12.3
18 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
19 */
20 class JGithubPackageUsersKeys extends JGithubPackage
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 * @since 3.3 (CMS)
30 *
31 * @return object
32 */
33 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 * @since 3.3 (CMS)
51 *
52 * @return object
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 * @since 3.3 (CMS)
70 *
71 * @return object
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 * @since 3.3 (CMS)
90 *
91 * @return object
92 */
93 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 * @since 3.3 (CMS)
117 *
118 * @return object
119 */
120 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 * @since 3.3 (CMS)
141 *
142 * @return object
143 */
144 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