Browse Source

Updated read me / documentation

Joachim M. Giæver 6 years ago
parent
commit
ebe479cf28
1 changed files with 287 additions and 2 deletions
  1. 287 2
      README.md

+ 287 - 2
README.md

@@ -20,8 +20,10 @@ Gogs PHP API Client
 			8. [Repo](#repo-gogsapirequest "Gogs\API\Request\Repo") Stores data and methods related to a single repository.
 			9. [Repos](#repos-gogsapirequest "Gogs\API\Request\Repos") Repos is a collection of repos.
 			10. [RequestInterface](#requestinterface-gogsapirequest "Gogs\API\Request\RequestInterface") Request interface, used by any kind of request object.
-			11. [User](#user-gogsapirequest "Gogs\API\Request\User") Stores user data and methods related to a single user.
-			12. [Users](#users-gogsapirequest "Gogs\API\Request\Users") Returns one or more users in the Gogs installation,depending on the called method.
+			11. [Token](#token-gogsapirequest "Gogs\API\Request\Token") A token related to a user
+			12. [Tokens](#tokens-gogsapirequest "Gogs\API\Request\Tokens") Collection of tokens for a given user.
+			13. [User](#user-gogsapirequest "Gogs\API\Request\User") Stores user data and methods related to a single user.
+			14. [Users](#users-gogsapirequest "Gogs\API\Request\Users") Returns one or more users in the Gogs installation,depending on the called method.
 		2. [Client](#client-gogsapi "Gogs\API\Client") Gogs API client.
 	2. [Lib](#gogslib "Gogs\Lib")
 		1. [Curl](#gogslibcurl "Gogs\Lib\Curl")
@@ -1686,6 +1688,259 @@ Returns: array
 ---
 
 
+### Token `Gogs\API\Request`
+
+
+* Class extends [Gogs\API\Request\Base](#base-gogsapirequest)
+* Class implements[Gogs\API\Request\RequestInterface](#requestinterface-gogsapirequest)
+
+A token related to a user
+
+Supports:
+ * POST `/users/{username}/tokens`
+
+Note! Tokens doesnt have a "GET" method. @see Tokens
+as this can load them.
+
+#### Methods
+
+|Name                                           |Return|Access   |Description         |
+|:---                                           |:---  |:---     |:---                |
+|[__construct](#__construct-gogsapirequesttoken)|      |public   | Initializes a token|
+|[set_scope](#set_scope-gogsapirequesttoken)    |bool  |protected|                    |
+|[create](#create-gogsapirequesttoken)          |bool  |public   | Create a new token|
+
+#### Method details
+
+##### __construct `Gogs\API\Request\Token`
+```php
+public 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|*None*             |
+|[User](#request-gogsapi)|$user     |*None*             |
+---
+
+
+##### set_scope `Gogs\API\Request\Token`
+```php
+protected function set_scope(string $method);
+```
+
+Parameters
+
+| Type | Variable | Description          |
+|---   |---       |---                   |
+|string|$method   |Method type, e.g "get"|
+
+Returns: bool
+
+---
+
+
+##### create `Gogs\API\Request\Token`
+```php
+public function create(... $args);
+```
+ Create a new token
+
+Valid parameters:
+
+ 1. name
+
+ This reflects the API v1 documentation.
+
+
+Parameters
+
+| Type                                                                              | Variable | Description                 |
+|---                                                                                |---       |---                          |
+|[...](http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list)|$args     |Arguments required by create.|
+
+Returns: bool
+
+---
+
+
+### Tokens `Gogs\API\Request`
+
+
+* Class extends [Gogs\API\Request\Collection](#collection-gogsapirequest)
+* Class implements
+	* [Gogs\Lib\ArrayIterator](#arrayiterator-gogslib)
+	* [Gogs\API\Request\RequestInterface](#requestinterface-gogsapirequest)
+
+Collection of tokens for a given user.
+
+Supports:
+ * GET `/users/{username}/tokens`
+
+#### Methods
+
+|Name                                            |Return                           |Access   |Description                    |
+|:---                                            |:---                             |:---     |:---                           |
+|[__construct](#__construct-gogsapirequesttokens)|                                 |public   | Initialize a token collection.|
+|[set_scope](#set_scope-gogsapirequesttokens)    |bool                             |protected|                               |
+|[create](#create-gogsapirequesttokens)          |bool                             |public   | Create a new token.           |
+|[add_object](#add_object-gogsapirequesttokens)  |array                            |protected|                               |
+|[get](#get-gogsapirequesttokens)                |object                           |public   | Return a token by name        |
+|[search](#search-gogsapirequesttokens)          |[true](#true-gogsapirequest)     |public   | Search for a token.           |
+|[sort_by](#sort_by-gogsapirequesttokens)        |[Collection](#collection-gogslib)|public   |                               |
+
+#### Method details
+
+##### __construct `Gogs\API\Request\Tokens`
+```php
+public 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|*None*             |
+|[User](#request-gogsapi)|$user     |*None*             |
+---
+
+
+##### set_scope `Gogs\API\Request\Tokens`
+```php
+protected function set_scope(string $method);
+```
+
+Parameters
+
+| Type | Variable | Description          |
+|---   |---       |---                   |
+|string|$method   |Method type, e.g "get"|
+
+Returns: bool
+
+---
+
+
+##### create `Gogs\API\Request\Tokens`
+```php
+public 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                 |
+|---                                                                                |---       |---                          |
+|[...](http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list)|$args     |Arguments required by create.|
+
+Returns: bool
+
+---
+
+
+##### add_object `Gogs\API\Request\Tokens`
+```php
+protected function add_object(iterable $obj);
+```
+
+Parameters
+
+| Type                                                                                                  | Variable | Description |
+|---                                                                                                    |---       |---          |
+|[iterable](http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.types)|$obj      |*None*       |
+
+Returns: array
+
+---
+
+
+##### get `Gogs\API\Request\Tokens`
+```php
+public function get(string $s);
+```
+ Return a token by name
+
+
+Parameters
+
+| Type | Variable | Description              |
+|---   |---       |---                       |
+|string|$s        |The idientifier to look up|
+
+Returns: object
+
+---
+
+
+##### search `Gogs\API\Request\Tokens`
+```php
+public function search(array $params = array(), bool $strict = false);
+```
+ Search for a token.
+
+Params can be an array of
+```php
+$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](#true-gogsapirequest)
+
+Throws: 
+
+* [SearchParamException](#searchparamexception-gogsapirequestexception "Exception: Gogs\API\Request\Exception\SearchParamException")
+
+---
+
+
+##### sort_by `Gogs\API\Request\Tokens`
+```php
+public function sort_by(int $flag = Collection::SORT_INDEX);
+```
+
+Parameters
+
+| Type | Variable | Description |
+|---   |---       |---          |
+|int   |$flag     |Sorting flag|
+
+Returns: [Collection](#collection-gogslib)
+
+---
+
+
 ### User `Gogs\API\Request`
 
 
@@ -1717,6 +1972,7 @@ A user can also list it's repos and organizations.
 |[organization](#organization-gogsapirequestuser)  |[Org](#org-gogsapirequest)    |public   | Return a single organization.                 |
 |[org](#org-gogsapirequestuser)                    |                              |public   |                                               |
 |[create](#create-gogsapirequestuser)              |bool                          |public   | Create a new user.                            |
+|[tokens](#tokens-gogsapirequestuser)              |                              |public   |                                               |
 
 #### Method details
 
@@ -1884,6 +2140,19 @@ Returns: bool
 ---
 
 
+##### tokens `Gogs\API\Request\User`
+```php
+public function tokens(string $password);
+```
+
+Parameters
+
+| Type | Variable | Description |
+|---   |---       |---          |
+|string|$password|*None*       |
+---
+
+
 ### Users `Gogs\API\Request`
 
 
@@ -2597,12 +2866,28 @@ A trait used for every class referencing the api-url and token.
 
 |Name                                       |Return|Access       |Description                                                                                                                                                                                                                                                                              |
 |:---                                       |:---  |:---         |:---                                                                                                                                                                                                                                                                                     |
+|[basic](#basic-gogslibcurlclient)          |      |public       | Basic sets the user for basic HTTP-authentication.                                                                                                                                                                                                                                      |
 |[method](#method-gogslibcurlclient)        |int   |protected    | Initializes a curl request of different kinds, dependingon the specified method. This can be                                                                                                                                                                                            |
 |[authorized](#authorized-gogslibcurlclient)|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](#get_log-gogslibcurlclient)      |array|public static| Returns log entries for the client.                                                                                                                                                                                                                                                     |
 
 #### Method details
 
+##### basic `Gogs\Lib\Curl\Client`
+```php
+public function basic(string $user);
+```
+ Basic sets the user for basic HTTP-authentication.
+
+
+Parameters
+
+| Type | Variable | Description |
+|---   |---       |---          |
+|string|$user     |*None*       |
+---
+
+
 ##### method `Gogs\Lib\Curl\Client`
 ```php
 protected function method(string $method, string $req, string $scope, array $params, bool $ret);