├── .gitignore ├── composer.json ├── LICENSE ├── tests └── test.php ├── src └── Ivmelo │ └── SUAP │ └── SUAP.php ├── composer.lock └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | vendor/ 3 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ivmelo/suap-api-php", 3 | "description": "Wrapper PHP para a API do SUAP.", 4 | "type": "library", 5 | "require": { 6 | "guzzlehttp/guzzle": "~6.0" 7 | }, 8 | "license": "MIT", 9 | "authors": [ 10 | { 11 | "name": "Ivanilson Melo", 12 | "email": "meloivanilson@gmail.com" 13 | } 14 | ], 15 | "autoload": { 16 | "psr-0": { 17 | "Ivmelo\\SUAP": "src/" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Ivanilson Melo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tests/test.php: -------------------------------------------------------------------------------- 1 | 16 | * 17 | * Depois, você pode usar o token para fazer os requests: 18 | * $ php test.php 19 | * 20 | */ 21 | if (count($argv) == 2) { 22 | $token = $argv[1]; 23 | } else { 24 | $student_id = $argv[1]; 25 | $suap_key = $argv[2]; 26 | } 27 | 28 | try { 29 | $client = new SUAP(); 30 | 31 | if (isset($token)) { 32 | // Se desejar, você pode passar o token no construtor. 33 | $client->setToken($token); 34 | 35 | // Meus Dados. 36 | print_r($client->getMeusDados()); 37 | 38 | // Períodos Letivos. 39 | $periodosLetivos = $client->getMeusPeriodosLetivos(); 40 | print_r($periodosLetivos); 41 | $year = end($periodosLetivos)['ano_letivo']; 42 | $term = end($periodosLetivos)['periodo_letivo']; 43 | 44 | // Boletim. 45 | print_r($client->getMeuBoletim($year, $term)); 46 | 47 | // Turmas Virtuais. 48 | $turmasVirtuais = $client->getTurmasVirtuais($year, $term); 49 | print_r($turmasVirtuais); 50 | 51 | // Detalhes de Turma Virtual. 52 | print_r($client->getTurmaVirtual(end($turmasVirtuais)['id'])); 53 | 54 | // Horários. 55 | print_r($client->getHorarios($year, $term)); 56 | } else { 57 | // Autentica e retorna token. 58 | print_r($client->autenticar($student_id, $suap_key, true)); 59 | } 60 | } catch (Exception $e) { 61 | // Mostrar erros. 62 | echo $e; 63 | } 64 | -------------------------------------------------------------------------------- /src/Ivmelo/SUAP/SUAP.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class SUAP 13 | { 14 | /** 15 | * O token de acesso do usuário. Tokens tem 24 horas de validade. 16 | * 17 | * @var string Token de acesso. 18 | */ 19 | private $token; 20 | 21 | /** 22 | * Endpoint do SUAP. 23 | * 24 | * @var string Endpoint de acesso ao suap. 25 | */ 26 | private $endpoint = 'https://suap.ifrn.edu.br/api/v2/'; 27 | 28 | /** 29 | * Um cliente GuzzleHttp para fazer os requests HTTP. 30 | * 31 | * @var GuzzleHttp\Client Cliente GuzzleHttp. 32 | */ 33 | private $client; 34 | 35 | /** 36 | * Construtor. Pode ser vazio ou receber um token de acesso. 37 | * 38 | * @param string $token Token de acesso. 39 | */ 40 | public function __construct($token = false) 41 | { 42 | if ($token) { 43 | $this->setToken($token); 44 | } 45 | 46 | // Create and use a guzzle client instance that will time out after 10 seconds 47 | $this->client = new Client([ 48 | 'timeout' => 10, 49 | 'connect_timeout' => 10, 50 | ]); 51 | } 52 | 53 | /** 54 | * Autentica o usuário e retorna um token de acesso. 55 | * Pode-se usar a senha ou chave de acesso do aluno. 56 | * 57 | * @param string $username Matrícula do aluno. 58 | * @param string $password Senha do aluno ou chave de acesso do responsável. 59 | * @param bool $accessKey Define se o login é por chave de acesso. 60 | * @param bool $setToken Define se deve salvar o token para requests subsequentes. 61 | * 62 | * @return array $data Array contendo o token de acesso. 63 | */ 64 | public function autenticar($username, $password, $accessKey = false, $setToken = true) 65 | { 66 | // Se estiver acessando com uma chave de acesso... 67 | if ($accessKey) { 68 | $url = $this->endpoint.'autenticacao/acesso_responsaveis/'; 69 | 70 | $params = [ 71 | 'matricula' => $username, 72 | 'chave' => $password, 73 | ]; 74 | } else { 75 | $url = $this->endpoint.'autenticacao/token/'; 76 | 77 | $params = [ 78 | 'username' => $username, 79 | 'password' => $password, 80 | ]; 81 | } 82 | 83 | $response = $this->client->request('POST', $url, [ 84 | 'form_params' => $params, 85 | ]); 86 | 87 | $data = false; 88 | 89 | if ($response->getStatusCode() == 200) { 90 | // Decodifica a resposta JSON para um array. 91 | $data = json_decode($response->getBody(), true); 92 | 93 | // Seta o token se solicitado. Padrão é true. 94 | if ($setToken && isset($data['token'])) { 95 | $this->setToken($data['token']); 96 | } 97 | } 98 | 99 | return $data; 100 | } 101 | 102 | /** 103 | * Seta o token para acesso a API. 104 | * 105 | * @param string $token Token de acesso. 106 | */ 107 | public function setToken($token) 108 | { 109 | $this->token = $token; 110 | } 111 | 112 | /** 113 | * Pega os dados pessoais do aluno autenticado. 114 | * 115 | * @return array $data Dados pessoais do aluno. 116 | */ 117 | public function getMeusDados() 118 | { 119 | $url = $this->endpoint.'minhas-informacoes/meus-dados/'; 120 | 121 | return $this->doGetRequest($url); 122 | } 123 | 124 | /** 125 | * Pega os períodos letivos do aluno autenticado. 126 | * 127 | * @return array $data Períodos letivos do aluno. 128 | */ 129 | public function getMeusPeriodosLetivos() 130 | { 131 | $url = $this->endpoint.'minhas-informacoes/meus-periodos-letivos/'; 132 | 133 | return $this->doGetRequest($url); 134 | } 135 | 136 | /** 137 | * Pega o boletim do aluno autenticado. 138 | * 139 | * @param int $year Ano letivo. 140 | * @param int $term Período letivo. 141 | * 142 | * @return array $data Boletim do aluno. 143 | */ 144 | public function getMeuBoletim($year, $term) 145 | { 146 | $url = $this->endpoint.'minhas-informacoes/boletim/'.$year.'/'.$term.'/'; 147 | 148 | return $this->doGetRequest($url); 149 | } 150 | 151 | /** 152 | * Pega a listagem de turmas do aluno para o período solicitado. 153 | * 154 | * @param int $year Ano letivo. 155 | * @param int $term Período letivo. 156 | * 157 | * @return array $data Listagem de turmas do aluno. 158 | */ 159 | public function getTurmasVirtuais($year, $term) 160 | { 161 | $url = $this->endpoint.'minhas-informacoes/turmas-virtuais/'.$year.'/'.$term.'/'; 162 | 163 | return $this->doGetRequest($url); 164 | } 165 | 166 | /** 167 | * Pega detalhes sobre uma turma especificada. 168 | * 169 | * @param int $id Id da turma virtual. 170 | * 171 | * @return array $data Detalhes da turma virtual. 172 | */ 173 | public function getTurmaVirtual($id) 174 | { 175 | $url = $this->endpoint.'minhas-informacoes/turma-virtual/'.$id.'/'; 176 | 177 | return $this->doGetRequest($url); 178 | } 179 | 180 | /** 181 | * Retorna um array com o horário semanal de um aluno. 182 | * 183 | * @param int $year Ano letivo. 184 | * @param int $term Período letivo. 185 | * 186 | * @return array $schedule Horário semanal do aluno. 187 | */ 188 | public function getHorarios($year, $term) 189 | { 190 | $classes = $this->getTurmasVirtuais($year, $term); 191 | 192 | $shifts = []; 193 | $shifts['M'][1]['hora'] = '07:00 - 07:45'; 194 | $shifts['M'][2]['hora'] = '07:45 - 08:30'; 195 | $shifts['M'][3]['hora'] = '08:50 - 09:35'; 196 | $shifts['M'][4]['hora'] = '09:35 - 10:20'; 197 | $shifts['M'][5]['hora'] = '10:30 - 11:15'; 198 | $shifts['M'][6]['hora'] = '11:15 - 12:00'; 199 | 200 | $shifts['V'][1]['hora'] = '13:00 - 13:45'; 201 | $shifts['V'][2]['hora'] = '13:45 - 14:30'; 202 | $shifts['V'][3]['hora'] = '14:40 - 15:25'; 203 | $shifts['V'][4]['hora'] = '15:25 - 16:10'; 204 | $shifts['V'][5]['hora'] = '16:30 - 17:15'; 205 | $shifts['V'][6]['hora'] = '17:15 - 18:00'; 206 | 207 | $shifts['N'][1]['hora'] = '19:00 - 19:45'; 208 | $shifts['N'][2]['hora'] = '19:45 - 20:30'; 209 | $shifts['N'][3]['hora'] = '20:40 - 21:25'; 210 | $shifts['N'][4]['hora'] = '21:25 - 22:10'; 211 | 212 | $schedule = []; 213 | $schedule[1] = $shifts; 214 | $schedule[2] = $shifts; 215 | $schedule[3] = $shifts; 216 | $schedule[4] = $shifts; 217 | $schedule[5] = $shifts; 218 | $schedule[6] = $shifts; 219 | $schedule[7] = $shifts; 220 | 221 | // Insere os dados da aula (2M12, 3V34) no local apropriado no array. 222 | foreach ($classes as $class) { 223 | $horarios = explode(' / ', $class['horarios_de_aula']); 224 | 225 | foreach ($horarios as $horario) { 226 | // As vezes disciplinas não tem horários. Isso resulta em uma String vazia. 227 | if ($horario != '') { 228 | $day = $horario[0]; 229 | $shift = $horario[1]; 230 | 231 | $stringSize = strlen($horario); 232 | 233 | for ($i = 2; $i < $stringSize; $i++) { 234 | $slot = $horario[$i]; 235 | $schedule[$day][$shift][$slot]['aula'] = $class; 236 | } 237 | } 238 | } 239 | } 240 | 241 | return $schedule; 242 | } 243 | 244 | /** 245 | * Faz um request GET para um endpoint definido. 246 | * 247 | * @param string $url Url para fazer o request. 248 | * 249 | * @return array $data Dados retornados pela API. 250 | */ 251 | private function doGetRequest($url) 252 | { 253 | $response = $this->client->request('GET', $url, [ 254 | 'headers' => [ 255 | 'Authorization' => 'JWT '.$this->token, 256 | ], 257 | ]); 258 | 259 | $data = false; 260 | 261 | if ($response->getStatusCode() == 200) { 262 | $data = json_decode($response->getBody(), true); 263 | } 264 | 265 | return $data; 266 | } 267 | } 268 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "61116549e120ee2b85a79e31b77f73d7", 8 | "packages": [ 9 | { 10 | "name": "guzzlehttp/guzzle", 11 | "version": "6.2.3", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/guzzle/guzzle.git", 15 | "reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/8d6c6cc55186db87b7dc5009827429ba4e9dc006", 20 | "reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "guzzlehttp/promises": "^1.0", 25 | "guzzlehttp/psr7": "^1.4", 26 | "php": ">=5.5" 27 | }, 28 | "require-dev": { 29 | "ext-curl": "*", 30 | "phpunit/phpunit": "^4.0", 31 | "psr/log": "^1.0" 32 | }, 33 | "type": "library", 34 | "extra": { 35 | "branch-alias": { 36 | "dev-master": "6.2-dev" 37 | } 38 | }, 39 | "autoload": { 40 | "files": [ 41 | "src/functions_include.php" 42 | ], 43 | "psr-4": { 44 | "GuzzleHttp\\": "src/" 45 | } 46 | }, 47 | "notification-url": "https://packagist.org/downloads/", 48 | "license": [ 49 | "MIT" 50 | ], 51 | "authors": [ 52 | { 53 | "name": "Michael Dowling", 54 | "email": "mtdowling@gmail.com", 55 | "homepage": "https://github.com/mtdowling" 56 | } 57 | ], 58 | "description": "Guzzle is a PHP HTTP client library", 59 | "homepage": "http://guzzlephp.org/", 60 | "keywords": [ 61 | "client", 62 | "curl", 63 | "framework", 64 | "http", 65 | "http client", 66 | "rest", 67 | "web service" 68 | ], 69 | "time": "2017-02-28T22:50:30+00:00" 70 | }, 71 | { 72 | "name": "guzzlehttp/promises", 73 | "version": "v1.3.1", 74 | "source": { 75 | "type": "git", 76 | "url": "https://github.com/guzzle/promises.git", 77 | "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" 78 | }, 79 | "dist": { 80 | "type": "zip", 81 | "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", 82 | "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", 83 | "shasum": "" 84 | }, 85 | "require": { 86 | "php": ">=5.5.0" 87 | }, 88 | "require-dev": { 89 | "phpunit/phpunit": "^4.0" 90 | }, 91 | "type": "library", 92 | "extra": { 93 | "branch-alias": { 94 | "dev-master": "1.4-dev" 95 | } 96 | }, 97 | "autoload": { 98 | "psr-4": { 99 | "GuzzleHttp\\Promise\\": "src/" 100 | }, 101 | "files": [ 102 | "src/functions_include.php" 103 | ] 104 | }, 105 | "notification-url": "https://packagist.org/downloads/", 106 | "license": [ 107 | "MIT" 108 | ], 109 | "authors": [ 110 | { 111 | "name": "Michael Dowling", 112 | "email": "mtdowling@gmail.com", 113 | "homepage": "https://github.com/mtdowling" 114 | } 115 | ], 116 | "description": "Guzzle promises library", 117 | "keywords": [ 118 | "promise" 119 | ], 120 | "time": "2016-12-20T10:07:11+00:00" 121 | }, 122 | { 123 | "name": "guzzlehttp/psr7", 124 | "version": "1.4.2", 125 | "source": { 126 | "type": "git", 127 | "url": "https://github.com/guzzle/psr7.git", 128 | "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" 129 | }, 130 | "dist": { 131 | "type": "zip", 132 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", 133 | "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", 134 | "shasum": "" 135 | }, 136 | "require": { 137 | "php": ">=5.4.0", 138 | "psr/http-message": "~1.0" 139 | }, 140 | "provide": { 141 | "psr/http-message-implementation": "1.0" 142 | }, 143 | "require-dev": { 144 | "phpunit/phpunit": "~4.0" 145 | }, 146 | "type": "library", 147 | "extra": { 148 | "branch-alias": { 149 | "dev-master": "1.4-dev" 150 | } 151 | }, 152 | "autoload": { 153 | "psr-4": { 154 | "GuzzleHttp\\Psr7\\": "src/" 155 | }, 156 | "files": [ 157 | "src/functions_include.php" 158 | ] 159 | }, 160 | "notification-url": "https://packagist.org/downloads/", 161 | "license": [ 162 | "MIT" 163 | ], 164 | "authors": [ 165 | { 166 | "name": "Michael Dowling", 167 | "email": "mtdowling@gmail.com", 168 | "homepage": "https://github.com/mtdowling" 169 | }, 170 | { 171 | "name": "Tobias Schultze", 172 | "homepage": "https://github.com/Tobion" 173 | } 174 | ], 175 | "description": "PSR-7 message implementation that also provides common utility methods", 176 | "keywords": [ 177 | "http", 178 | "message", 179 | "request", 180 | "response", 181 | "stream", 182 | "uri", 183 | "url" 184 | ], 185 | "time": "2017-03-20T17:10:46+00:00" 186 | }, 187 | { 188 | "name": "psr/http-message", 189 | "version": "1.0.1", 190 | "source": { 191 | "type": "git", 192 | "url": "https://github.com/php-fig/http-message.git", 193 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" 194 | }, 195 | "dist": { 196 | "type": "zip", 197 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", 198 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", 199 | "shasum": "" 200 | }, 201 | "require": { 202 | "php": ">=5.3.0" 203 | }, 204 | "type": "library", 205 | "extra": { 206 | "branch-alias": { 207 | "dev-master": "1.0.x-dev" 208 | } 209 | }, 210 | "autoload": { 211 | "psr-4": { 212 | "Psr\\Http\\Message\\": "src/" 213 | } 214 | }, 215 | "notification-url": "https://packagist.org/downloads/", 216 | "license": [ 217 | "MIT" 218 | ], 219 | "authors": [ 220 | { 221 | "name": "PHP-FIG", 222 | "homepage": "http://www.php-fig.org/" 223 | } 224 | ], 225 | "description": "Common interface for HTTP messages", 226 | "homepage": "https://github.com/php-fig/http-message", 227 | "keywords": [ 228 | "http", 229 | "http-message", 230 | "psr", 231 | "psr-7", 232 | "request", 233 | "response" 234 | ], 235 | "time": "2016-08-06T14:39:51+00:00" 236 | } 237 | ], 238 | "packages-dev": [], 239 | "aliases": [], 240 | "minimum-stability": "stable", 241 | "stability-flags": [], 242 | "prefer-stable": false, 243 | "prefer-lowest": false, 244 | "platform": [], 245 | "platform-dev": [] 246 | } 247 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SUAP API PHP 2 | 3 | [![SensioLabsInsight](https://insight.sensiolabs.com/projects/cca1ac97-8137-4887-86f1-78c927125cbd/mini.png)](https://insight.sensiolabs.com/projects/cca1ac97-8137-4887-86f1-78c927125cbd) 4 | [![StyleCI](https://styleci.io/repos/64276422/shield)](https://styleci.io/repos/64276422) 5 | [![Latest Stable Version](https://poser.pugx.org/ivmelo/suap-api-php/v/stable)](https://packagist.org/packages/ivmelo/suap-api-php) 6 | [![Total Downloads](https://poser.pugx.org/ivmelo/suap-api-php/downloads)](https://packagist.org/packages/ivmelo/suap-api-php) 7 | [![License](https://poser.pugx.org/ivmelo/suap-api-php/license)](https://packagist.org/packages/ivmelo/suap-api-php) 8 | 9 | Um wrapper PHP para a [API](http://suap.ifrn.edu.br/api/docs/) do [SUAP (Sistema Unificado de Administração Publica)](http://portal.ifrn.edu.br/tec-da-informacao/servicos-ti/menus/servicos/copy2_of_suap) do IFRN. Este pacote permite que você tenha acesso aos dados do SUAP na sua aplicação PHP. 10 | 11 | É o componente principal do [SUAP Bot](https://telegram.me/suapbot). 12 | 13 | Atualmente fornece informações de boletim (notas, frequência), cursos, horários, locais de aula e dados do aluno. 14 | 15 | Este pacote foi atualizado para acessar os dados através da API oficial do SUAP, e não mais fazendo web scraping. Caso deseje utilizar a versão que faz web scraping, veja a tag `0.2.0`. 16 | 17 | 18 | ### Instalação 19 | Para instalar, recomenda-se o uso do [Composer](https://getcomposer.org). 20 | 21 | Adicione a dependência abaixo no seu composer.json e execute ```composer update```. 22 | 23 | ```json 24 | "require": { 25 | "ivmelo/suap-api-php": "1.0.*" 26 | } 27 | ``` 28 | Alternativamente, você pode instalar diretamente pela linha de comando: 29 | 30 | ```bash 31 | $ composer require "ivmelo/suap-api-php": "1.0.*" 32 | ``` 33 | 34 | ### Uso 35 | Você pode instanciar um cliente usando um token de acesso, ou usar o construtor vazio. 36 | 37 | ```php 38 | $suap = SUAP('token'); 39 | // ou 40 | $suap = SUAP(); 41 | $suap->setToken('token'); 42 | 43 | ``` 44 | 45 | ### Autenticação 46 | 47 | Para autenticar, basta usar chamar o método `autenticar($usuario, $chave)`. 48 | 49 | ``` 50 | $suap = SUAP(); 51 | $data = $suap->autenticar('20121014040000', 'senhaouchave'); 52 | ``` 53 | 54 | O método retornará um array com um token de acesso (`$data['token']`). 55 | ``` 56 | Array 57 | ( 58 | [token] => eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJ1c2VybmFtZSI6IjIwMTIxMDE0MDQwMDgzIiwib3JpZ19pYXQiOjE0OTQwMjcyMDksInVzZXJfaWQiOjEwODQyLCJlbWFpbCI6Iml2YW5pbHNvbi5tZWxvQGFjYWRlbWljby5pZnJuLmVkdS5iciIsImV4cCI6MTQ5NDExMzYwOX0 59 | ) 60 | ``` 61 | 62 | O token será salvo no objeto para que seja reutilizado nos requests subsequentes. Caso não deseje salvar o token, basta setar o quarto parâmetro do construtor como false: `autenticar($matricula, $senha, true, false)`. 63 | 64 | Você também pode utilizar a chave de acesso de responsável para efetuar o login. Para isso, basta passar true como terceiro parâmetro do método `autenticar($matricula, $chave, true)`. 65 | 66 | ``` 67 | $suap = SUAP(); 68 | $suap->autenticar('20121014040000', 'chave', true); 69 | ``` 70 | 71 | Para obter a chave de acesso, faça login no SUAP, e vá em "Meus Dados" > "Dados pessoais" > "Dados Gerais" e procure por "Chave de Acesso. Ela deve ter 5 dígitos e ser algo parecido com ```4d5f9```. 72 | 73 | 74 | ### Dados do Aluno 75 | Para receber dados do aluno, basta chamar o método `getMeusDados()`. 76 | 77 | ```php 78 | $meusDados = $suap->getMeusDados(); 79 | ``` 80 | 81 | A saída será um array com informações básicas do estudante e do curso. 82 | 83 | ``` 84 | Array 85 | ( 86 | [id] => 123456 87 | [matricula] => 20121014040000 88 | [nome_usual] => Nome Sobrenome 89 | [email] => nome.sobrenome@academico.ifrn.edu.br 90 | [url_foto_75x100] => /media/alunos/000000.jpg 91 | [tipo_vinculo] => Aluno 92 | [vinculo] => Array 93 | ( 94 | [matricula] => 20121014040000 95 | [nome] => Nome Completo Do Estudante 96 | [curso] => Tecnologia em Análise e Desenvolvimento de Sistemas 97 | [campus] => CNAT 98 | [situacao] => Matriculado 99 | [cota_sistec] => 100 | [cota_mec] => 101 | [situacao_sistemica] => Migrado do Q-Acadêmico para o SUAP 102 | ) 103 | 104 | ) 105 | ``` 106 | 107 | 108 | ### Períodos Letivos 109 | Para receber os períodos letivos do aluno use o método `getMeusPeriodosLetivos()`. 110 | 111 | ```php 112 | $meusDados = $suap->getMeusPeriodosLetivos(); 113 | ``` 114 | 115 | A saída será um array com a listagem de períodos letivos do aluno. 116 | 117 | ``` 118 | Array 119 | ( 120 | [0] => Array 121 | ( 122 | [ano_letivo] => 2012 123 | [periodo_letivo] => 1 124 | ) 125 | 126 | [1] => Array 127 | ( 128 | [ano_letivo] => 2012 129 | [periodo_letivo] => 2 130 | ) 131 | 132 | ... 133 | 134 | [10] => Array 135 | ( 136 | [ano_letivo] => 2017 137 | [periodo_letivo] => 1 138 | ) 139 | 140 | ) 141 | ``` 142 | 143 | ### Boletim 144 | Para receber dados do boletim do aluno, basta instanciar um cliente e chamar o método `getMeuBoletim($anoLetivo, $periodoLetivo)`. 145 | 146 | ``` 147 | $boletim = $suap->getMeuBoletim(2017, 1); 148 | ``` 149 | 150 | A saída será um array com informações sobre a disciplina encontradas no boletim do aluno. 151 | 152 | Alunos do ensino superior só terão as notas da etapa 1 e 2. 153 | 154 | ``` 155 | Array 156 | ( 157 | [0] => Array 158 | ( 159 | [codigo_diario] => 15360 160 | [disciplina] => TEC.0028 - Desenvolvimento de Sistemas Coorporativos 161 | [segundo_semestre] => 162 | [carga_horaria] => 80 163 | [carga_horaria_cumprida] => 76 164 | [numero_faltas] => 8 165 | [percentual_carga_horaria_frequentada] => 90 166 | [situacao] => Aprovado 167 | [quantidade_avaliacoes] => 2 168 | [nota_etapa_1] => Array 169 | ( 170 | [nota] => 92 171 | [faltas] => 0 172 | ) 173 | 174 | [nota_etapa_2] => Array 175 | ( 176 | [nota] => 50 177 | [faltas] => 8 178 | ) 179 | 180 | [nota_etapa_3] => Array 181 | ( 182 | [nota] => 183 | [faltas] => 0 184 | ) 185 | 186 | [nota_etapa_4] => Array 187 | ( 188 | [nota] => 189 | [faltas] => 0 190 | ) 191 | 192 | [media_disciplina] => 67 193 | [nota_avaliacao_final] => Array 194 | ( 195 | [nota] => 196 | [faltas] => 0 197 | ) 198 | 199 | [media_final_disciplina] => 67 200 | ) 201 | 202 | [1] => Array 203 | ( 204 | [codigo_diario] => 15359 205 | [disciplina] => TEC.0010 - Empreendedorismo 206 | [segundo_semestre] => 207 | [carga_horaria] => 40 208 | [carga_horaria_cumprida] => 40 209 | [numero_faltas] => 6 210 | [percentual_carga_horaria_frequentada] => 85 211 | [situacao] => Aprovado 212 | [quantidade_avaliacoes] => 2 213 | [nota_etapa_1] => Array 214 | ( 215 | [nota] => 80 216 | [faltas] => 2 217 | ) 218 | 219 | [nota_etapa_2] => Array 220 | ( 221 | [nota] => 100 222 | [faltas] => 4 223 | ) 224 | 225 | [nota_etapa_3] => Array 226 | ( 227 | [nota] => 228 | [faltas] => 0 229 | ) 230 | 231 | [nota_etapa_4] => Array 232 | ( 233 | [nota] => 234 | [faltas] => 0 235 | ) 236 | 237 | [media_disciplina] => 92 238 | [nota_avaliacao_final] => Array 239 | ( 240 | [nota] => 241 | [faltas] => 0 242 | ) 243 | 244 | [media_final_disciplina] => 92 245 | ) 246 | 247 | ... 248 | 249 | [5] => Array 250 | ( 251 | [codigo_diario] => 15363 252 | [disciplina] => TEC.0030 - Teste de Software 253 | [segundo_semestre] => 254 | [carga_horaria] => 80 255 | [carga_horaria_cumprida] => 72 256 | [numero_faltas] => 24 257 | [percentual_carga_horaria_frequentada] => 67 258 | [situacao] => Aprovado 259 | [quantidade_avaliacoes] => 2 260 | [nota_etapa_1] => Array 261 | ( 262 | [nota] => 47 263 | [faltas] => 20 264 | ) 265 | 266 | [nota_etapa_2] => Array 267 | ( 268 | [nota] => 73 269 | [faltas] => 4 270 | ) 271 | 272 | [nota_etapa_3] => Array 273 | ( 274 | [nota] => 275 | [faltas] => 0 276 | ) 277 | 278 | [nota_etapa_4] => Array 279 | ( 280 | [nota] => 281 | [faltas] => 0 282 | ) 283 | 284 | [media_disciplina] => 63 285 | [nota_avaliacao_final] => Array 286 | ( 287 | [nota] => 288 | [faltas] => 0 289 | ) 290 | 291 | [media_final_disciplina] => 63 292 | ) 293 | 294 | ) 295 | ``` 296 | 297 | ### Listagem de Turmas Virtuais 298 | Para visualizar a listagem das turmas virtuais, incluindo ids, horários e locais de aula, use o método `getTurmasVirtuais($anoLetivo, $periodoLetivo)`. 299 | 300 | ```php 301 | $turmasVirtuais = $suap->getTurmasVirtuais(2017, 1); 302 | ``` 303 | 304 | O método retornará um array com a lista de disciplinas do semestre atual junto com outras informações sobre as mesmas. 305 | 306 | ``` 307 | Array 308 | ( 309 | [0] => Array 310 | ( 311 | [id] => 20118 312 | [sigla] => TEC.0011 313 | [descricao] => Gestão de Tecnologia da Informação 314 | [observacao] => 315 | [locais_de_aula] => Array 316 | ( 317 | [0] => Audio de Visual 03 - DIATINF - Prédio Anexo - 1º Andar (CNAT) 318 | ) 319 | 320 | [horarios_de_aula] => 2V34 / 3V56 321 | ) 322 | 323 | [1] => Array 324 | ( 325 | [id] => 20119 326 | [sigla] => TEC.0012 327 | [descricao] => Computador e Sociedade 328 | [observacao] => 329 | [locais_de_aula] => Array 330 | ( 331 | [0] => Audio de Visual 03 - DIATINF - Prédio Anexo - 1º Andar (CNAT) 332 | ) 333 | 334 | [horarios_de_aula] => 3V34 335 | ) 336 | 337 | [2] => Array 338 | ( 339 | [id] => 20120 340 | [sigla] => TEC.0036 341 | [descricao] => Seminário de Orientação para Trabalho de Conclusão de Curso 342 | [observacao] => 343 | [locais_de_aula] => Array 344 | ( 345 | [0] => Audio de Visual 03 - DIATINF - Prédio Anexo - 1º Andar (CNAT) 346 | ) 347 | 348 | [horarios_de_aula] => 4V34 349 | ) 350 | 351 | [3] => Array 352 | ( 353 | [id] => 20102 354 | [sigla] => TEC.0004 355 | [descricao] => Epistemologia da Ciência 356 | [observacao] => 357 | [locais_de_aula] => Array 358 | ( 359 | [0] => Audio de Visual 02 - DIATINF - Informática (CNAT) 360 | ) 361 | 362 | [horarios_de_aula] => 3M56 363 | ) 364 | 365 | [4] => Array 366 | ( 367 | [id] => 23115 368 | [sigla] => TEC.0075 369 | [descricao] => Aplicações com Interfaces Ricas 370 | [observacao] => 371 | [locais_de_aula] => Array 372 | ( 373 | [0] => Laboratório 06 - DIATINF - Informática (CNAT) 374 | ) 375 | 376 | [horarios_de_aula] => 2M56 / 4M56 377 | ) 378 | 379 | ) 380 | ``` 381 | 382 | ### Detalhes de Turma Virtual 383 | Para visualizar os detalhes de uma turma virtual, basta usar o método `getTurmaVirtual($idDaTurma)`. 384 | 385 | ``` 386 | $course = $suap->getTurmaVirtual(23115); 387 | ``` 388 | 389 | O retorno será um array com os detalhes da turma incluindo participantes, aulas, materiais de aula, professores e etc... 390 | ``` 391 | Array 392 | ( 393 | [id] => 23115 394 | [ano_letivo] => 2017 395 | [periodo_letivo] => 1 396 | [componente_curricular] => TEC.0075 - Aplicações com Interfaces Ricas (NCT) - Graduação [60 h/80 Aulas] - Curso 404 397 | [professores] => Array 398 | ( 399 | [0] => Array 400 | ( 401 | [matricula] => 123456 402 | [foto] => /media/fotos/75x100/ABCEDF000000.jpg 403 | [email] => email.professor@ifrn.edu.br 404 | [nome] => Nome do Professor 405 | ) 406 | 407 | ) 408 | 409 | [locais_de_aula] => Array 410 | ( 411 | [0] => Laboratório 06 - DIATINF - Informática (CNAT) 412 | ) 413 | 414 | [data_inicio] => 2017-03-21 415 | [data_fim] => 2017-08-01 416 | [participantes] => Array 417 | ( 418 | [0] => Array 419 | ( 420 | [matricula] => 20121000000000 421 | [foto] => /media/alunos/75x100/000000.jpg 422 | [email] => email.do.aluno@academico.ifrn.edu.br 423 | [nome] => Nome do Aluno 424 | ) 425 | 426 | [1] => Array 427 | ( 428 | [matricula] => 20121000000000 429 | [foto] => /media/alunos/75x100/000000.jpg 430 | [email] => email.do.aluno@academico.ifrn.edu.br 431 | [nome] => Nome do Aluno 432 | ) 433 | 434 | [2] => Array 435 | ( 436 | [matricula] => 20121000000000 437 | [foto] => /media/alunos/75x100/000000.jpg 438 | [email] => email.do.aluno@academico.ifrn.edu.br 439 | [nome] => Nome do Aluno 440 | ) 441 | 442 | [3] => Array 443 | ( 444 | [matricula] => 20121000000000 445 | [foto] => /media/alunos/75x100/000000.jpg 446 | [email] => email.do.aluno@academico.ifrn.edu.br 447 | [nome] => Nome do Aluno 448 | ) 449 | 450 | ) 451 | 452 | [aulas] => Array 453 | ( 454 | [0] => Array 455 | ( 456 | [etapa] => 1 457 | [professor] => Nome do Professor 458 | [quantidade] => 2 459 | [faltas] => 0 460 | [conteudo] => Isolated Storage. 461 | [data] => 2017-05-03 462 | ) 463 | 464 | [1] => Array 465 | ( 466 | [etapa] => 1 467 | [professor] => Nome do Professor 468 | [quantidade] => 2 469 | [faltas] => 2 470 | [conteudo] => Treinamento em Python. 471 | [data] => 2017-04-26 472 | ) 473 | 474 | [2] => Array 475 | ( 476 | [etapa] => 1 477 | [professor] => Nome do Professor 478 | [quantidade] => 2 479 | [faltas] => 0 480 | [conteudo] => Introdução ao Python. 481 | [data] => 2017-04-24 482 | ) 483 | 484 | ) 485 | 486 | [materiais_de_aula] => Array 487 | ( 488 | [0] => Array 489 | ( 490 | [url] => /media/edu/material_aula/material_de_aula.pdf 491 | [data_vinculacao] => 2017-04-18 492 | [descricao] => Exemplo Silverlight (DataGrid) 493 | ) 494 | 495 | [1] => Array 496 | ( 497 | [url] => /media/edu/material_aula/material_de_aula.pdf 498 | [data_vinculacao] => 2017-04-07 499 | [descricao] => Estilos no Silverlight (Exemplos) 500 | ) 501 | 502 | [2] => Array 503 | ( 504 | [url] => /media/edu/material_aula/material_de_aula.pdf 505 | [data_vinculacao] => 2017-04-05 506 | [descricao] => Silverlight Exemplos01 507 | ) 508 | ) 509 | 510 | ) 511 | 512 | ``` 513 | 514 | ### Horários de Aula 515 | Para recuperar horários de aula no formato de array, use o método `getHorarios($anoLetivo, $periodoLetivo)`. 516 | 517 | ```php 518 | $horarios = $suap->getHorarios(2017, 1); 519 | ``` 520 | 521 | Isso retornará um array associativo usando dias da semana como chave (1: dom, 2: seg, 3: ter...), o turno como subchave (M: matutino, V: vespertino, N: noturno) e o slot da aula como segunda subchave(1-6). 522 | 523 | I.E. Para pegar a quarta aula da terça feira a tarde: 524 | ``` 525 | print_r($schedule[3]['V'][4]); 526 | ``` 527 | 528 | O retorno do método pode ser visto a seguir (Algumas partes foram omitidas usando `...`). 529 | ``` 530 | Array 531 | ( 532 | [1] => Array 533 | ( 534 | [M] => Array 535 | ( 536 | ... 537 | ) 538 | 539 | [V] => Array 540 | ( 541 | ... 542 | ) 543 | 544 | [N] => Array 545 | ( 546 | ... 547 | ) 548 | 549 | ) 550 | 551 | [2] => Array 552 | ( 553 | [M] => Array 554 | ( 555 | [1] => Array 556 | ( 557 | [time] => 07:00 - 07:45 558 | ) 559 | 560 | ... 561 | 562 | [5] => Array 563 | ( 564 | [time] => 10:30 - 11:15 565 | [aula] => Array 566 | ( 567 | [id] => 23115 568 | [sigla] => TEC.0075 569 | [descricao] => Aplicações com Interfaces Ricas 570 | [observacao] => 571 | [locais_de_aula] => Array 572 | ( 573 | [0] => Laboratório 06 - DIATINF - Informática (CNAT) 574 | ) 575 | 576 | [horarios_de_aula] => 2M56 / 4M56 577 | ) 578 | 579 | ) 580 | 581 | [6] => Array 582 | ( 583 | [time] => 11:15 - 12:00 584 | [aula] => Array 585 | ( 586 | [id] => 23115 587 | [sigla] => TEC.0075 588 | [descricao] => Aplicações com Interfaces Ricas 589 | [observacao] => 590 | [locais_de_aula] => Array 591 | ( 592 | [0] => Laboratório 06 - DIATINF - Informática (CNAT) 593 | ) 594 | 595 | [horarios_de_aula] => 2M56 / 4M56 596 | ) 597 | 598 | ) 599 | 600 | ) 601 | 602 | [V] => Array 603 | ( 604 | [1] => Array 605 | ( 606 | [time] => 13:00 - 13:45 607 | ) 608 | 609 | [2] => Array 610 | ( 611 | [time] => 13:45 - 14:30 612 | ) 613 | 614 | [3] => Array 615 | ( 616 | [time] => 14:40 - 15:25 617 | [aula] => Array 618 | ( 619 | [id] => 20118 620 | [sigla] => TEC.0011 621 | [descricao] => Gestão de Tecnologia da Informação 622 | [observacao] => 623 | [locais_de_aula] => Array 624 | ( 625 | [0] => Audio de Visual 03 - DIATINF - Prédio Anexo - 1º Andar (CNAT) 626 | ) 627 | 628 | [horarios_de_aula] => 2V34 / 3V56 629 | ) 630 | 631 | ) 632 | 633 | [4] => Array 634 | ( 635 | [time] => 15:25 - 16:10 636 | [aula] => Array 637 | ( 638 | [id] => 20118 639 | [sigla] => TEC.0011 640 | [descricao] => Gestão de Tecnologia da Informação 641 | [observacao] => 642 | [locais_de_aula] => Array 643 | ( 644 | [0] => Audio de Visual 03 - DIATINF - Prédio Anexo - 1º Andar (CNAT) 645 | ) 646 | 647 | [horarios_de_aula] => 2V34 / 3V56 648 | ) 649 | 650 | ) 651 | 652 | [5] => Array 653 | ( 654 | [time] => 16:30 - 17:15 655 | ) 656 | 657 | [6] => Array 658 | ( 659 | [time] => 17:15 - 18:00 660 | ) 661 | 662 | ) 663 | 664 | [N] => Array 665 | ( 666 | [1] => Array 667 | ( 668 | [time] => 19:00 - 19:45 669 | ) 670 | 671 | ... 672 | 673 | [4] => Array 674 | ( 675 | [time] => 21:25 - 22:10 676 | ) 677 | 678 | ) 679 | 680 | ) 681 | 682 | [3] => Array 683 | ( 684 | ... 685 | ) 686 | 687 | ... 688 | 689 | [7] => Array 690 | ( 691 | ... 692 | ) 693 | 694 | ) 695 | ``` 696 | 697 | ### E se ocorrer algum erro durante o request? 698 | Caso algum erro ocorra durante o request, o cliente HTTP lançará exceções. Isto inclui falha no login, 404, 500, etc... 699 | 700 | Você deve usar try-catch blocks para tratar os possíveis erros dentro da sua aplicação sempre que usar algum método da API. 701 | 702 | ### Desenvolvimento (Como contribuir) 703 | Para ajudar no Desenvolvimento, clone o repositório, instale as dependências e use o arquivo test.php que encontra-se na pasta tests. 704 | 705 | ```bash 706 | $ git clone git@github.com:ivmelo/suap-api-php.git 707 | $ cd suap-api-php 708 | $ composer install 709 | $ cd tests 710 | $ php test.php 711 | ``` 712 | 713 | 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. 714 | 715 | O código em desenvolvimento mais recente está na branch `master`. 716 | 717 | ### Coisas a Fazer: 718 | Veja a sessão de [Issues](https://github.com/ivmelo/suap-api-php/issues) para ver o que falta fazer ou se tem algum bug precisando de atenção. 719 | 720 | ### Versões Anteriores 721 | Para ver as versões anteriores da biblioteca (Incluindo as que fazem web scraping), veja as tags do projeto. 722 | 723 | ### Licença 724 | The MIT License (MIT) 725 | 726 | Copyright (c) 2016 Ivanilson Melo 727 | 728 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 729 | 730 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 731 | 732 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 733 | --------------------------------------------------------------------------------