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 Activity Events class for the Joomla Platform.
14 *
15 * @documentation https://developer.github.com/v3/activity/starring/
16 *
17 * @since 3.3 (CMS)
18 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
19 */
20 class JGithubPackageActivityStarring extends JGithubPackage
21 {
22 /**
23 * List Stargazers.
24 *
25 * @param string $owner Repository owner.
26 * @param string $repo Repository name.
27 *
28 * @since 3.3 (CMS)
29 *
30 * @return mixed
31 */
32 public function getList($owner, $repo)
33 {
34 // Build the request path.
35 $path = '/repos/' . $owner . '/' . $repo . '/stargazers';
36
37 return $this->processResponse(
38 $this->client->get($this->fetchUrl($path))
39 );
40 }
41
42 /**
43 * List repositories being starred.
44 *
45 * List repositories being starred by a user.
46 *
47 * @param string $user User name.
48 *
49 * @since 3.3 (CMS)
50 *
51 * @return object
52 */
53 public function getRepositories($user = '')
54 {
55 // Build the request path.
56 $path = ($user)
57 ? '/users' . $user . '/starred'
58 : '/user/starred';
59
60 return $this->processResponse(
61 $this->client->get($this->fetchUrl($path))
62 );
63 }
64
65 /**
66 * Check if you are starring a repository.
67 *
68 * Requires for the user to be authenticated.
69 *
70 * @param string $owner Repository owner.
71 * @param string $repo Repository name.
72 *
73 * @throws UnexpectedValueException
74 * @since 3.3 (CMS)
75 *
76 * @return object
77 */
78 public function check($owner, $repo)
79 {
80 // Build the request path.
81 $path = '/user/starred/' . $owner . '/' . $repo;
82
83 $response = $this->client->get($this->fetchUrl($path));
84
85 switch ($response->code)
86 {
87 case '204' :
88 // This repository is watched by you.
89 return true;
90 break;
91
92 case '404' :
93 // This repository is not watched by you.
94 return false;
95 break;
96 }
97
98 throw new UnexpectedValueException('Unexpected response code: ' . $response->code);
99 }
100
101 /**
102 * Star a repository.
103 *
104 * Requires for the user to be authenticated.
105 *
106 * @param string $owner Repository owner.
107 * @param string $repo Repository name.
108 *
109 * @since 3.3 (CMS)
110 *
111 * @return object
112 */
113 public function star($owner, $repo)
114 {
115 // Build the request path.
116 $path = '/user/starred/' . $owner . '/' . $repo;
117
118 return $this->processResponse(
119 $this->client->put($this->fetchUrl($path), ''),
120 204
121 );
122 }
123
124 /**
125 * Unstar a repository.
126 *
127 * Requires for the user to be authenticated.
128 *
129 * @param string $owner Repository owner.
130 * @param string $repo Repository name.
131 *
132 * @since 3.3 (CMS)
133 *
134 * @return object
135 */
136 public function unstar($owner, $repo)
137 {
138 // Build the request path.
139 $path = '/user/starred/' . $owner . '/' . $repo;
140
141 return $this->processResponse(
142 $this->client->delete($this->fetchUrl($path)),
143 204
144 );
145 }
146 }
147