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
 16  *
 17  * @since       12.3
 18  * @deprecated  4.0  Use the `joomla/github` package via Composer instead
 19  */
 20 class JGithubPackageUsers extends JGithubPackage
 21 {
 22     protected $name = 'Users';
 23 
 24     protected $packages = array('emails', 'followers', 'keys');
 25 
 26     /**
 27      * Get a single user.
 28      *
 29      * @param   string  $user  The users login name.
 30      *
 31      * @throws DomainException
 32      *
 33      * @return object
 34      */
 35     public function get($user)
 36     {
 37         // Build the request path.
 38         $path = '/users/' . $user;
 39 
 40         // Send the request.
 41         return $this->processResponse(
 42             $this->client->get($this->fetchUrl($path))
 43         );
 44     }
 45 
 46     /**
 47      * Get the current authenticated user.
 48      *
 49      * @throws DomainException
 50      *
 51      * @return mixed
 52      */
 53     public function getAuthenticatedUser()
 54     {
 55         // Build the request path.
 56         $path = '/user';
 57 
 58         // Send the request.
 59         return $this->processResponse(
 60             $this->client->get($this->fetchUrl($path))
 61         );
 62     }
 63 
 64     /**
 65      * Update a user.
 66      *
 67      * @param   string  $name      The full name
 68      * @param   string  $email     The email
 69      * @param   string  $blog      The blog
 70      * @param   string  $company   The company
 71      * @param   string  $location  The location
 72      * @param   string  $hireable  If he is unemplayed :P
 73      * @param   string  $bio       The biometrical DNA fingerprint (or smthng...)
 74      *
 75      * @throws DomainException
 76      *
 77      * @return mixed
 78      */
 79     public function edit($name = '', $email = '', $blog = '', $company = '', $location = '', $hireable = '', $bio = '')
 80     {
 81         $data = array(
 82             'name'     => $name,
 83             'email'    => $email,
 84             'blog'     => $blog,
 85             'company'  => $company,
 86             'location' => $location,
 87             'hireable' => $hireable,
 88             'bio'      => $bio,
 89         );
 90 
 91         // Build the request path.
 92         $path = '/user';
 93 
 94         // Send the request.
 95         return $this->processResponse(
 96             $this->client->patch($this->fetchUrl($path), json_encode($data))
 97         );
 98     }
 99 
100     /**
101      * Get all users.
102      *
103      * This provides a dump of every user, in the order that they signed up for GitHub.
104      *
105      * @param   integer  $since  The integer ID of the last User that you’ve seen.
106      *
107      * @throws DomainException
108      * @return mixed
109      */
110     public function getList($since = 0)
111     {
112         // Build the request path.
113         $path = '/users';
114 
115         $path .= ($since) ? '?since=' . $since : '';
116 
117         // Send the request.
118         return $this->processResponse(
119             $this->client->get($this->fetchUrl($path))
120         );
121     }
122 
123     /*
124      * Legacy methods
125      */
126 
127     /**
128      * Get a single user.
129      *
130      * @param   string  $user  The users login name.
131      *
132      * @deprecated use users->get()
133      *
134      * @throws DomainException
135      *
136      * @return mixed
137      */
138     public function getUser($user)
139     {
140         return $this->get($user);
141     }
142 
143     /**
144      * Update a user.
145      *
146      * @param   string  $name      The full name
147      * @param   string  $email     The email
148      * @param   string  $blog      The blog
149      * @param   string  $company   The company
150      * @param   string  $location  The location
151      * @param   string  $hireable  If he is unemplayed :P
152      * @param   string  $bio       The biometrical DNA fingerprint (or smthng...)
153      *
154      * @deprecated use users->edit()
155      *
156      * @throws DomainException
157      *
158      * @return mixed
159      */
160     public function updateUser($name = '', $email = '', $blog = '', $company = '', $location = '', $hireable = '', $bio = '')
161     {
162         return $this->edit($name = '', $email = '', $blog = '', $company = '', $location = '', $hireable = '', $bio = '');
163     }
164 
165     /**
166      * Get all users.
167      *
168      * This provides a dump of every user, in the order that they signed up for GitHub.
169      *
170      * @param   integer  $since  The integer ID of the last User that you’ve seen.
171      *
172      * @deprecated use users->getList()
173      *
174      * @throws DomainException
175      * @return mixed
176      */
177     public function getUsers($since = 0)
178     {
179         return $this->getList($since);
180     }
181 }
182