1<?php
2/*
3 * Jenkins API
4 * @author Algorys
5 */
6class DokuwikiJenkins {
7    public $client;
8    public $url;
9
10    function __construct($data) {
11        $this->client = curl_init();
12        $this->url = $data['protocol'].'://'.$data['user'].':'.$data['token'].'@'.$data['url'];
13    }
14
15    function request($url, $build = false) {
16        if ($build)
17            $url_srv = $this->url . $url . '/api/json';
18        else
19            $url_srv = $this->url . $url . '/lastBuild/api/json';
20
21        curl_setopt($this->client, CURLOPT_URL, $url_srv);
22        curl_setopt($this->client, CURLOPT_HTTPHEADER, array(
23            'Content-Type: application/json',
24            'Accept: application/json'
25        ));
26        curl_setopt($this->client, CURLOPT_RETURNTRANSFER, true);
27
28        $answer = curl_exec($this->client);
29        $answer_decoded = json_decode($answer, true);
30
31        return $answer_decoded;
32    }
33
34    function getJobURLRequest($job) {
35        $job_request = explode('/', $job);
36
37        $job_url = '';
38        foreach ($job_request as $key => $job_part) {
39            $job_url .= '/job/'.$job_part;
40        }
41
42        return $job_url;
43    }
44
45    function getWeatherImg($url) {
46        $request = $this->request($url, true);
47        $weather = $request['healthReport'][0]['iconUrl'];
48
49        return $weather;
50    }
51}
52