index.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * TODO:
  4. *
  5. * Rewrite this. Shouldnt be a test file, like its now.
  6. *
  7. * */
  8. define('BASE_PATH', realpath(dirname(__FILE__)));
  9. define('API_URL', 'https://git.giaever.org/api/v1');
  10. define('API_TOKEN', '142efbfd6fbdf147f03d289f8b22a438eaa1b5d1');
  11. function my_autoloader($class) {
  12. $file = str_replace("\\", DIRECTORY_SEPARATOR, strtolower($class)) . ".php";
  13. echo $class . ' -> ' . $file . "\n";
  14. require_once BASE_PATH . DIRECTORY_SEPARATOR . $file;
  15. }
  16. spl_autoload_register('my_autoloader');
  17. try {
  18. $client = new \Client\GogsAPI(API_URL, API_TOKEN);
  19. //$users = $client->users()->search(array("name" => "bje007"));
  20. $me = $client->user()->load();
  21. try {
  22. // Create new repo
  23. $repo = $me->repos()->new(
  24. /*name*/ "gogs-php-api-client-test",
  25. /*desc*/ "Repository created from test file.",
  26. /*private*/ false,
  27. /*auto init*/ true,
  28. /*git ignore*/ "Vim",
  29. /*license*/ "MIT License"
  30. /* default read me */
  31. );
  32. echo "New repo created!\n";
  33. } catch(\Lib\HTTPUnexpectedResponse $e) {
  34. // Repo exists, get it!
  35. $repo = $me->repo("gogs-php-api-client-test");
  36. // Delete it (it will now be created on reload!)
  37. $repo->delete();
  38. echo "Repo deleted\n";
  39. }
  40. } catch (\Lib\NotAuthorizedException $e) {
  41. die("NOT AUTH: " . $e->getMessage());
  42. } catch (\Lib\HTTPUnexpectedResponse $e) {
  43. die($e);
  44. }
  45. ?>