|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Gameap\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Gameap\Models\Game; |
|
6
|
|
|
use Gameap\Models\GameMod; |
|
7
|
|
|
use Gameap\Exceptions\Services\GlobalApiException; |
|
8
|
|
|
use GuzzleHttp\Client; |
|
9
|
|
|
use GuzzleHttp\RequestOptions; |
|
10
|
|
|
use GuzzleHttp\Exception\ClientException; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
use Config; |
|
13
|
|
|
|
|
14
|
|
|
class GlobalApi |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @return array |
|
18
|
|
|
* @throws GlobalApiException |
|
19
|
|
|
*/ |
|
20
|
|
|
public static function games() |
|
21
|
|
|
{ |
|
22
|
|
|
try { |
|
23
|
|
|
$client = new Client(['headers' => ['Accept: application/json']]); |
|
24
|
|
|
$res = $client->get(config('app.global_api') . '/games'); |
|
25
|
|
|
$status = $res->getStatusCode(); |
|
26
|
|
|
} catch (ClientException $e) { |
|
27
|
|
|
throw new GlobalApiException($e->getMessage()); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
if ($status != Response::HTTP_OK) { |
|
31
|
|
|
throw new GlobalApiException('Unexpected HTTP status code: ' . $status); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$json = $res->getBody()->getContents(); |
|
35
|
|
|
$results = json_decode($json, true); |
|
36
|
|
|
|
|
37
|
|
|
if (empty($results['success']) || $results['success'] != true) { |
|
38
|
|
|
throw new GlobalApiException('API Error'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return $results['data']; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param $summary |
|
46
|
|
|
* @param $description |
|
47
|
|
|
* @param $environment |
|
48
|
|
|
* @return bool |
|
49
|
|
|
* @throws GlobalApiException |
|
50
|
|
|
*/ |
|
51
|
|
|
public static function sendBug($summary, $description, $environment = '') |
|
52
|
|
|
{ |
|
53
|
|
|
$version = Config::get('constants.AP_VERSION'); |
|
54
|
|
|
|
|
55
|
|
|
$environment .= 'PHP version: ' . phpversion() . "\n"; |
|
56
|
|
|
$environment .= php_uname() . "\n"; |
|
57
|
|
|
|
|
58
|
|
|
$ar = compact('version', 'summary', 'description', 'environment'); |
|
|
|
|
|
|
59
|
|
|
try { |
|
60
|
|
|
$client = new Client(['headers' => ['Accept' => 'application/json']]); |
|
61
|
|
|
|
|
62
|
|
|
$res = $client->post( |
|
63
|
|
|
config('app.global_api') . '/bugs', |
|
64
|
|
|
[ |
|
65
|
|
|
RequestOptions::JSON => compact('version', 'summary', 'description', 'environment'), |
|
66
|
|
|
] |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
$status = $res->getStatusCode(); |
|
70
|
|
|
} catch (ClientException $e) { |
|
71
|
|
|
throw new GlobalApiException($e->getMessage()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if ($status != Response::HTTP_CREATED) { |
|
75
|
|
|
throw new GlobalApiException('Unexpected HTTP status code: ' . $status); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return true; |
|
79
|
|
|
} |
|
80
|
|
|
} |