opendrive.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. # Debug
  3. $DEBUG = false;
  4. if ($_ENV['DEBUG']) {
  5. $DEBUG = true;
  6. }
  7. # On-disk config
  8. require_once '.secrets';
  9. # Config
  10. $API_BASE = 'https://dev.opendrive.com/api/v1';
  11. # Open the DB connection
  12. function dbOpen() {
  13. global $DB_STRING;
  14. global $DB_USER;
  15. global $DB_PASSWD;
  16. try {
  17. $dbh = new PDO($DB_STRING, $DB_USER, $DB_PASSWD);
  18. } catch (PDOException $e) {
  19. die('DB error: ' . $e->getMessage() . "\n");
  20. }
  21. return $dbh;
  22. }
  23. function login() {
  24. global $API_BASE;
  25. global $OD_USER;
  26. global $OD_PASSWD;
  27. $ch = curl_init($API_BASE . '/session/login.json');
  28. curl_setopt_array($ch, array(
  29. CURLOPT_POST => TRUE,
  30. CURLOPT_RETURNTRANSFER => TRUE,
  31. CURLOPT_HTTPHEADER => array(
  32. 'Content-Type: application/json'
  33. ),
  34. CURLOPT_POSTFIELDS => json_encode($postData)
  35. ));
  36. // Send the request
  37. $response = curl_exec($ch);
  38. // Check for errors
  39. if($response === FALSE){
  40. die(curl_error($ch));
  41. }
  42. // Decode the response
  43. $responseData = json_decode($response, TRUE);
  44. return($responseData);
  45. }
  46. ?>