Gogs\APIGogs API client.
This class initially provide the programmer with a starting point (a kind of an "interface" to start from), to keep track of the context when going from a user, to a repo, organization etc.
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | ||
| users | Users | public | Returns a Request\Users to fetch users from theGogs installation. |
| user | User | public | Get a single user from Gogs. |
| repos | Repos | public | Returns an \Request\Repos to fetch repositorieson the Gogs installation. |
| get_log | array | public | A wrapper function as get_log on Client wontreturn anything. This is bogus, but. |
Gogs\API\Clientpublic function __construct(string $api_url, string $api_token);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $api_url | The base URL for the Gogs API (e.g https://git.domain.tld/api/v1) |
| string | $api_token | The token for an authorized user to query Gogs API. |
Gogs\API\Clientpublic function users();
Returns a Request\Users to fetch users from the Gogs installation.
Returns: Users
Gogs\API\Clientpublic function user(string $name = "me");
Get a single user from Gogs.
Returns either
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $name | None |
Returns: User
Gogs\API\Clientpublic function repos();
Returns an \Request\Repos to fetch repositories on the Gogs installation.
Returns: Repos
Gogs\API\Clientpublic function get_log();
A wrapper function as get_log on Client wont return anything. This is bogus, but.
... this workaround WORKS!
Returns: array
Gogs\API\RequestBase class for request types.
Each request shall inherit this class to ensure it will have the correct methods required by interface, and get the cURL functionality.
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | ||
| load | object | final public | Load an object. |
| method_get | string | final protected | Perform a GET-request against the Gogs API. |
| method_post | string | final protected | Perform a POST-request against the Gogs API. |
| method_delete | string | final protected | Perform a DELETE-request against the Gogs API. |
| get | object | public | Get object references by identifier. |
| create | bool | public | Create object inherited by class. |
| patch | bool | public | Patch (update) object |
| delete | bool | public | Delete object. |
| json_decode | object | final protected | Decode JSON-string. |
| json_encode | string | final protected | Encode JSON-object/array. |
| json_error | final protected | Check for errors on encoding/decoding. | |
| json_set_property | true v array | protected | Set properties for the current object. |
| property_exists | string v false | final protected | Checks if the property (key) exists within selfor parent class. |
| __get | mixed v null | final public | Get property by name. |
| __set | mixed v null | final public | Set property by name. |
| __isset | bool | final public | Checks if property is set. |
| set_scope | bool | abstract protected | Set the scope for the request methods accepted by the child. |
| search | true | protected | Search for an matching object. |
Gogs\API\Request\Basepublic function __construct(string $api_url, string $api_token);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $api_url | The URL to the API. |
| string | $api_token | A token for an authorized user |
Gogs\API\Request\Basefinal public function load(bool $force = false);
Load an object.
If $force = true the object will be fetched
from the Gogs API again.
Parameters
| Type | Variable | Description |
|---|---|---|
| bool | $force | Force update, default: true |
Returns: object
Throws:
Gogs\API\Request\Basefinal protected function method_get(array $params = array());
Perform a GET-request against the Gogs API.
Ensure the correct scope i set first, with
$this->set_scope("*valid scope*"); // e.g create
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $params | The parameters |
Returns: string
Gogs\API\Request\Basefinal protected function method_post(array $params = array());
Perform a POST-request against the Gogs API.
Ensure the correct scope i set first, with
$this->set_scope("*valid scope*"); // e.g create
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $params | The parameters |
Returns: string
Gogs\API\Request\Basefinal protected function method_delete();
Perform a DELETE-request against the Gogs API.
Ensure the correct scope i set first, with
$this->set_scope("*valid scope*"); // e.g delete
Returns: string
Gogs\API\Request\Basepublic function get(string $s);
Get object references by identifier.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $s | The idientifier to look up |
Returns: object
Gogs\API\Request\Basepublic function create(... $args);
Create object inherited by class.
Child class must add a scope for 'create' and ensure child is not loaded,
otherwise will create throw an exception.
Parameters
| Type | Variable | Description |
|---|---|---|
| ... | $args | Arguments required by create. |
Returns: bool
Throws:
Gogs\API\Request\Basepublic function patch();
Patch (update) object
Returns: bool
Throws:
Gogs\API\Request\Basepublic function delete();
Delete object.
Returns: bool
Throws:
Gogs\API\Request\Basefinal protected function json_decode(string $jenc);
Decode JSON-string.
Will ensure that there weren't any errors by calling $this->json_error.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $jenc | Encoded JSON string |
Returns: object
Gogs\API\Request\Basefinal protected function json_encode(iterable $jdec);
Encode JSON-object/array.
Will ensure that there weren't any errors by calling $this->json_error.
Parameters
| Type | Variable | Description |
|---|---|---|
| iterable | $jdec | JSON-data |
Returns: string
Gogs\API\Request\Basefinal protected function json_error();
Check for errors on encoding/decoding.
Throws:
Gogs\API\Request\Baseprotected function json_set_property(iterable $obj);
Set properties for the current object.
Each child class must implement this to set its data. Will
be called by methods such as load and from collection
classes.
Will return true/false for singel objects but an array on collections. The array will contain the newly inserted elements. This to prevent additional iterations.
This method should also set loaded to true or false, depending on success or failure.
Parameters
| Type | Variable | Description |
|---|---|---|
| iterable | $obj | None |
Returns: true v array
Gogs\API\Request\Basefinal protected function property_exists(mixed $name);
Checks if the property (key) exists within self or parent class.
Returns the actual key if it does. A class key (aka property)
start with the tag classname_ followed by property name,
reflecting the JSON-object, and can be reached by
$class->parameter,$class->classname_parameter or alternatively (for classes that inherits another class).$class->parentclassname_parameter.If a class override a parent class with the same parameter, the class's own parameter will be favoured.
As this is public properties this wont be an security issue;
Parameters
| Type | Variable | Description |
|---|---|---|
| mixed | $name | Name of the key. |
Returns: string v false
Gogs\API\Request\Basefinal public function __get(string $name);
Get property by name.
Checks both self and parent for the property.
Returns the value if property exists, otherwise an E_USER_NOTICE
is triggered.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $name | None |
Returns: mixed v null
Gogs\API\Request\Basefinal public function __set(string $name, mixed $value);
Set property by name.
Checks both self and parent for the property.
Returns the value if property exists, otherwise an E_USER_NOTICE
is triggered.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $name | Property name |
| mixed | $value | Property value |
Returns: mixed v null
Gogs\API\Request\Basefinal public function __isset(string $name);
Checks if property is set.
Checks both self and parent for property.
Triggers E_USER_NOTICE if property is unknown.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $name | Property name |
Returns: bool
Gogs\API\Request\Baseabstract protected function set_scope(string $method);
Set the scope for the request methods accepted by the child.
This can be
get,search,delete etc.Must return true if scope exists of false otherwise. Methods the calls this will throw an exception if not true is returned.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $method | Method type, e.g "get" |
Returns: bool
Gogs\API\Request\Baseprotected function search(array $params = array(), bool $strict = false);
Search for an matching object.
Methods do OR-ing and not AND-ing by default.
Params should be key (object property) and value that this parameter should match, e.g
$repo->search(
"name" => "this",
"owner" => array(
"username" => "that"
)
);
will match "this" IN $repo->name OR "that" IN $repo->owner->username .
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $params | Parameters |
| bool | $strict | Turn search into AND-ing, require match in each field. |
Returns: true
Throws:
Gogs\API\RequestA single Branch
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | Initialize a branch for the given repository. | |
| set_scope | bool | protected |
Gogs\API\Request\Branchpublic function __construct(string $api_url, string $api_token, Repo $repo);
Initialize a branch for the given repository.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $api_url | The URL to the API. |
| string | $api_token | A token for an authorized user |
| Repo | $repo | Related repository |
Gogs\API\Request\Branchprotected function set_scope(string $method);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $method | Method type, e.g "get" |
Returns: bool
Gogs\API\RequestHolds a collection of Branches for a Repository.
Supported:
/repos/username/repo/branches| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | Initialize Brances for a given repo | |
| set_scope | bool | protected | |
| search | true | public | Search for a branch. |
| sort_by | Collection | public | |
| add_object | array | protected |
Gogs\API\Request\Branchespublic function __construct(string $api_url, string $api_token, Repo $repo);
Initialize Brances for a given repo
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $api_url | The URL to the API. |
| string | $api_token | A token for an authorized user |
| Repo | $repo | The repository |
Gogs\API\Request\Branchesprotected function set_scope(string $method);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $method | Method type, e.g "get" |
Returns: bool
Gogs\API\Request\Branchespublic function search(array $params = array(), bool $strict = true);
Search for a branch.
This method doesnt search by a uri, instead it will load every branch from Gogs and do a match on this.
Params can be an array of
$branches->search(array(
"name" => "name", // alt. "q". required
"limit" => 10, // not required, default: 10
));
By now, this method can be intensive, as it will load every branch and then do a match on each entry.
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $params | Parameters |
| bool | $strict | Turn search into AND-ing, require match in each field. |
Returns: true
Throws:
Gogs\API\Request\Branchespublic function sort_by(int $flag = Collection::SORT_INDEX);
Parameters
| Type | Variable | Description |
|---|---|---|
| int | $flag | Sorting flag |
Returns: Collection
Gogs\API\Request\Branchesprotected function add_object(iterable $obj);
Parameters
| Type | Variable | Description |
|---|---|---|
| iterable | $obj | None |
Returns: array
Gogs\API\RequestCollection is a collection of data of one type.
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | Initialize a collection. | |
| add | mixed v int | protected | Add an object to the collection. |
| remove | bool | protected | Remove an element in collection. |
| copy | Colletion | public | |
| all | array | public | |
| len | int | public | |
| by_key | mixed | public | |
| next | mixed | public | |
| prev | mixed | public | |
| current | public | ||
| reset | mixed | public | |
| sort | Collection | public | |
| filter | Collection | public | |
| limit | Collection | public | |
| offset | Collection | public | |
| reverse | Collection | public | |
| json_set_property | true v array | protected | |
| search | true | public | Search an collection. |
| add_object | array | abstract protected | Add an object to the collection with the specific type. |
| sort_by | Collection | abstract public | Sort the object |
Gogs\API\Request\Collectionpublic function __construct(string $api_url, string $api_token, Collection $other = null);
Initialize a collection.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $api_url | The URL to the API. |
| string | $api_token | A token for an authorized user |
| Collection | $other | Collection to initialize from |
Gogs\API\Request\Collectionprotected function add(mixed $obj, mixed $key = null);
Add an object to the collection.
When adding a key the object will be stored on the particual key, also overwriting existing data.
Parameters
| Type | Variable | Description |
|---|---|---|
| mixed | $obj | Element to store |
| mixed | $key | Index key to store on |
Returns: mixed v int
Gogs\API\Request\Collectionprotected function remove(mixed $any, bool $deep = true);
Remove an element in collection.
The function will first look for the element as a index key, but if its not found it will look for the element as a value.
Deep functions only when the value is given and not the key.
Parameters
| Type | Variable | Description |
|---|---|---|
| mixed | $any | Index key or element value |
| bool | $deep | Delete every item and not just the first |
Returns: bool
Gogs\API\Request\Collectionpublic function copy();
Returns: Colletion
Gogs\API\Request\Collectionpublic function all();
Returns: array
Gogs\API\Request\Collectionpublic function len();
Returns: int
Gogs\API\Request\Collectionpublic function by_key(mixed $idx);
Parameters
| Type | Variable | Description |
|---|---|---|
| mixed | $idx | Index key. |
Returns: mixed
Gogs\API\Request\Collectionpublic function next();
Returns: mixed
Gogs\API\Request\Collectionpublic function prev();
Returns: mixed
Gogs\API\Request\Collectionpublic function current();
Gogs\API\Request\Collectionpublic function reset();
Returns: mixed
Gogs\API\Request\Collectionpublic function sort(callable $f);
Parameters
| Type | Variable | Description |
|---|---|---|
| callable | $f | None |
Returns: Collection
Gogs\API\Request\Collectionpublic function filter(callable $f);
Parameters
| Type | Variable | Description |
|---|---|---|
| callable | $f | None |
Returns: Collection
Gogs\API\Request\Collectionpublic function limit(int $lim);
Parameters
| Type | Variable | Description |
|---|---|---|
| int | $lim | Maximum entries returned |
Returns: Collection
Gogs\API\Request\Collectionpublic function offset(int $off);
Parameters
| Type | Variable | Description |
|---|---|---|
| int | $off | Offset from in collection |
Returns: Collection
Gogs\API\Request\Collectionpublic function reverse();
Returns: Collection
Gogs\API\Request\Collectionprotected function json_set_property(iterable $obj);
Parameters
| Type | Variable | Description |
|---|---|---|
| iterable | $obj | None |
Returns: true v array
Gogs\API\Request\Collectionpublic function search(array $params = array(), bool $strict = false);
Search an collection.
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $params | Parameters |
| bool | $strict | Turn search into AND-ing, require match in each field. |
Returns: true
Throws:
Gogs\API\Request\Collectionabstract protected function add_object(iterable $object);
Add an object to the collection with the specific type.
Typically it will create an instance of the type that the collection will consist of.
Should call json set property
Parameters
| Type | Variable | Description |
|---|---|---|
| iterable | $object | None |
Returns: array
Gogs\API\Request\Collectionabstract public function sort_by(int $flag = \Gogs\Lib\ArrayIterator::SORT_INDEX);
Sort the object
Should call sort on parent with the specified sort method, given by $flag
Parameters
| Type | Variable | Description |
|---|---|---|
| int | $flag | Sorting flag |
Returns: Collection
Gogs\API\RequestStores data and methods related to a single organization.
By now the following are supported:
/orgs/username/admin/users/username/orgs (Requires admin rights. Curl will throw NotAuthorized exception if not).| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | Initialize an organization. | |
| set_scope | bool | protected | |
| create | bool | public | Create a new user |
Gogs\API\Request\Orgpublic function __construct(string $api_url, string $api_token, User $owner = null, string $oname = null);
Initialize an organization.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $api_url | The URL to the API. |
| string | $api_token | A token for an authorized user |
| User | $owner | The owner of the organization |
| string | $oname | Organization name |
Gogs\API\Request\Orgprotected function set_scope(string $method);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $method | Method type, e.g "get" |
Returns: bool
Throws:
Gogs\API\Request\Orgpublic function create(... $args);
Create a new user
Valid parameters:
This reflects the API v1 doc, but is in an order where the required fields is first.
Parameters
| Type | Variable | Description |
|---|---|---|
| ... | $args | Arguments required by create. |
Returns: bool
Gogs\API\RequestOrgs is a collection of organizations.
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | Initialize an organization collection for user. | |
| set_scope | bool | protected | |
| create | bool | public | Create a new organization |
| get | object | public | Get an organization by indentifier. |
| search | true | public | Search for an organization. |
| add_object | array | protected | |
| sort_by | Collection | public |
Gogs\API\Request\Orgspublic function __construct(string $api_url, string $api_token, User $owner);
Initialize an organization collection for user.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $api_url | The URL to the API. |
| string | $api_token | A token for an authorized user |
| User | $owner | The user |
Gogs\API\Request\Orgsprotected function set_scope(string $method);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $method | Method type, e.g "get" |
Returns: bool
Gogs\API\Request\Orgspublic function create(... $args);
Create a new organization
If arguments are given, the User will be created, otherise it will return an initialized object, leaving the programmer to create the user.
Parameters
| Type | Variable | Description |
|---|---|---|
| ... | $args | Arguments required by create. |
Returns: bool
Gogs\API\Request\Orgspublic function get(string $s);
Get an organization by indentifier.
Method will first look through organizations already loaded. If not found it will return a new object.
Method does not ensure the organization in loaded
from Gogs so the user should call ->load() on
returned element.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $s | The idientifier to look up |
Returns: object
Gogs\API\Request\Orgspublic function search(array $params = array(), bool $strict = false);
Search for an organization.
Params can be an array of
$orgs->search(array(
"name" => "name", // alt. "q". required
"limit" => 10, // not required, default: 10
));
By now, this method can be intensive, as it will load every organization and then do a match on each entry.
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $params | Parameters |
| bool | $strict | Turn search into AND-ing, require match in each field. |
Returns: true
Throws:
Gogs\API\Request\Orgsprotected function add_object(iterable $obj);
Parameters
| Type | Variable | Description |
|---|---|---|
| iterable | $obj | None |
Returns: array
Gogs\API\Request\Orgspublic function sort_by(int $flag = Collection::SORT_INDEX);
Parameters
| Type | Variable | Description |
|---|---|---|
| int | $flag | Sorting flag |
Returns: Collection
Gogs\API\RequestStores data and methods related to a single repository.
By now the following are supported:
/repos/username/reponame/user/repos/admin/user/username/repos/org/orgname/repos/repos/username/reponame| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | Initialize a repo object. | |
| set_scope | bool | protected | |
| branches | Branches | public | Return branches for repository. |
| json_set_property | true v array | protected | Overrides Base method as this should set owner as well |
| create | bool | public | Create a new repo |
| migrate | public | Migrate a repository from other Git hosting sources. | |
| sync | bool | public | Add repo to sync queue. |
Gogs\API\Request\Repopublic function __construct(string $api_url, string $api_token, User $owner = null, string $name = null);
Initialize a repo object.
Note that the owner can also be an Org (organization), or any other class that inherits a user.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $api_url | The URL to the API. |
| string | $api_token | A token for an authorized user |
| User | $owner | The owner of the repo |
| string | $name | The repo name |
Gogs\API\Request\Repoprotected function set_scope(string $method);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $method | Method type, e.g "get" |
Returns: bool
Throws:
Gogs\API\Request\Repopublic function branches();
Return branches for repository.
Returns: Branches
Gogs\API\Request\Repoprotected function json_set_property(iterable $obj);
Overrides Base method as this should set owner as well
Parameters
| Type | Variable | Description |
|---|---|---|
| iterable | $obj | None |
Returns: true v array
Gogs\API\Request\Repopublic function create(... $args);
Create a new repo
Valid paramters:
This reflects the API v1 documentation, but is in an order where the required fields are first.
Parameters
| Type | Variable | Description |
|---|---|---|
| ... | $args | Arguments required by create. |
Returns: bool
Gogs\API\Request\Repopublic function migrate(mixed $args);
Migrate a repository from other Git hosting sources.
Valid parameters:
UID will be set to owner. Either a User or an Organization.
From API doc: To migrate a repository for a organization,
the authenticated user must be a owner of the specified organization.
This reflects the API v1 documentation, but is in an order where the required fields as first.
Parameters
| Type | Variable | Description |
|---|---|---|
| mixed | $args | None |
Throws:
Gogs\API\Request\Repopublic function sync();
Add repo to sync queue.
Requires the repository to be a mirror.
Returns: bool
Gogs\API\RequestRepos is a collection of repos.
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | Initialize a repos collection | |
| set_scope | bool | protected | |
| get | object | public | Get a single repository by name. |
| create | bool | public | |
| search | true | public | Searches for a repo. |
| sort_by | Collection | public | Sort repos by method. |
| add_object | array | protected | |
| privates | Collection | public | Get private repositories |
| publics | Collection | public | Get public repositories |
| personals | Collection | public | Get personal repositories |
| contributions | Collection | public | Get repositories contributed to |
| personals_privates | Collection | public | Get personal private repositories |
| personals_publics | Collection | public | Get personal public repositories |
| contributions_privates | Collection | public | Get private contributions |
| contributions_publics | Collection | public | Get public contributions |
Gogs\API\Request\Repospublic function __construct(string $api_url, string $api_token, User $owner = null);
Initialize a repos collection
If owner is not set it will query the whole repo archive on Gogs.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $api_url | The URL to the API. |
| string | $api_token | A token for an authorized user |
| User | $owner | The owner of the collection |
Gogs\API\Request\Reposprotected function set_scope(string $method);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $method | Method type, e.g "get" |
Returns: bool
Gogs\API\Request\Repospublic function get(string $name);
Get a single repository by name.
If the owner is set, the name can be just the
actual name of the repo
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $name | None |
Returns: object
Gogs\API\Request\Repospublic function create(... $args);
Parameters
| Type | Variable | Description |
|---|---|---|
| ... | $args | Arguments required by create. |
Returns: bool
Gogs\API\Request\Repospublic function search(array $params = array(), bool $strict = false);
Searches for a repo.
If the owner is specified the search will be limited to the actual user.
Params can be an array of
$repos->search(array(
"name" => "name", // alt. "q". required
"limit" => 10, // not required, default: 10
));
If repositories is allready loaded it will do a match on the existing collection.
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $params | Parameters |
| bool | $strict | Turn search into AND-ing, require match in each field. |
Returns: true
Throws:
Gogs\API\Request\Repospublic function sort_by(int $flag = Collection::SORT_INDEX, bool $asc = false);
Sort repos by method.
Valid methods:
updated_at valuecreated_at valueowner (organization repos etc may appear)Parameters
| Type | Variable | Description |
|---|---|---|
| int | $flag | Sorting flag |
| bool | $asc | Ascending order |
Returns: Collection
Gogs\API\Request\Reposprotected function add_object(iterable $obj);
Parameters
| Type | Variable | Description |
|---|---|---|
| iterable | $obj | None |
Returns: array
Gogs\API\Request\Repospublic function privates();
Get private repositories
Returns: Collection
Gogs\API\Request\Repospublic function publics();
Get public repositories
Returns: Collection
Gogs\API\Request\Repospublic function personals();
Get personal repositories
Returns: Collection
Gogs\API\Request\Repospublic function contributions();
Get repositories contributed to
Returns: Collection
Gogs\API\Request\Repospublic function personals_privates();
Get personal private repositories
Returns: Collection
Gogs\API\Request\Repospublic function personals_publics();
Get personal public repositories
Returns: Collection
Gogs\API\Request\Repospublic function contributions_privates();
Get private contributions
Returns: Collection
Gogs\API\Request\Repospublic function contributions_publics();
Get public contributions
Returns: Collection
Gogs\API\RequestA token related to a user
Supports:
/users/{username}/tokensNote! Tokens doesnt have a "GET" method. @see Tokens as this can load them.
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | Initializes a token | |
| set_scope | bool | protected | |
| create | bool | public | Create a new token |
Gogs\API\Request\Tokenpublic function __construct(string $api_url, string $password, User $user);
Initializes a token
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $api_url | The URL to the API. |
| string | $password | The users personal password |
| User | $user | None |
Gogs\API\Request\Tokenprotected function set_scope(string $method);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $method | Method type, e.g "get" |
Returns: bool
Gogs\API\Request\Tokenpublic function create(... $args);
Create a new token
Valid parameters:
This reflects the API v1 documentation.
Parameters
| Type | Variable | Description |
|---|---|---|
| ... | $args | Arguments required by create. |
Returns: bool
Gogs\API\RequestCollection of tokens for a given user.
Supports:
/users/{username}/tokens| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | Initialize a token collection. | |
| set_scope | bool | protected | |
| create | bool | public | Create a new token. |
| add_object | array | protected | |
| get | object | public | Return a token by name |
| search | true | public | Search for a token. |
| sort_by | Collection | public |
Gogs\API\Request\Tokenspublic function __construct(string $api_url, string $password, User $user);
Initialize a token collection.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $api_url | The URL to the API. |
| string | $password | User's personal password |
| User | $user | Owner of tokens |
Gogs\API\Request\Tokensprotected function set_scope(string $method);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $method | Method type, e.g "get" |
Returns: bool
Gogs\API\Request\Tokenspublic function create(... $args);
Create a new token.
Returns a new token object. If arguments is specified the "token" will be created.
Arguments can be left empty to "create" the token, leaving the programmer to call create on the token object with the arguments itself, to create it.
Creating the token through this function will store the function in
the collection. If not created, it wont be added, and collection
must be reloaded (->load(true)) to add it.
Parameters
| Type | Variable | Description |
|---|---|---|
| ... | $args | Arguments required by create. |
Returns: bool
Gogs\API\Request\Tokensprotected function add_object(iterable $obj);
Parameters
| Type | Variable | Description |
|---|---|---|
| iterable | $obj | None |
Returns: array
Gogs\API\Request\Tokenspublic function get(string $s);
Return a token by name
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $s | The idientifier to look up |
Returns: object
Gogs\API\Request\Tokenspublic function search(array $params = array(), bool $strict = false);
Search for a token.
Params can be an array of
$orgs->search(array(
"name" => "name", // alt. "q". required
"limit" => 10, // not required, default: 10
));
By now, this method can be intensive, as it will load every token and then do a match on each entry.
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $params | Parameters |
| bool | $strict | Turn search into AND-ing, require match in each field. |
Returns: true
Throws:
Gogs\API\Request\Tokenspublic function sort_by(int $flag = Collection::SORT_INDEX);
Parameters
| Type | Variable | Description |
|---|---|---|
| int | $flag | Sorting flag |
Returns: Collection
Gogs\API\RequestStores user data and methods related to a single user.
By now the following are supported:
/user/users/username/admin/users (Requires admin rights. Curl will throw NotAuthorized exception if not)./admin/users (Requires admin rights. Curl will throw NotAuthorized exception if not).A user can also list it's repos and organizations.
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | Initialize an user object. | |
| set_scope | bool | protected | |
| authenticated | bool | public | Returns if the user is the authenticated user. |
| repos | Repos | public | Returns every repo under user. |
| repo | Repo | public | Return a single repo. |
| organizations | Orgs | public | Return every organization under user. |
| orgs | public | ||
| organization | Org | public | Return a single organization. |
| org | public | ||
| create | bool | public | Create a new user. |
| tokens | Tokens | public | Returns user tokens |
Gogs\API\Request\Userpublic function __construct(string $api_url, string $api_token, string $user = "");
Initialize an user object.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $api_url | The URL to the API. |
| string | $api_token | A token for an authorized user |
| string | $user | The username. "Empty" or "me" will return authenticated user |
Gogs\API\Request\Userprotected function set_scope(string $method);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $method | Method type, e.g "get" |
Returns: bool
Throws:
Gogs\API\Request\Userpublic function authenticated();
Returns if the user is the authenticated user.
Returns: bool
Gogs\API\Request\Userpublic function repos();
Returns every repo under user.
Returns: Repos
Gogs\API\Request\Userpublic function repo(string $name);
Return a single repo.
Note: This will also load the repo.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $name | Repo name |
Returns: Repo
Gogs\API\Request\Userpublic function organizations();
Return every organization under user.
Returns: Orgs
Gogs\API\Request\Userpublic function orgs();
Gogs\API\Request\Userpublic function organization(string $name);
Return a single organization.
Note: This will also load the repo.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $name | Organization name |
Returns: Org
Gogs\API\Request\Userpublic function org(string $name);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $name | None |
Gogs\API\Request\Userpublic function create(... $args);
Create a new user.
Valid parameters
This reflects the API v1 documentation, but is in an order where the required fields are first.
Parameters
| Type | Variable | Description |
|---|---|---|
| ... | $args | Arguments required by create. |
Returns: bool
Gogs\API\Request\Userpublic function tokens(string $password);
Returns user tokens
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $password | User personal password. |
Returns: Tokens
Gogs\API\RequestReturns one or more users in the Gogs installation, depending on the called method.
| Name | Return | Access | Description |
|---|---|---|---|
| set_scope | bool | protected | |
| create | bool | public | Returns a new user object. If argumentsis specified the user will be "created". |
| get | object | public | Return a user by username. |
| search | true | public | Search for an user |
| sort_by | Collection | public | |
| add_object | array | protected |
Gogs\API\Request\Usersprotected function set_scope(string $method);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $method | Method type, e.g "get" |
Returns: bool
Gogs\API\Request\Userspublic function create(... $args);
Returns a new user object. If arguments is specified the user will be "created".
The arguments can be left out to "create" the user through the user object iteself.
Parameters
| Type | Variable | Description |
|---|---|---|
| ... | $args | Arguments required by create. |
Returns: bool
Gogs\API\Request\Userspublic function get(string $s);
Return a user by username.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $s | The idientifier to look up |
Returns: object
Gogs\API\Request\Userspublic function search(array $params = array(), bool $strict = false);
Search for an user
Params can be an array of
$orgs->search(array(
"name" => "name", // alt. "q". required
"limit" => 10, // not required, default: 10
));
By now, this method can be intensive, as it will load every organization and then do a match on each entry.
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $params | Parameters |
| bool | $strict | Turn search into AND-ing, require match in each field. |
Returns: true
Throws:
Gogs\API\Request\Userspublic function sort_by(int $flag = Collection::SORT_INDEX);
Parameters
| Type | Variable | Description |
|---|---|---|
| int | $flag | Sorting flag |
Returns: Collection
Gogs\API\Request\Usersprotected function add_object(iterable $obj);
Parameters
| Type | Variable | Description |
|---|---|---|
| iterable | $obj | None |
Returns: array
Gogs\API\RequestRequest interface, used by any kind of request object.
| Name | Return | Access | Description |
|---|---|---|---|
| load | object | public | Load object. |
| get | object | public | Get by identifier |
| create | bool | public | Create object |
| patch | bool | public | Patch (update) object |
| delete | bool | public | Delete object |
Gogs\API\Request\RequestInterfacepublic function load(bool $force = false);
Load object.
Parameters
| Type | Variable | Description |
|---|---|---|
| bool | $force | Force update, default: true |
Returns: object
Gogs\API\Request\RequestInterfacepublic function get(string $s);
Get by identifier
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $s | The idientifier to look up |
Returns: object
Gogs\API\Request\RequestInterfacepublic function create(... $args);
Create object
Parameters
| Type | Variable | Description |
|---|---|---|
| ... | $args | Arguments required by create. |
Returns: bool
Gogs\API\Request\RequestInterfacepublic function patch();
Patch (update) object
Returns: bool
Gogs\API\Request\RequestInterfacepublic function delete();
Delete object
Returns: bool
Gogs\API\Request\ExceptionThrown whenever a class that inherits the base-class is used wrong (e.g tries to create on a loaded object)
Gogs\API\Request\ExceptionThrown when the requested method for a class isn't implemented.
Gogs\API\Request\ExceptionTypically thrown when needed data to build the query is missing.
Gogs\API\Request\ExceptionThrown when needed parameters for a search is missing.
Gogs\LibBase class for collections. Implements basic functions and typically used to return collections which wont be a part of the "request package"
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | ||
| set | public | Set value(e) to the collection. | |
| by_key | mixed | public | |
| copy | Colletion | public | Copy collection |
| all | array | public | |
| len | int | public | |
| next | mixed | public | |
| prev | mixed | public | |
| current | public | ||
| reset | mixed | public | |
| sort | Collection | public | |
| filter | Collection | public | Filter collection |
| limit | Collection | public | |
| offset | Collection | public | |
| reverse | Collection | public | |
| remove | bool | public | Remove an element in collection. |
Gogs\Lib\Collectionpublic function __construct(array $arr = array());
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $arr | None |
Gogs\Lib\Collectionpublic function set(mixed $val, mixed $key = null);
Set value(e) to the collection.
If the value is an array it will overwrite the whole object-array, aka everything.
Parameters
| Type | Variable | Description |
|---|---|---|
| mixed | $val | None |
| mixed | $key | None |
Gogs\Lib\Collectionpublic function by_key(mixed $idx);
Parameters
| Type | Variable | Description |
|---|---|---|
| mixed | $idx | Index key. |
Returns: mixed
Gogs\Lib\Collectionpublic function copy();
Copy collection
Returns: Colletion
Gogs\Lib\Collectionpublic function all();
Returns: array
Gogs\Lib\Collectionpublic function len();
Returns: int
Gogs\Lib\Collectionpublic function next();
Returns: mixed
Gogs\Lib\Collectionpublic function prev();
Returns: mixed
Gogs\Lib\Collectionpublic function current();
Gogs\Lib\Collectionpublic function reset();
Returns: mixed
Gogs\Lib\Collectionpublic function sort(callable $f);
Parameters
| Type | Variable | Description |
|---|---|---|
| callable | $f | None |
Returns: Collection
Gogs\Lib\Collectionpublic function filter(callable $f);
Filter collection
Parameters
| Type | Variable | Description |
|---|---|---|
| callable | $f | None |
Returns: Collection
Gogs\Lib\Collectionpublic function limit(int $lim);
Parameters
| Type | Variable | Description |
|---|---|---|
| int | $lim | Maximum entries returned |
Returns: Collection
Gogs\Lib\Collectionpublic function offset(int $off);
Parameters
| Type | Variable | Description |
|---|---|---|
| int | $off | Offset from in collection |
Returns: Collection
Gogs\Lib\Collectionpublic function reverse();
Returns: Collection
Gogs\Lib\Collectionpublic function remove(mixed $any, bool $deep = true);
Remove an element in collection.
The function will first look for the element as a index key, but if its not found it will look for the element as a value.
Deep functions only when the value is given and not the key.
Parameters
| Type | Variable | Description |
|---|---|---|
| mixed | $any | Index key or element value |
| bool | $deep | Delete every item and not just the first |
Returns: bool
Gogs\LibInterface to store one or more elements in array providing an iterator interface.
| Name | Return | Access | Description |
|---|---|---|---|
| current | public | Get current element in collection. | |
| next | mixed | public | Get next element in collection. |
| prev | mixed | public | Return previous element in collection. |
| reset | mixed | public | Reset collection (set array to head). |
| len | int | public | Return collection size. |
| all | array | public | Return the whole colection. |
| by_key | mixed | public | Get element by index key. |
| copy | Colletion | public | Copy collection |
| limit | Collection | public | Limit until in collection |
| offset | Collection | public | Get from offset collection |
| reverse | Collection | public | Reverse the collection |
| sort | Collection | public | Sort collection |
| filter | Collection | public | Filter collection |
Gogs\Lib\ArrayIteratorpublic function current();
Get current element in collection.
Gogs\Lib\ArrayIteratorpublic function next();
Get next element in collection.
Returns: mixed
Gogs\Lib\ArrayIteratorpublic function prev();
Return previous element in collection.
Returns: mixed
Gogs\Lib\ArrayIteratorpublic function reset();
Reset collection (set array to head).
Returns: mixed
Gogs\Lib\ArrayIteratorpublic function len();
Return collection size.
Returns: int
Gogs\Lib\ArrayIteratorpublic function all();
Return the whole colection.
Returns: array
Gogs\Lib\ArrayIteratorpublic function by_key(mixed $idx);
Get element by index key.
Parameters
| Type | Variable | Description |
|---|---|---|
| mixed | $idx | Index key. |
Returns: mixed
Gogs\Lib\ArrayIteratorpublic function copy();
Copy collection
Returns: Colletion
Gogs\Lib\ArrayIteratorpublic function limit(int $lim);
Limit until in collection
Parameters
| Type | Variable | Description |
|---|---|---|
| int | $lim | Maximum entries returned |
Returns: Collection
Gogs\Lib\ArrayIteratorpublic function offset(int $off);
Get from offset collection
Parameters
| Type | Variable | Description |
|---|---|---|
| int | $off | Offset from in collection |
Returns: Collection
Gogs\Lib\ArrayIteratorpublic function reverse();
Reverse the collection
Returns: Collection
Gogs\Lib\ArrayIteratorpublic function sort(callable $f);
Sort collection
Parameters
| Type | Variable | Description |
|---|---|---|
| callable | $f | None |
Returns: Collection
Gogs\Lib\ArrayIteratorpublic function filter(callable $f);
Filter collection
Parameters
| Type | Variable | Description |
|---|---|---|
| callable | $f | None |
Returns: Collection
Gogs\Lib\CurlA trait used for every class referencing the api-url and token.
| Name | Return | Access | Description |
|---|---|---|---|
| basic | protected | Basic sets the user for basic HTTP-authentication. | |
| set_param | protected | Set param into array | |
| filter_params | protected | Filter out NULL values from parameters. | |
| method | int | protected | Initializes a curl request of different kinds, dependingon the specified method. This can be |
| authorized | bool | protected | Checks if the user is authorized for the scope. Shouldn'tbe used frequently. One test for one scope should be enough,but if you know for sure thats you're programming with theuse of an authorized user you should leave this and justhandle the NotAuthorizedExeption whenever thrown. |
| get_log | array | public static | Returns log entries for the client. |
Gogs\Lib\Curl\Clientprotected function basic(string $user);
Basic sets the user for basic HTTP-authentication.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $user | None |
Gogs\Lib\Curl\Clientprotected function set_param(array $params, string $param_name, array $args, int $index, string $type, mixed $default = null, callable $f = null);
Set param into array
The specified callback will only run if the expected parameter is set. This callback can either overwrite paramtere as passing them as reference or throw an exception to indicate invalid data.
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $params | &$params Array to insert to |
| string | $param_name | Index in params-array |
| array | $args | Arguments array |
| int | $index | Index in arguments array |
| string | $type | Expected type of data |
| mixed | $default | Default if not expected type on index |
| callable | $f | Callback method if param is set |
Gogs\Lib\Curl\Clientprotected function filter_params(array $params);
Filter out NULL values from parameters.
Saves transferring size.
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $params | &$params Parameters |
Gogs\Lib\Curl\Clientprotected function method(string $method, string $req, string $scope, array $params, bool $ret);
Initializes a curl request of different kinds, depending on the specified method. This can be
DELETE, PATCH, POST or GET. An unidentified value will become a GET-request.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $method | either DELETE, PATCH, POST, GET |
| string | $req | &$req variable to store request body in |
| string | $scope | scope within the API (e.g /user/repos) |
| array | $params | parameters to pass |
| bool | $ret | return transfer |
Returns: int
Gogs\Lib\Curl\Clientprotected function authorized(string $scope = "");
Checks if the user is authorized for the scope. Shouldn't be used frequently. One test for one scope should be enough, but if you know for sure thats you're programming with the use of an authorized user you should leave this and just handle the NotAuthorizedExeption whenever thrown.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $scope | the scope, a relative uri. |
Returns: bool
Throws:
Gogs\Lib\Curl\Clientpublic static function get_log();
Returns log entries for the client.
Returns: array
Gogs\Lib\Curl\ExceptionDefines an unexpected response.
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | Sets the exceptions. | |
| __toString | string | public | Visual representation of the exception. |
| getResponse | string | public | Get the actual response from the body or the request. |
Gogs\Lib\Curl\Exception\HTTPUnexpectedResponsepublic function __construct(string $message, int $code, Exception $previous = null);
Sets the exceptions.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $message | None |
| int | $code | None |
| Exception | $previous | None |
Gogs\Lib\Curl\Exception\HTTPUnexpectedResponsepublic function __toString();
Visual representation of the exception.
Returns: string
Gogs\Lib\Curl\Exception\HTTPUnexpectedResponsepublic function getResponse();
Get the actual response from the body or the request.
Returns: string
Gogs\Lib\Curl\ExceptionWhen the request fails because of an unauthorized token, this is thrown instead.
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | Sets the exceptions. |
Gogs\Lib\Curl\Exception\NotAuthorizedExceptionpublic function __construct(string $message, int $code = 401, Exception $previous = null);
Sets the exceptions.
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $message | None |
| int | $code | None |
| Exception | $previous | None |