FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
RepositoryApi.php
Go to the documentation of this file.
1 <?php
2 /*
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 version 2 as published by the Free Software Foundation.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11 
12 You should have received a copy of the GNU General Public License along
13 with this program; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 */
16 
18 
29 {
34  private $curlRequestService = null;
35 
41  {
42  $this->curlRequestService = $curlRequestService;
43  }
44 
50  private function curlGet($apiRequest)
51  {
52  $url = 'https://api.github.com/repos/fossology/fossology/'.$apiRequest;
53 
54  $request = $this->curlRequestService->create($url);
55  $curlopt = array(
56  CURLOPT_HEADER => true,
57  CURLOPT_RETURNTRANSFER => true,
58  CURLOPT_HTTPHEADER => array('User-Agent: fossology'),
59  CURLOPT_TIMEOUT => 2,
60  );
61  $request->setOptions($curlopt);
62  $response = $request->execute();
63  if ($response !== false) {
64  $headerSize = $request->getInfo(CURLINFO_HEADER_SIZE);
65  $resultBody = json_decode(substr($response, $headerSize), true);
66  } else {
67  $resultBody = array();
68  }
69  $request->close();
70 
71  return $resultBody;
72  }
73 
78  public function getLatestRelease()
79  {
80  return $this->curlGet('releases/latest');
81  }
82 
88  public function getCommitsOfLastDays($days = 30)
89  {
90  $since = '?since=' . date('Y-m-d\\TH:i:s\\Z', time() - 3600 * 24 * $days);
91  return $this->curlGet('commits' . $since);
92  }
93 }
getLatestRelease()
Get the latest release info from GitHub.
Helper class to get the latest release and commits from GitHub API.
Utility functions for specific applications.
getCommitsOfLastDays($days=30)
Get the commits from past n days.
curlGet($apiRequest)
Send a curl request to apiRequest for resource.