|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Andreshg112\TecniRtm; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
|
6
|
|
|
|
|
7
|
|
|
class TecniRtm |
|
8
|
|
|
{ |
|
9
|
|
|
/** @var string $apiKey Llave de la API suministrada por Tecni-RTM. */ |
|
10
|
|
|
protected $apiKey = null; |
|
11
|
|
|
|
|
12
|
|
|
/** @var Client $http */ |
|
13
|
|
|
protected $http = null; |
|
14
|
|
|
|
|
15
|
|
|
/** @var string $host URL o IP donde se encuentra instalado Tecni-RTM. */ |
|
16
|
|
|
protected $host = null; |
|
17
|
|
|
|
|
18
|
|
|
/** @var string $secret Secreto de la API. */ |
|
19
|
|
|
protected $secret = null; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Crea una instancia recibiendo la llave y el secreto. |
|
23
|
|
|
* Si no se pasan los parámetros, los toma de config/tecni-rtm.php (Solo Laravel). |
|
24
|
|
|
*/ |
|
25
|
4 |
|
public function __construct(Client $http = null) |
|
26
|
|
|
{ |
|
27
|
4 |
|
$this->http = isset($http) ? $http : new Client(); |
|
28
|
4 |
|
$this->host = config('tecni-rtm.host'); |
|
29
|
4 |
|
$this->apiKey = config('tecni-rtm.api_key'); |
|
30
|
4 |
|
$this->secret = config('tecni-rtm.secret'); |
|
31
|
4 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Consulta las revisiones terminadas durante el día de hoy. |
|
35
|
|
|
* |
|
36
|
|
|
* @return array |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function completedReviews() |
|
39
|
|
|
{ |
|
40
|
1 |
|
$url = "{$this->host}/api/revisiones-terminadas"; |
|
41
|
1 |
|
$timestamp = time(); |
|
42
|
1 |
|
$payload = config('tecni-rtm.payload'); |
|
43
|
1 |
|
$signature = hash('sha256', $payload . $timestamp . $this->secret); |
|
44
|
|
|
|
|
45
|
|
|
$json = [ |
|
46
|
1 |
|
'api_key' => $this->apiKey, 'timestamp' => $timestamp, 'signature' => $signature, |
|
47
|
1 |
|
'payload' => $payload, |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
1 |
|
$response = $this->http->post($url, ['json' => $json]); |
|
51
|
|
|
|
|
52
|
1 |
|
$result = json_decode((string)$response->getBody(), true); |
|
53
|
1 |
|
$payloadResponse = json_decode($result['payload'], true); |
|
54
|
|
|
|
|
55
|
1 |
|
return $payloadResponse; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Consulta las revisiones en curso. |
|
60
|
|
|
* |
|
61
|
|
|
* @return array |
|
62
|
|
|
*/ |
|
63
|
1 |
|
public function ongoingReviews() |
|
64
|
|
|
{ |
|
65
|
1 |
|
$url = "{$this->host}/api/revisiones-en-curso"; |
|
66
|
1 |
|
$timestamp = time(); |
|
67
|
1 |
|
$signature = hash('sha256', $timestamp . $this->secret); |
|
68
|
|
|
|
|
69
|
1 |
|
$json = ['api_key' => $this->apiKey, 'timestamp' => $timestamp, 'signature' => $signature]; |
|
70
|
|
|
|
|
71
|
1 |
|
$response = $this->http->post($url, ['json' => $json]); |
|
72
|
|
|
|
|
73
|
1 |
|
$result = json_decode((string)$response->getBody(), true); |
|
74
|
1 |
|
$payload = json_decode($result['payload'], true); |
|
75
|
|
|
|
|
76
|
1 |
|
return $payload; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|