/**
  *
  * Uploads given file as an attachment for specified bug.
  *
  * Please note that this function utilizes @ prefixed file upload identifiers for PHP 5.4 compatibility.
  * While PHP 5.5 accepts this (E_WARNING), consider upgrading to CurlFile for PHP >= 5.6 compatibility.
  *
  * @param string $filepath an absolute path of the file to be uploaded (mandatory realpath format)
  *                         example: /home/path/to/file.txt (Linux), C:\Users\Documents\file.txt (Windows)
  *
  * @throws SDKInvalidArgException if $filepath is not a string
  *
  * @return BugAttachment the newly uploaded attachment
  *
  */
 public function upload($filepath)
 {
     if (!is_string($filepath)) {
         throw new SDKInvalidArgException('`$filepath` must be of type string');
     }
     $req = new APIRequest($this->origin, '/v1/bugs/' . $this->bug_id . '/attachments', 'POST', ['form_data' => true, 'params' => ['file' => $this->getCurlFile($filepath)]]);
     return new BugAttachment($this->origin, $req->exec());
 }
 public function create($fields)
 {
     parent::create($fields);
     $supports = ['number' => REQUIRED];
     if ($this->enforce($fields, $supports)) {
         $req = new APIRequest($this->origin, '/v1/projects/' . $this->project_id . '/versions', 'POST', ['params' => $fields]);
         return new ProjectVersion($this->origin, $req->exec());
     }
 }
 public function update($id, $fields)
 {
     parent::update($id, $fields);
     $supports = ['title' => OPTIONAL, 'status_id' => OPTIONAL, 'severity_id' => OPTIONAL, 'project_version_id' => OPTIONAL, 'project_section_id' => OPTIONAL, 'type_id' => OPTIONAL, 'assigned_user_id' => OPTIONAL, 'description' => OPTIONAL, 'expected_results' => OPTIONAL, 'steps' => OPTIONAL, 'platform' => OPTIONAL];
     if ($this->enforce($fields, $supports)) {
         $fields = array_merge(['include' => 'steps,platform'], $fields);
         $req = new APIRequest($this->origin, '/v1/bugs/' . $id, 'PUT', ['params' => $fields]);
         return new Bug($this->origin, $req->exec());
     }
 }
 public function create($fields)
 {
     parent::create($fields);
     $supports = ['title' => REQUIRED, 'status_id' => REQUIRED, 'severity_id' => REQUIRED, 'project_version' => REQUIRED, 'project_version_id' => REQUIRED, 'project_section_id' => OPTIONAL, 'type_id' => OPTIONAL, 'reproducibility_id' => OPTIONAL, 'assigned_user_id' => OPTIONAL, 'description' => OPTIONAL, 'expected_results' => OPTIONAL, 'steps' => OPTIONAL, 'platform' => OPTIONAL];
     if (array_key_exists('project_version_id', $fields)) {
         $supports['project_version'] = OPTIONAL;
     } elseif (array_key_exists('project_version', $fields)) {
         $supports['project_version_id'] = OPTIONAL;
     }
     if ($this->enforce($fields, $supports)) {
         $fields = array_merge(['include' => 'steps,platform'], $fields);
         $req = new APIRequest($this->origin, '/v1/projects/' . $this->project_id . '/bugs', 'POST', ['params' => $fields]);
         return new Bug($this->origin, $req->exec());
     }
 }
 public function find($id)
 {
     parent::find($id);
     $req = new APIRequest($this->origin, '/v1/platform/os/' . $id, 'GET', ['params' => ['include' => 'versions']]);
     return new PlatformOS($this->origin, $req->exec());
 }
 public function find($id)
 {
     parent::find($id);
     $req = new APIRequest($this->origin, '/v1/platform/devices/' . $id, 'GET');
     return new PlatformDevice($this->origin, $req->exec());
 }
 public function delete($id)
 {
     parent::delete($id);
     $req = new APIRequest($this->origin, '/v1/attachments/' . $id, 'DELETE');
     return $req->exec();
 }
 public function find($id)
 {
     parent::find($id);
     $req = new APIRequest($this->origin, '/v1/projects/' . $id, 'GET');
     return new Project($this->origin, $req->exec());
 }
 /**
  *
  * Generates an access token string from the provided authorization code
  *
  * @param string $client_id     client ID given at application registration
  * @param string $client_secret client secret given at application registration
  * @param string $grant_type    oauth specific grant_type value (i.e.: authorization_code)
  * @param string $code          authorization code obtained from the generated auth link
  * @param string $redirect_uri  URL to be redirected to after authorization
  *
  * @throws SDKInvalidArgException if provided $client_id param is not a string
  * @throws SDKInvalidArgException if provided $client_secret param is not a string
  * @throws SDKInvalidArgException if provided $grant_type param is not a string
  * @throws SDKInvalidArgException if provided $code param is not a string
  * @throws SDKInvalidArgException if provided $redirect_uri param is not a string
  *
  * @return string returns obtained access token string
  *
  */
 public function exchangeAuthCode($client_id, $client_secret, $grant_type, $code, $redirect_uri)
 {
     if (!is_string($client_id)) {
         throw new SDKInvalidArgException('`$client_id` must be a string');
     } elseif (!is_string($client_secret)) {
         throw new SDKInvalidArgException('`$client_secret` must be a string');
     } elseif (!is_string($grant_type)) {
         throw new SDKInvalidArgException('`$grant_type` must be a string');
     } elseif (!is_string($code)) {
         throw new SDKInvalidArgException('`$code` must be a string');
     } elseif (!is_string($redirect_uri)) {
         throw new SDKInvalidArgException('`$redirect_uri` must be a string');
     }
     $params = ['grant_type' => $grant_type, 'client_id' => $client_id, 'client_secret' => $client_secret, 'redirect_uri' => $redirect_uri, 'code' => $code];
     $req = new APIRequest($this->origin, '/login/oauth/access_token', 'POST', ['base_uri' => 'https://leantesting.com', 'params' => $params]);
     $resp = $req->exec();
     return $resp['access_token'];
 }