@ -12,6 +12,7 @@
* A relais authentication id (token)
* A relais authentication id (token)
*/
*/
function upei_roblib_ill_add_request($form_state, $aid) {
function upei_roblib_ill_add_request($form_state, $aid) {
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
$url = variable_get('upei_roblib_ill_add_url', 'https://caul-cbua.relais-host.com/portal-service/request/add');
$url = variable_get('upei_roblib_ill_add_url', 'https://caul-cbua.relais-host.com/portal-service/request/add');
$relais_arr = array(
$relais_arr = array(
@ -28,14 +29,16 @@ function upei_roblib_ill_add_request($form_state, $aid) {
'timeout' => 15,
'timeout' => 15,
'headers' => array('Content-Type' => 'application/json'),
'headers' => array('Content-Type' => 'application/json'),
);
);
$result = null;// = drupal_http_request($url . '?aid=' . $aid, $options);
if(!isset($aid) || is_array($aid)) {
upei_roblib_ill_log_request($relais_arr, $aid);
drupal_set_message(t('Error retrieving authentication token, @message', array('@message' => $aid['Problem']['Message'])), 'error');
return;
}
$result = drupal_http_request($url . '?aid=' . $aid, $options);
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
upei_roblib_ill_log_request($relais_arr, NULL);
$response_json = $result->data;
$response_arr = json_decode($response_json, TRUE);
if ($result->code == '200') {
if ($result->code == '200') {
$response_json = $result->data;
$response_arr = json_decode($response_json);
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
upei_roblib_ill_log_request($relais_arr, $response_arr);
//TODO remove or improve the line below after testing
//TODO remove or improve the line below after testing
drupal_set_message('submitted request to relais' . $response_json);
drupal_set_message('submitted request to relais' . $response_json);
}
}
@ -45,14 +48,15 @@ function upei_roblib_ill_add_request($form_state, $aid) {
'@message' => $result->message
'@message' => $result->message
)), 'error');
)), 'error');
}
}
upei_roblib_ill_log_request($relais_arr, $response_arr);
}
}
/**
/**
* Request an aid from Relais.
* Request an aid from Relais.
* @param string $barcode
* @param string $barcode
* A patron_id, campus_id or barcode to identify a user
* A patron_id, campus_id or barcode to identify a user
* @return string/null
* @return string/array
* Returns a Relais authentication id (token) or NULL on if authentication fails
* Returns a Relais authentication id (token) or an array containing the Relais response error which should include the error message if authentication fails
*/
*/
function upei_roblib_ill_authenticate($barcode) {
function upei_roblib_ill_authenticate($barcode) {
$url = variable_get('upei_roblib_ill_auth_url', 'https://caul-cbua.relais-host.com/portal-service/user/authentication');
$url = variable_get('upei_roblib_ill_auth_url', 'https://caul-cbua.relais-host.com/portal-service/user/authentication');
@ -69,15 +73,14 @@ function upei_roblib_ill_authenticate($barcode) {
'headers' => array('Content-Type' => 'application/json'),
'headers' => array('Content-Type' => 'application/json'),
);
);
$result = drupal_http_request($url, $options);
$result = drupal_http_request($url, $options);
$response_data = json_decode($result->data, TRUE);
if ($result->code == '200') {
if ($result->code == '200') {
$response_data = json_decode($result->data, TRUE);
if (isset($response_data['Problem'])) {
if (isset($response_data['Problem'])) {
drupal_set_message(t('Error retrieving authentication token, @message', array('@message' => $response_data['Problem']['Message'])), 'error');
return $response_data;
return NULL;
}
}
$aid = $response_data['AuthorizationId'];
$aid = $response_data['AuthorizationId'];
}
}
return isset($aid) ? $aid : NULL ;
return isset($aid) ? $aid : $response_data ;
}
}