Browse Source

Added user bug on missing username

Joachim M. Giæver 6 years ago
parent
commit
f16a15c070
2 changed files with 9 additions and 6 deletions
  1. 7 6
      index.php
  2. 2 0
      src/API/Request/User.php

+ 7 - 6
index.php

@@ -13,13 +13,12 @@ use Gogs\Lib\Curl\Exception as ApiException;
 
 define('API_URL', 'https://git.giaever.org/api/v1');
 define('API_TOKEN', '142efbfd6fbdf147f03d289f8b22a438eaa1b5d1');
-//define("API_TOKEN", 'e14b9eff0749b6f0c4cadf4bb72b83d44578ae28');
 
 
 try {
     $client =  new Gogs\API\Client(API_URL, API_TOKEN);
 
-    $me = $client->user("")->load();
+    $me = $client->user()->load();
 
     $user_search = $client->users()->search(array(
         "name" => "tester2"
@@ -48,6 +47,7 @@ try {
 
     } catch(ApiException\HTTPUnexpectedResponse $e) {
 
+        echo $e;
         // Repo exists, get it!
         $repo = $me->repo("gogs-php-api-client-test");
 
@@ -61,10 +61,11 @@ try {
     foreach($me->organizations()->load()->all() as $org)
         var_dump("ORG", $org->username);
 
-    echo sprintf(
-        "org->username: %s\norg->org_username: %s\norg->user_username: %s\n",
-        $org->username, $org->org_username, $org->user_username
-    ); 
+    if (isset($org))
+        echo sprintf(
+            "org->username: %s\norg->org_username: %s\norg->user_username: %s\n",
+            $org->username, $org->org_username, $org->user_username
+        ); 
 
     // Requires ADMIN rights to the authenticated user
     #try {

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

@@ -41,6 +41,8 @@ namespace Gogs\API\Request {
         public function __construct(string $api_url, string $api_token, string $user = "") {
             $this->authenticated = (empty($user) || $user == "me");
             parent::__construct($api_url, $api_token);
+            if (!$this->authenticated())
+                $this->username = $user;
         }
 
         /**