SHARE
TWEET

Untitled

a guest Apr 2nd, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $access_token = '';
  3. function librus_login($username, $password)
  4. {
  5.     global $access_token;
  6.     $ch = curl_init();
  7.  
  8.     curl_setopt($ch, CURLOPT_URL,"https://api.librus.pl/OAuth/Token");
  9.     curl_setopt($ch, CURLOPT_POST, 1);
  10.     curl_setopt($ch, CURLOPT_POSTFIELDS,
  11.                 "username=$username&password=$password&grant_type=password");
  12.     curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  13.     'Content-Type: application/x-www-form-urlencoded',
  14.     'Cache-Control: no-cache',
  15.     //'Authorization: Basic wmSyUMo8llDAs4y9tJVYY92oyZ6h4lAt7KCuy0Gv'
  16.     'Authorization: Basic MzU6NjM2YWI0MThjY2JlODgyYjE5YTMzZjU3N2U5NGNiNGY='
  17. //'Authorization: Basic Mjo1MmI2MmI4MjJkY2E1ZDQyODgxMTVhODNiOWM1ZDdjYw=='
  18.     //'Authorization: Basic MC4wNjkyODcwMCAxNTI4NzAzMzEyXzZmZTljZjc1MDhjMzNkZThiNDYwMzQ0MDljYTY4NmNl'
  19.     ));
  20.  
  21.     // in real life you should use something like:
  22.     // curl_setopt($ch, CURLOPT_POSTFIELDS,
  23.     //          http_build_query(array('postvar1' => 'value1')));
  24.  
  25.     // receive server response ...
  26.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  27.  
  28.     $json = curl_exec ($ch);
  29.     echo $json;
  30.     curl_close ($ch);
  31.     $result = json_decode($json, true);
  32.     $access_token = $result['token_type'].' '.$result['access_token'];
  33. }
  34.  
  35. function librus_get($url)
  36. {
  37.     global $access_token;
  38.     $ch = curl_init();
  39.  
  40.     curl_setopt($ch, CURLOPT_URL,$url);
  41.     curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  42.     'Cache-Control: no-cache',
  43.     'Authorization: '.$access_token
  44.     ));
  45.  
  46.     // in real life you should use something like:
  47.     // curl_setopt($ch, CURLOPT_POSTFIELDS,
  48.     //          http_build_query(array('postvar1' => 'value1')));
  49.  
  50.     // receive server response ...
  51.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  52.  
  53.     $json = curl_exec ($ch);
  54.  
  55.     curl_close ($ch);
  56.     $result = json_decode($json, true);
  57.     return $result;
  58. }
  59. header('Content-Type: text/plain');
  60. librus_login('kuba.sz', 'haslo');
  61. echo $access_token;
  62. $grades = librus_get('https://api.librus.pl/2.0/Grades');
  63. var_dump($grades);
  64.  
  65. foreach ($grades['Grades'] as $value) {
  66.     echo $value['Grade'].' ';
  67.  
  68. }
  69.  
  70. $teachers = array();
  71. foreach (librus_get('https://api.librus.pl/2.0/Users/')['Users'] as $value) {
  72.     $teachers[$value['Id']] = $value['FirstName'].' '.$value['LastName'];
  73. }
  74. var_dump($teachers);
  75.  
  76. $subjects = array();
  77. foreach (librus_get('https://api.librus.pl/2.0/Subjects/')['Subjects'] as $value) {
  78.     $subjects[$value['Id']] = $value['Name'];
  79. }
  80. var_dump($subjects);
  81.  
  82. $grades_categories = array();
  83. foreach (librus_get('https://api.librus.pl/2.0/Grades/Categories/')['Categories'] as $value) {
  84.     $grades_categories[$value['Id']] = $value['Name'];
  85. }
  86. var_dump($grades_categories);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top