|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Part of the Joomla Framework Github Package |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. |
|
6
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Joomla\Github\Package; |
|
10
|
|
|
|
|
11
|
|
|
use Joomla\Github\AbstractPackage; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* GitHub API References class for the Joomla Framework. |
|
15
|
|
|
* |
|
16
|
|
|
* @documentation http://developer.github.com/v3/repos/users |
|
17
|
|
|
* |
|
18
|
|
|
* @since 1.0 |
|
19
|
|
|
* |
|
20
|
|
|
* @property-read Users\Emails $emails GitHub API object for emails. |
|
21
|
|
|
* @property-read Users\Followers $followers GitHub API object for followers. |
|
22
|
|
|
* @property-read Users\Keys $keys GitHub API object for keys. |
|
23
|
|
|
*/ |
|
24
|
|
|
class Users extends AbstractPackage |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Get a single user. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $user The users login name. |
|
30
|
|
|
* |
|
31
|
|
|
* @return object |
|
32
|
|
|
* |
|
33
|
|
|
* @since 1.0 |
|
34
|
|
|
* @throws \DomainException |
|
35
|
|
|
*/ |
|
36
|
|
|
public function get($user) |
|
37
|
|
|
{ |
|
38
|
|
|
// Build the request path. |
|
39
|
|
|
$path = '/users/' . $user; |
|
40
|
|
|
|
|
41
|
|
|
// Send the request. |
|
42
|
|
|
return $this->processResponse( |
|
43
|
|
|
$this->client->get($this->fetchUrl($path)) |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get the authenticated user. |
|
49
|
|
|
* |
|
50
|
|
|
* @return mixed |
|
51
|
|
|
* |
|
52
|
|
|
* @since 1.0 |
|
53
|
|
|
* @throws \DomainException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getAuthenticatedUser() |
|
56
|
|
|
{ |
|
57
|
|
|
// Build the request path. |
|
58
|
|
|
$path = '/user'; |
|
59
|
|
|
|
|
60
|
|
|
// Send the request. |
|
61
|
|
|
return $this->processResponse( |
|
62
|
|
|
$this->client->get($this->fetchUrl($path)) |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Update the authenticated user. |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $name The full name |
|
70
|
|
|
* @param string $email The email |
|
71
|
|
|
* @param string $blog The blog |
|
72
|
|
|
* @param string $company The company |
|
73
|
|
|
* @param string $location The location |
|
74
|
|
|
* @param string $hireable If he is unemployed :P |
|
75
|
|
|
* @param string $bio The biometrical DNA fingerprint (or smthng...) |
|
76
|
|
|
* |
|
77
|
|
|
* @return mixed |
|
78
|
|
|
* |
|
79
|
|
|
* @since 1.0 |
|
80
|
|
|
* @throws \DomainException |
|
81
|
|
|
*/ |
|
82
|
|
|
public function edit($name = '', $email = '', $blog = '', $company = '', $location = '', $hireable = '', $bio = '') |
|
83
|
|
|
{ |
|
84
|
|
|
$data = array( |
|
85
|
|
|
'name' => $name, |
|
86
|
|
|
'email' => $email, |
|
87
|
|
|
'blog' => $blog, |
|
88
|
|
|
'company' => $company, |
|
89
|
|
|
'location' => $location, |
|
90
|
|
|
'hireable' => $hireable, |
|
91
|
|
|
'bio' => $bio |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
|
|
// Build the request path. |
|
95
|
|
|
$path = '/user'; |
|
96
|
|
|
|
|
97
|
|
|
// Send the request. |
|
98
|
|
|
return $this->processResponse( |
|
99
|
|
|
$this->client->patch($this->fetchUrl($path), json_encode($data)) |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Get all users. |
|
105
|
|
|
* |
|
106
|
|
|
* This provides a dump of every user, in the order that they signed up for GitHub. |
|
107
|
|
|
* |
|
108
|
|
|
* @param integer $since The integer ID of the last User that you’ve seen. |
|
109
|
|
|
* |
|
110
|
|
|
* @return object |
|
111
|
|
|
* |
|
112
|
|
|
* @since 1.0 |
|
113
|
|
|
* @throws \DomainException |
|
114
|
|
|
*/ |
|
115
|
|
View Code Duplication |
public function getList($since = 0) |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
// Build the request path. |
|
118
|
|
|
$path = '/users'; |
|
119
|
|
|
|
|
120
|
|
|
$path .= ($since) ? '?since=' . $since : ''; |
|
121
|
|
|
|
|
122
|
|
|
// Send the request. |
|
123
|
|
|
return $this->processResponse( |
|
124
|
|
|
$this->client->get($this->fetchUrl($path)) |
|
125
|
|
|
); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.