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/followers
16 *
17 * @since 12.3
18 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
19 */
20 class JGithubPackageUsersFollowers extends JGithubPackage
21 {
22 /**
23 * List followers of a user.
24 *
25 * @param string $user The name of the user. If not set the current authenticated user will be used.
26 *
27 * @since 3.3 (CMS)
28 *
29 * @return object
30 */
31 public function getList($user = '')
32 {
33 // Build the request path.
34 $path = ($user)
35 ? '/users/' . $user . '/followers'
36 : '/user/followers';
37
38 return $this->processResponse(
39 $this->client->get($this->fetchUrl($path))
40 );
41 }
42
43 /**
44 * List users followed by another user.
45 *
46 * @param string $user The name of the user. If not set the current authenticated user will be used.
47 *
48 * @since 3.3 (CMS)
49 *
50 * @return object
51 */
52 public function getListFollowedBy($user = '')
53 {
54 // Build the request path.
55 $path = ($user)
56 ? '/users/' . $user . '/following'
57 : '/user/following';
58
59 return $this->processResponse(
60 $this->client->get($this->fetchUrl($path))
61 );
62 }
63
64 /**
65 * Check if you are following a user.
66 *
67 * @param string $user The name of the user.
68 *
69 * @throws UnexpectedValueException
70 * @since 3.3 (CMS)
71 *
72 * @return boolean
73 */
74 public function check($user)
75 {
76 // Build the request path.
77 $path = '/user/following/' . $user;
78
79 $response = $this->client->get($this->fetchUrl($path));
80
81 switch ($response->code)
82 {
83 case '204' :
84 // You are following this user
85 return true;
86 break;
87
88 case '404' :
89 // You are not following this user
90 return false;
91 break;
92
93 default :
94 throw new UnexpectedValueException('Unexpected response code: ' . $response->code);
95 break;
96 }
97 }
98
99 /**
100 * Follow a user.
101 *
102 * Following a user requires the user to be logged in and authenticated with
103 * basic auth or OAuth with the user:follow scope.
104 *
105 * @param string $user The name of the user.
106 *
107 * @since 3.3 (CMS)
108 *
109 * @return object
110 */
111 public function follow($user)
112 {
113 // Build the request path.
114 $path = '/user/following/' . $user;
115
116 return $this->processResponse(
117 $this->client->put($this->fetchUrl($path), ''),
118 204
119 );
120 }
121
122 /**
123 * Unfollow a user.
124 *
125 * Unfollowing a user requires the user to be logged in and authenticated with
126 * basic auth or OAuth with the user:follow scope.
127 *
128 * @param string $user The name of the user.
129 *
130 * @since 3.3 (CMS)
131 *
132 * @return object
133 */
134 public function unfollow($user)
135 {
136 // Build the request path.
137 $path = '/user/following/' . $user;
138
139 return $this->processResponse(
140 $this->client->delete($this->fetchUrl($path)),
141 204
142 );
143 }
144 }
145