|
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\Users; |
|
10
|
|
|
|
|
11
|
|
|
use Joomla\Github\AbstractPackage; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* GitHub API Emails class for the Joomla Framework. |
|
15
|
|
|
* |
|
16
|
|
|
* Management of email addresses via the API requires that you are authenticated |
|
17
|
|
|
* through basic auth or OAuth with the user scope. |
|
18
|
|
|
* |
|
19
|
|
|
* @documentation http://developer.github.com/v3/repos/users/emails |
|
20
|
|
|
* |
|
21
|
|
|
* @since 1.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
class Emails extends AbstractPackage |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* List email addresses for a user. |
|
27
|
|
|
* |
|
28
|
|
|
* @return object |
|
29
|
|
|
* |
|
30
|
|
|
* @since 1.0 |
|
31
|
|
|
*/ |
|
32
|
|
|
public function getList() |
|
33
|
|
|
{ |
|
34
|
|
|
// Build the request path. |
|
35
|
|
|
$path = '/user/emails'; |
|
36
|
|
|
|
|
37
|
|
|
return $this->processResponse( |
|
38
|
|
|
$this->client->get($this->fetchUrl($path)) |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Add email address(es). |
|
44
|
|
|
* |
|
45
|
|
|
* @param string|array $email The email address(es). |
|
46
|
|
|
* |
|
47
|
|
|
* @return object |
|
48
|
|
|
* |
|
49
|
|
|
* @since 1.0 |
|
50
|
|
|
*/ |
|
51
|
|
View Code Duplication |
public function add($email) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
// Build the request path. |
|
54
|
|
|
$path = '/user/emails'; |
|
55
|
|
|
|
|
56
|
|
|
return $this->processResponse( |
|
57
|
|
|
$this->client->post($this->fetchUrl($path), json_encode($email)), |
|
58
|
|
|
201 |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Delete email address(es). |
|
64
|
|
|
* |
|
65
|
|
|
* @param string|array $email The email address(es). |
|
66
|
|
|
* |
|
67
|
|
|
* @return object |
|
68
|
|
|
* |
|
69
|
|
|
* @since 1.0 |
|
70
|
|
|
*/ |
|
71
|
|
View Code Duplication |
public function delete($email) |
|
|
|
|
|
|
72
|
|
|
{ |
|
73
|
|
|
// Build the request path. |
|
74
|
|
|
$path = '/user/emails'; |
|
75
|
|
|
|
|
76
|
|
|
$this->client->setOption('body', json_encode($email)); |
|
77
|
|
|
|
|
78
|
|
|
return $this->processResponse( |
|
79
|
|
|
$this->client->delete($this->fetchUrl($path)), |
|
80
|
|
|
204 |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
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.