chobie\Jira\Api::api PHP Method

api() public method

Send request to specified host.
public api ( string $method = self::REQUEST_GET, string $url, array | string $data = [], boolean $return_as_array = false, boolean $is_file = false, boolean $debug = false ) : array | Result | false
$method string Request method.
$url string URL.
$data array | string Data.
$return_as_array boolean Return results as associative array.
$is_file boolean Is file-related request.
$debug boolean Debug this request.
return array | chobie\Jira\Api\Result | false
    public function api($method = self::REQUEST_GET, $url, $data = array(), $return_as_array = false, $is_file = false, $debug = false)
    {
        $result = $this->client->sendRequest($method, $url, $data, $this->getEndpoint(), $this->authentication, $is_file, $debug);
        if (strlen($result)) {
            $json = json_decode($result, true);
            if ($this->options & self::AUTOMAP_FIELDS) {
                if (isset($json['issues'])) {
                    if (!count($this->fields)) {
                        $this->getFields();
                    }
                    foreach ($json['issues'] as $offset => $issue) {
                        $json['issues'][$offset] = $this->automapFields($issue);
                    }
                }
            }
            if ($return_as_array) {
                return $json;
            } else {
                return new Result($json);
            }
        } else {
            return false;
        }
    }

Usage Example

Example #1
0
 /**
  * Make API request
  *
  * @param string $method
  * @param string $url
  * @param array  $data
  * @param bool   $asJson
  * @param bool   $isFile
  * @param bool   $debug
  * @return JiraLib\Api\Result
  */
 public function api($method = Api::REQUEST_GET, $url = '', $data = array(), $asJson = false, $isFile = false, $debug = false)
 {
     $result = parent::api($method, $url, $data, true, $isFile, $debug);
     if ($result) {
         $this->processErrors($result);
         if (!$asJson) {
             $result = new Api\Result($result);
         }
     }
     return $result;
 }