sch_mm module fetch unit from mm.sch.gr

parent 03aa0d64
......@@ -15,6 +15,7 @@ return [
'module/authorization/bootstrap.php',
// 'module/sch_ldap/bootstrap.php',
'module/sch_sso/bootstrap.php',
'module/sch_mm/bootstrap.php',
// 'module/sch_auto_create/bootstrap.php',
'module/schools/bootstrap.php',
'module/application/bootstrap.php',
......
<?php
/**
* gredu_labs.
*
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\Application\Model;
use RedBeanPHP\SimpleModel;
class User extends SimpleModel
{
}
return [
'sch_mm' => [
'api_url' => '',
'api_user' => '',
'api_pass' => '',
]
];
\ No newline at end of file
......@@ -82,7 +82,7 @@ return function (Slim\App $app) {
$container['settings']['db']['pass']
);
define('REDBEAN_MODEL_PREFIX', 'GrEduLabs\\Application\\Model\\');
define('REDBEAN_MODEL_PREFIX', '');
}, 10000000);
......
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return function (Slim\App $app) {
$container = $app->getContainer();
$container['autoloader']->addPsr4('SchMM\\', __DIR__ . '/src/');
$container[SchMM\FetchUnit::class] = function ($c) {
$settings = $c['settings'];
return new SchMM\FetchUnit(new GuzzleHttp\Client([
'base_uri' => $settings['sch_mm']['api_url'],
'auth' => [
$settings['sch_mm']['api_user'],
$settings['sch_mm']['api_pass'],
],
]));
};
};
\ No newline at end of file
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace SchMM;
use GuzzleHttp\ClientInterface;
class FetchUnit
{
/**
* @var ClientInterface
*/
protected $httpClient;
/**
* Class constructor
*
* @param ClientInterface $httpClient
*/
public function __construct(ClientInterface $httpClient)
{
$this->httpClient = $httpClient;
}
public function __invoke($mmId)
{
$config = $this->httpClient->getConfig();
$baseUri = $config['base_uri'];
$auth = $config['auth'];
$url = $baseUri->withQueryValue($baseUri, 'registry_no', $mmId);
$response = $this->httpClient->request('GET', $url, ['auth' => $auth]);
$responseData = json_decode($response->getBody()->getContents(), true);
if (!isset($responseData['data']) || empty($responseData['data'])) {
return null;
}
return $responseData['data'][0];
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment