Browse Source

Updated Users: removed required username on get/load

Joachim M. Giæver 6 years ago
parent
commit
25664d1781
2 changed files with 6 additions and 7 deletions
  1. 4 2
      index.php
  2. 2 5
      src/API/Request/User.php

+ 4 - 2
index.php

@@ -12,7 +12,8 @@ require "./src/gpac.php";
 use Gogs\Lib\Curl\Exception as ApiException;
 
 define('API_URL', 'https://git.giaever.org/api/v1');
-define('API_TOKEN', '142efbfd6fbdf147f03d289f8b22a438eaa1b5d1');
+//define('API_TOKEN', '142efbfd6fbdf147f03d289f8b22a438eaa1b5d1');
+define('API_TOKEN', 'e14b9eff0749b6f0c4cadf4bb72b83d44578ae28');
 
 $client =  new Gogs\API\Client(API_URL, API_TOKEN);
 
@@ -94,6 +95,7 @@ try {
 
     $orgs = $me->orgs()->load();
 
+    /*
     try {
         echo "\nCreate organization\n";
         $org = $orgs->create(
@@ -105,7 +107,7 @@ try {
         throw new ApiException\NotAuthorizedException("Creating organization", $e->getCode(), $e);
     } catch (ApiException\HTTPUnexpectedResponse $e) {
         echo $e->getResponse();
-    }
+    }*/
 
     echo "\nLooking up organizations of test-" . $me->username . "\n";
     foreach($orgs->search(array("name" => "test-" . $me->username))->all() as $key => $org)

+ 2 - 5
src/API/Request/User.php

@@ -18,7 +18,7 @@ namespace Gogs\API\Request {
      * @see Orgs
      * 
      * @author Joachim M. Giaever (joachim[]giaever.org)
-     * @version 0.1
+     * @version 0.1.1
      */
     class User extends Base {
 
@@ -66,10 +66,7 @@ namespace Gogs\API\Request {
                 break;
             case "get":
             case "load":
-                if (!$this->authenticated && empty($this->username))
-                    throw new Exception\RequestErrorException("Missing userdata 'username'.");
-
-                $this->scope = ($this->authenticated ? "/user" : "/users/" . $this->username);
+                $this->scope = empty($this->username) ? "/user" : "/users/" . $this->username;
                 break;
             default:
                 return false;