| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 | 
							- <?php 
 
- namespace Gogs\API\Request {
 
-     /** 
 
-      * Stores data and methods related to a single organization.
 
-      *
 
-      * By now the following are supported:
 
-      *
 
-      *  * GET `/orgs/username`
 
-      *  * POST `/admin/users/username/orgs` (**Requires** admin rights. Curl will throw NotAuthorized exception if not).
 
-      *
 
-      * @author Joachim M. Giaever (joachim[]giaever.org)
 
-      * @version 0.1.1
 
-      */
 
-     final class Org extends User {
 
-         public $org_description;
 
-         public $org_website;
 
-         public $org_location;
 
-         private $owner;
 
-         /**
 
-          * Initialize an organization.
 
-          *
 
-          * @param string $api_url The api-url
 
-          * @param string $api_token The api-token
 
-          * @param User $owner The owner of the organization
 
-          * @param string $oname Organization name
 
-          */
 
-         public function __construct(string $api_url, string $api_token, User $owner = null, string $oname = null)  {
 
-             parent::__construct($api_url, $api_token);
 
-             $this->username = $oname;
 
-             $this->owner = $owner;
 
-         }
 
-         /** 
 
-          * @see Base
 
-          * @throws Exception\InvalidMethodRequestException when owner is not set
 
-          * @throws Exception\RequestErrorException when missing organization data
 
-          */
 
-         protected function set_scope(string $method) {
 
-             switch ($method) {
 
-             case "create":
 
-                 if ($this->owner == null)
 
-                     throw new Exception\InvalidMethodRequestException("Cant create organization without a related User");
 
-                 $this->scope = "/admin/users/" . $this->owner->username . "/orgs";
 
-                 return true;
 
-             case "get":
 
-                 if (!$this->username)
 
-                     throw new Exception\RequestErrorException("Missing organization-data 'username'.");
 
-                 $this->scope = "/orgs/" . $this->username;
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         /** 
 
-          * @see Base
 
-          */
 
-         public function search(string $q) {
 
-             $searchable = sprintf("%s %s %s", $this->full_name, $this->username, $this->description);
 
-             return stripos($searchable, $q) !== false;
 
-         }
 
-         /** 
 
-          * Create a new user
 
-          *
 
-          * Valid parameters:
 
-          *
 
-          *  1. username
 
-          *  2. full_name
 
-          *  3. description
 
-          *  4. website
 
-          *  5. location
 
-          *
 
-          *  This reflects the API v1 doc, but is in an order
 
-          *  where the required fields is first.
 
-          *
 
-          * @todo Create team within org with user
 
-          * @param ...$args The parameter values.
 
-          * @return  bool
 
-          */
 
-         public function create(...$args) {
 
-             $params = array(
 
-                 "username" => isset($args[0]) && is_string($args[0]) ? $args[0] : null,
 
-                 "full_name" => isset($args[1]) && is_string($args[1]) ? $args[1] : null,
 
-                 "description" => isset($args[2]) && is_string($args[2]) ? $args[2] : null,
 
-                 "website" => isset($args[3]) && is_string($args[3]) ? $args[3] : null,
 
-                 "location" => isset($args[4]) && is_string($args[4]) ? $args[4] : null
 
-             );
 
-             $params = array_filter($params, function($val) {
 
-                 return $val != null;
 
-             });
 
-             Base::create($params);
 
-         }
 
-     }
 
- }
 
- ?>
 
 
  |