1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace Gogs\API\Request {
- /**
- * 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.
- *
- * @author Joachim M. Giaever (joachim[]giaever.org)
- * @version 0.1.2
- */
- final class Token extends Base {
- const VERSION = "0.1.1";
- protected $owner;
- public $token_name;
- public $token_sha1;
-
- public function __construct(string $api_url, string $password, User $user) {
- parent::__construct($api_url, $password);
- if (!$user->email)
- $user->load();
- $this->basic($user->email);
- $this->owner = $user;
- }
-
- protected function set_scope(string $method) {
- switch ($method) {
- case "create":
- $this->scope = sprintf("/users/%s/tokens", $this->owner->username);
- return true;
- }
- return false;
- }
-
- public function create(...$args) {
- $params = array();
- $this->set_param($params, "name", $args, 0, "string", null);
- $this->filter_params($params);
- return parent::create($params);
- }
- }
- }
|