-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
50 lines (40 loc) · 1 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Dotenv\Dotenv;
use GuzzleHttp\Psr7;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
/**
* Carregando variaveis de ambiente
*/
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
/**
* Criando um instancia imutavel do cliente Guzzle
* @var GuzzleHttp\Client
*/
$client = new Client([
'base_uri' => $_ENV['GITHUB_API_URL'],
'timeout' => 2.0,
'headers' => [
'Accept' => 'application/json',
'Content-type' => 'application/json',
'Authorization' => 'Bearer ' . $_ENV['GITHUB_TOKEN']
]
]);
/**
* Testando integração com á API REST do Gravatar
*/
try {
$data = [
'json' => [
'description' => 'Integração com API Github usando Guzzle'
]
];
$response = $client->patch('repos/walissonaguirra/guzzle-github', $data);
echo $response->getBody();
} catch (ClientException $e) {
echo Psr7\Message::toString($e->getRequest());
echo Psr7\Message::toString($e->getResponse());
}