FOSSology  4.4.0
Open Source License Compliance by Open Source Software
RepositoryApi.php
Go to the documentation of this file.
1 <?php
2 # SPDX-FileCopyrightText: © Fossology contributors
3 
4 # SPDX-License-Identifier: GPL-2.0-only
5 
7 
18 {
23  private $curlRequestService = null;
24 
30  {
31  $this->curlRequestService = $curlRequestService;
32  }
33 
39  private function curlGet($apiRequest)
40  {
41  $url = 'https://api.github.com/repos/fossology/fossology/'.$apiRequest;
42 
43  $request = $this->curlRequestService->create($url);
44  $curlopt = array(
45  CURLOPT_HEADER => true,
46  CURLOPT_RETURNTRANSFER => true,
47  CURLOPT_HTTPHEADER => array('User-Agent: fossology'),
48  CURLOPT_TIMEOUT => 2,
49  );
50  $request->setOptions($curlopt);
51  $response = $request->execute();
52  if ($response !== false) {
53  $headerSize = $request->getInfo(CURLINFO_HEADER_SIZE);
54  $resultBody = json_decode(substr($response, $headerSize), true);
55  } else {
56  $resultBody = array();
57  }
58  $request->close();
59 
60  return $resultBody;
61  }
62 
67  public function getLatestRelease()
68  {
69  return $this->curlGet('releases/latest');
70  }
71 
77  public function getCommitsOfLastDays($days = 30)
78  {
79  $since = '?since=' . date('Y-m-d\\TH:i:s\\Z', time() - 3600 * 24 * $days);
80  return $this->curlGet('commits' . $since);
81  }
82 }
Helper class to get the latest release and commits from GitHub API.
getCommitsOfLastDays($days=30)
Get the commits from past n days.
curlGet($apiRequest)
Send a curl request to apiRequest for resource.
getLatestRelease()
Get the latest release info from GitHub.
Utility functions for specific applications.