Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atualização para novo formato da API SUAP #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ $suap = SUAP();
$data = $suap->autenticar('20121014040000', 'senhaouchave');
```

O método retornará um array com um token de acesso (`$data['token']`).
O método retornará um array com um token de acesso (`$data['access']`) e outro de renovação (`$data['refresh']`).
```
Array
(
[token] => eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJ1c2VybmFtZSI6IjIwMTIxMDE0MDQwMDgzIiwib3JpZ19pYXQiOjE0OTQwMjcyMDksInVzZXJfaWQiOjEwODQyLCJlbWFpbCI6Iml2YW5pbHNvbi5tZWxvQGFjYWRlbWljby5pZnJuLmVkdS5iciIsImV4cCI6MTQ5NDExMzYwOX0
[refresh] => eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTY1OTExODcxNCwiaWF0IjoxNjU5MDMyMzE0LCJqdGkiOiI3MGNkOWFhZDVmZmU0ZWU4YjliZWQ1Yjk5ODE0MTNjZiIsInVzZXJfaWQiOjQzODR9._42_QxSkUKr_Xq6vWiq97jjicnA6Buaij9Sckc-9PWs
[access] => eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjU5MDMyNjE0LCJpYXQiOjE2NTkwMzIzMTQsImp0aSI6IjhjNWY5Mjk4MTk2ODQ4NmFhMDIzNzBmYmQxYWQ3ZTYyIiwidXNlcl9pZCI6NDM4NH0.wC9KkHj76aj1plYHbr0HRUSxqG7BUjXX_Bc-Sa-7yO8
)
```

Expand Down Expand Up @@ -710,7 +711,15 @@ $ cd tests
$ php test.php <matricula> <chave>
```

Altere o arquivo `test.php` de acordo com a sua preferência, mas evite comitar mudanças a menos que tenha adicionado alguma funcionalidade nova a biblioteca.
Utilize a chave *access* retornada acima para testar as demais requisições.
Elas funcionarão por completo apenas se a matrícula utilizada anteriormente
for de estudante:

```bash
$ php test.php <access>
```

Altere o arquivo `test.php` de acordo com a sua preferência, mas evite commits com mudanças a menos que tenha adicionado alguma funcionalidade nova a biblioteca.

O código em desenvolvimento mais recente está na branch `master`.

Expand Down
6 changes: 3 additions & 3 deletions src/Ivmelo/SUAP/SUAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public function autenticar($username, $password, $accessKey = false, $setToken =
$data = json_decode($response->getBody(), true);

// Seta o token se solicitado. Padrão é true.
if ($setToken && isset($data['token'])) {
$this->setToken($data['token']);
if ($setToken && isset($data['access'])) {
$this->setToken($data['access']);
}
}

Expand Down Expand Up @@ -252,7 +252,7 @@ private function doGetRequest($url)
{
$response = $this->client->request('GET', $url, [
'headers' => [
'Authorization' => 'JWT '.$this->token,
'Authorization' => 'Bearer '.$this->token,
],
]);

Expand Down
4 changes: 2 additions & 2 deletions tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Recebe argumentos do terminal.
*
* Para pegar um Token:
* $ php test.php <student_id> <acess_key>
* $ php test.php <student_id> <access_key>
*
* Depois, você pode usar o token para fazer os requests:
* $ php test.php <token>
Expand Down Expand Up @@ -55,7 +55,7 @@
print_r($client->getHorarios($year, $term));
} else {
// Autentica e retorna token.
print_r($client->autenticar($student_id, $suap_key, true));
print_r($client->autenticar($student_id, $suap_key, false, true));
}
} catch (Exception $e) {
// Mostrar erros.
Expand Down