README.md 2.6 KB

gogs-php-api-client

A client to query Gogs (https://gogs.io) API from PHP.

Uages:

A guide on how to use will come shortly!

Quick example:

Clone the repo. Set the API_URL and API_TOKEN in the index-file.

$client =  new \Client\GogsAPI(API_URL, API_TOKEN);

$me = $client->user();
$other = $client->user("username");

$repos = $me->get("/repos")->load();

// Loop through every repo
for($repo = $repos->current(); $repo != false; $repo = $repos->next())
    var_dump($repo);

Progress

Users

Search

GET /users/search
$users = $client->users()->search(array("name" => /* username */));

The array-param can be

  • name/q: The username
  • limit: maximum number of results, default: 10

Returns a CollectionResult, e.g

foreach ($users as $user)
    echo $user->ufull_name . "\n";

Get authenticated user

GET /user
$me = $client->user(); // alt: $client->users()->get()

Get a single user

GET /users/:username
$user = $client->user("username"); // alt: $client->users()->get("username")

Create a user

POST /admin/users
$user = $clients->users()->new(
    "new user", "users@email.com"
);

The params should be in the order

  • username (required)
  • email (required)
  • source_id
  • login_name
  • password
  • send_notify

Requires the authenticated user to have admin rights.

Delete a user

DELETE /admin/users/:username
$user->delete();

Requires the authenticated user to have admin rights.

Get a user's repos

GET /user/repos

or

GET /users/:username/repos
$repos = $user->repos()->load();

Get specific user's repo

GET /repos/:owner/:repo
$repo = $user->repo( /* repo */ );

Create a user's repo

POST /user/repos

or

POST /admin/users/:username/repos
$user->repos()->new(
    "name"
);

The params should be in the order

  • name
  • description
  • private
  • bool
  • auto_init
  • gitignores
  • license
  • readme

Requires the authenticated user to have admin rights to be able to create repos for other users than itself.

Delete a user's repo

DELETE /repos/:owner/:repo
$repo->delete();

Requires the authenticated user to have admin rights to be able to delete repos for other users than itself.

Get a user's organizations

GET /user/orgs

or

GET /users/:username/orgs
$orgs = $user->organizations();

Organizations

Get an organizations repositories

GET /orgs/:orgname/repos
$org = $user->organizations()->load()->current();

$repos = $org->repos();