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 Search class for the Joomla Platform.
14 *
15 * @documentation https://developer.github.com/v3/search
16 *
17 * @since 12.3
18 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
19 */
20 class JGithubPackageSearch extends JGithubPackage
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 * @throws UnexpectedValueException
31 *
32 * @since 3.3 (CMS)
33 *
34 * @return object
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 $start_page Page number to fetch
63 *
64 * @since 3.3 (CMS)
65 *
66 * @return object
67 */
68 public function repositories($keyword, $language = '', $start_page = 0)
69 {
70 // Build the request path.
71 $path = '/legacy/repos/search/' . $keyword . '?';
72
73 $path .= ($language) ? '&language=' . $language : '';
74 $path .= ($start_page) ? '&start_page=' . $start_page : '';
75
76 // Send the request.
77 return $this->processResponse(
78 $this->client->get($this->fetchUrl($path))
79 );
80 }
81
82 /**
83 * Search users.
84 *
85 * Find users by keyword.
86 *
87 * @param string $keyword The search term.
88 * @param integer $start_page Page number to fetch
89 *
90 * @since 3.3 (CMS)
91 *
92 * @return object
93 */
94 public function users($keyword, $start_page = 0)
95 {
96 // Build the request path.
97 $path = '/legacy/user/search/' . $keyword . '?';
98
99 $path .= ($start_page) ? '&start_page=' . $start_page : '';
100
101 // Send the request.
102 return $this->processResponse(
103 $this->client->get($this->fetchUrl($path))
104 );
105 }
106
107 /**
108 * Email search.
109 *
110 * This API call is added for compatibility reasons only. There’s no guarantee
111 * that full email searches will always be available. The @ character in the
112 * address must be left unencoded. Searches only against public email addresses
113 * (as configured on the user’s GitHub profile).
114 *
115 * @param string $email The email address(es).
116 *
117 * @since 3.3 (CMS)
118 *
119 * @return object
120 */
121 public function email($email)
122 {
123 // Build the request path.
124 $path = '/legacy/user/email/' . $email;
125
126 // Send the request.
127 return $this->processResponse(
128 $this->client->get($this->fetchUrl($path))
129 );
130 }
131 }
132