1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Data Analytics |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the LICENSE.md file. |
7
|
|
|
* |
8
|
|
|
* @author Marcel Scherello <[email protected]> |
9
|
|
|
* @copyright 2019 Marcel Scherello |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\Analytics\Datasource; |
13
|
|
|
|
14
|
|
|
use OCA\Analytics\Controller\DbController; |
15
|
|
|
use OCP\ILogger; |
16
|
|
|
|
17
|
|
|
class GithubService |
18
|
|
|
{ |
19
|
|
|
private $logger; |
20
|
|
|
private $DBController; |
21
|
|
|
|
22
|
|
|
public function __construct( |
23
|
|
|
ILogger $logger, |
24
|
|
|
DbController $DBController |
25
|
|
|
) |
26
|
|
|
{ |
27
|
|
|
$this->logger = $logger; |
28
|
|
|
$this->DBController = $DBController; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Get the items for the selected category |
33
|
|
|
* |
34
|
|
|
* @NoAdminRequired |
35
|
|
|
* @param $datasetMetadata |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
public function read($datasetMetadata) |
39
|
|
|
{ |
40
|
|
|
$string = 'https://api.github.com/repos/' . $datasetMetadata['link'] . '/releases'; |
41
|
|
|
|
42
|
|
|
$ch = curl_init(); |
43
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); |
|
|
|
|
44
|
|
|
curl_setopt($ch, CURLOPT_HEADER, false); |
45
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
46
|
|
|
curl_setopt($ch, CURLOPT_URL, $string); |
47
|
|
|
curl_setopt($ch, CURLOPT_REFERER, $string); |
48
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
49
|
|
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); |
50
|
|
|
$result = curl_exec($ch); |
|
|
|
|
51
|
|
|
curl_close($ch); |
|
|
|
|
52
|
|
|
#echo $result; |
53
|
|
|
|
54
|
|
|
$jason_a = json_decode($result, true); |
55
|
|
|
$i = 0; |
56
|
|
|
|
57
|
|
|
//$tagName = $jason_a[0]['tag_name']; |
58
|
|
|
//$tagVariable = 'tag_name'; |
59
|
|
|
//$tagName = $jason_a[0][$tagVariable]; |
60
|
|
|
//$count = $jason_a[0] . assets . download_cont; |
61
|
|
|
//$this->logger->error($tagName . $count); |
62
|
|
|
|
63
|
|
|
$data = array(); |
64
|
|
|
foreach ($jason_a as $item) { |
65
|
|
|
if ($i === 15) break; |
66
|
|
|
$nc_value = 0; |
67
|
|
|
foreach ($item['assets'] as $asset) { |
68
|
|
|
if (substr($asset['name'], -2) == 'gz') $nc_value = $asset['download_count']; |
69
|
|
|
} |
70
|
|
|
array_push($data, ['dimension2' => $item['tag_name'], 'dimension3' => $nc_value]); |
71
|
|
|
$i++; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$header = array(); |
75
|
|
|
$header['dimension1'] = ''; |
76
|
|
|
$header['dimension2'] = 'Version'; |
77
|
|
|
$header['dimension3'] = 'Count'; |
78
|
|
|
|
79
|
|
|
$result = [ |
80
|
|
|
'header' => $header, |
81
|
|
|
'data' => $data |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
return $result; |
85
|
|
|
} |
86
|
|
|
} |