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 Forks class for the Joomla Platform.
14 *
15 * @documentation https://developer.github.com/v3/repos/keys
16 *
17 * @since 11.3
18 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
19 */
20 class JGithubPackageRepositoriesKeys extends JGithubPackage
21 {
22 /**
23 * List keys in a repository.
24 *
25 * @param string $owner The name of the owner of the GitHub repository.
26 * @param string $repo The name of the GitHub repository.
27 *
28 * @since 12.4
29 *
30 * @return object
31 */
32 public function getList($owner, $repo)
33 {
34 // Build the request path.
35 $path = '/repos/' . $owner . '/' . $repo . '/keys';
36
37 return $this->processResponse(
38 $this->client->get($this->fetchUrl($path))
39 );
40 }
41
42 /**
43 * Get a key.
44 *
45 * @param string $owner The name of the owner of the GitHub repository.
46 * @param string $repo The name of the GitHub repository.
47 * @param integer $id The id of the key.
48 *
49 * @since 12.4
50 *
51 * @return object
52 */
53 public function get($owner, $repo, $id)
54 {
55 // Build the request path.
56 $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id;
57
58 return $this->processResponse(
59 $this->client->get($this->fetchUrl($path))
60 );
61 }
62
63 /**
64 * Create a key.
65 *
66 * @param string $owner The name of the owner of the GitHub repository.
67 * @param string $repo The name of the GitHub repository.
68 * @param string $title The key title.
69 * @param string $key The key.
70 *
71 * @since 12.4
72 *
73 * @return object
74 */
75 public function create($owner, $repo, $title, $key)
76 {
77 // Build the request path.
78 $path = '/repos/' . $owner . '/' . $repo . '/keys';
79
80 $data = array(
81 'title' => $title,
82 'key' => $key,
83 );
84
85 return $this->processResponse(
86 $this->client->post($this->fetchUrl($path), json_encode($data)),
87 201
88 );
89 }
90
91 /**
92 * Edit a key.
93 *
94 * @param string $owner The name of the owner of the GitHub repository.
95 * @param string $repo The name of the GitHub repository.
96 * @param integer $id The id of the key.
97 * @param string $title The key title.
98 * @param string $key The key.
99 *
100 * @since 12.4
101 *
102 * @return object
103 */
104 public function edit($owner, $repo, $id, $title, $key)
105 {
106 // Build the request path.
107 $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id;
108
109 $data = array(
110 'title' => $title,
111 'key' => $key,
112 );
113
114 return $this->processResponse(
115 $this->client->patch($this->fetchUrl($path), json_encode($data))
116 );
117 }
118
119 /**
120 * Delete a key.
121 *
122 * @param string $owner The name of the owner of the GitHub repository.
123 * @param string $repo The name of the GitHub repository.
124 * @param integer $id The id of the key.
125 *
126 * @since 12.4
127 *
128 * @return boolean
129 */
130 public function delete($owner, $repo, $id)
131 {
132 // Build the request path.
133 $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id;
134
135 $this->processResponse(
136 $this->client->delete($this->fetchUrl($path)),
137 204
138 );
139
140 return true;
141 }
142 }
143