|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Part of the Joomla Framework Github Package |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (C) 2005 - 2018 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 Search class for the Joomla Framework. |
|
15
|
|
|
* |
|
16
|
|
|
* @link https://developer.github.com/v3/search |
|
17
|
|
|
* |
|
18
|
|
|
* @since 1.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
class Search extends AbstractPackage |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Search issues. |
|
24
|
|
|
* |
|
25
|
|
|
* @param string $owner The name of the owner of the repository. |
|
26
|
|
|
* @param string $repo The name of the repository. |
|
27
|
|
|
* @param string $state The state - open or closed. |
|
28
|
|
|
* @param string $keyword The search term. |
|
29
|
|
|
* |
|
30
|
|
|
* @return object |
|
31
|
|
|
* |
|
32
|
|
|
* @since 1.0 |
|
33
|
|
|
* @throws \UnexpectedValueException |
|
34
|
|
|
* @deprecated The legacy API is deprecated |
|
35
|
|
|
*/ |
|
36
|
|
|
public function issues($owner, $repo, $state, $keyword) |
|
37
|
|
|
{ |
|
38
|
|
|
if (false == in_array($state, array('open', 'close'))) |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
throw new \UnexpectedValueException('State must be either "open" or "closed"'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
// Build the request path. |
|
44
|
|
|
$path = '/legacy/issues/search/' . $owner . '/' . $repo . '/' . $state . '/' . $keyword; |
|
45
|
|
|
|
|
46
|
|
|
// Send the request. |
|
47
|
|
|
return $this->processResponse( |
|
48
|
|
|
$this->client->get($this->fetchUrl($path)) |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Search repositories. |
|
54
|
|
|
* |
|
55
|
|
|
* Find repositories by keyword. Note, this legacy method does not follow |
|
56
|
|
|
* the v3 pagination pattern. |
|
57
|
|
|
* This method returns up to 100 results per page and pages can be fetched |
|
58
|
|
|
* using the start_page parameter. |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $keyword The search term. |
|
61
|
|
|
* @param string $language Filter results by language https://github.com/languages |
|
62
|
|
|
* @param integer $startPage Page number to fetch |
|
63
|
|
|
* |
|
64
|
|
|
* @return object |
|
65
|
|
|
* |
|
66
|
|
|
* @since 1.0 |
|
67
|
|
|
* @deprecated The legacy API is deprecated |
|
68
|
|
|
*/ |
|
69
|
|
View Code Duplication |
public function repositories($keyword, $language = '', $startPage = 0) |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
// Build the request path. |
|
72
|
|
|
$path = '/legacy/repos/search/' . $keyword . '?'; |
|
73
|
|
|
|
|
74
|
|
|
$path .= ($language) ? '&language=' . $language : ''; |
|
75
|
|
|
$path .= ($startPage) ? '&start_page=' . $startPage : ''; |
|
76
|
|
|
|
|
77
|
|
|
// Send the request. |
|
78
|
|
|
return $this->processResponse( |
|
79
|
|
|
$this->client->get($this->fetchUrl($path)) |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Search users. |
|
85
|
|
|
* |
|
86
|
|
|
* Find users by keyword. |
|
87
|
|
|
* |
|
88
|
|
|
* @param string $keyword The search term. |
|
89
|
|
|
* @param integer $startPage Page number to fetch |
|
90
|
|
|
* |
|
91
|
|
|
* @return object |
|
92
|
|
|
* |
|
93
|
|
|
* @since 1.0 |
|
94
|
|
|
* @deprecated The legacy API is deprecated |
|
95
|
|
|
*/ |
|
96
|
|
View Code Duplication |
public function users($keyword, $startPage = 0) |
|
|
|
|
|
|
97
|
|
|
{ |
|
98
|
|
|
// Build the request path. |
|
99
|
|
|
$path = '/legacy/user/search/' . $keyword . '?'; |
|
100
|
|
|
|
|
101
|
|
|
$path .= ($startPage) ? '&start_page=' . $startPage : ''; |
|
102
|
|
|
|
|
103
|
|
|
// Send the request. |
|
104
|
|
|
return $this->processResponse( |
|
105
|
|
|
$this->client->get($this->fetchUrl($path)) |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Email search. |
|
111
|
|
|
* |
|
112
|
|
|
* This API call is added for compatibility reasons only. There’s no guarantee |
|
113
|
|
|
* that full email searches will always be available. The @ character in the |
|
114
|
|
|
* address must be left unencoded. Searches only against public email addresses |
|
115
|
|
|
* (as configured on the user’s GitHub profile). |
|
116
|
|
|
* |
|
117
|
|
|
* @param string $email The email address(es). |
|
118
|
|
|
* |
|
119
|
|
|
* @return object |
|
120
|
|
|
* |
|
121
|
|
|
* @since 1.0 |
|
122
|
|
|
* @deprecated The legacy API is deprecated |
|
123
|
|
|
*/ |
|
124
|
|
|
public function email($email) |
|
125
|
|
|
{ |
|
126
|
|
|
// Build the request path. |
|
127
|
|
|
$path = '/legacy/user/email/' . $email; |
|
128
|
|
|
|
|
129
|
|
|
// Send the request. |
|
130
|
|
|
return $this->processResponse( |
|
131
|
|
|
$this->client->get($this->fetchUrl($path)) |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.