Skip to content

Commit

Permalink
Merge pull request #4 from dereuromark/assoc-array
Browse files Browse the repository at this point in the history
Consistent API return as assoc array
  • Loading branch information
dereuromark authored Oct 6, 2022
2 parents bb3b31d + bd46f73 commit 369758e
Show file tree
Hide file tree
Showing 12 changed files with 838 additions and 31 deletions.
58 changes: 29 additions & 29 deletions src/Jira/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ protected function clearLocalCaches() {
/**
* Get fields definitions.
*
* @return array
* @return array|null
*/
public function getFields() {
// Fetch fields when the method is called for the first time.
if ($this->fields === null) {
$fields = [];
$result = $this->api(static::REQUEST_GET, '/rest/api/2/field', [], true);
$result = $this->api(static::REQUEST_GET, '/rest/api/2/field');

/* set hash key as custom field id */
foreach ($result as $field) {
Expand Down Expand Up @@ -254,7 +254,7 @@ public function deleteIssue($issueKey, bool $deleteSubtasks = true, array $param
/**
* Gets attachments meta information.
*
* @return array
* @return array|false
*/
public function getAttachmentsMetaInformation() {
return $this->api(static::REQUEST_GET, '/rest/api/2/attachment/meta');
Expand All @@ -268,7 +268,7 @@ public function getAttachmentsMetaInformation() {
* @return array|false
*/
public function getAttachment($attachment_id) {
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/attachment/%s', $attachment_id), [], true);
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/attachment/%s', $attachment_id));
}

/**
Expand All @@ -283,37 +283,37 @@ public function getProjects() {
/**
* Returns one project.
*
* @param string $project_key Project key.
* @param string $projectKey Project ID or key.
*
* @return array|false
*/
public function getProject($project_key) {
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s', $project_key), [], true);
public function getProject($projectKey) {
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s', $projectKey));
}

/**
* Returns all roles of a project.
*
* @param string $project_key Project key.
* @param string $projectKey Project ID or key.
*
* @return array|false
*/
public function getRoles($project_key) {
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/role', $project_key), [], true);
public function getRoles($projectKey) {
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/role', $projectKey));
}

/**
* Returns role details.
*
* @param string $project_key Project key.
* @param string $role_id Role ID.
* @param string $projectKey Project key.
* @param string $roleId Role ID.
*
* @return array|false
*/
public function getRoleDetails($project_key, $role_id) {
public function getRoleDetails($projectKey, $roleId) {
return $this->api(
static::REQUEST_GET,
sprintf('/rest/api/2/project/%s/role/%s', $project_key, $role_id),
sprintf('/rest/api/2/project/%s/role/%s', $projectKey, $roleId),
[],
true,
);
Expand All @@ -322,7 +322,7 @@ public function getRoleDetails($project_key, $role_id) {
/**
* Returns the meta data for creating issues.
* This includes the available projects, issue types
* and fields, including field types and whether or not those fields are required.
* and fields, including field types and whether those fields are required.
* Projects will not be returned if the user does not have permission to create issues in that project.
* Fields will only be returned if "projects.issuetypes.fields" is added as expand parameter.
*
Expand Down Expand Up @@ -472,7 +472,7 @@ public function transition($issueKey, array $params = []) {
*/
public function getIssueTypes() {
$result = [];
$types = $this->api(static::REQUEST_GET, '/rest/api/2/issuetype', [], true);
$types = $this->api(static::REQUEST_GET, '/rest/api/2/issuetype');

foreach ($types as $type) {
$result[] = new IssueType($type);
Expand All @@ -489,7 +489,7 @@ public function getIssueTypes() {
* @return array|false
*/
public function getVersions($project_key) {
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/versions', $project_key), [], true);
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/versions', $project_key));
}

/**
Expand Down Expand Up @@ -521,13 +521,13 @@ public function findVersionByName($project_key, $name) {
/**
* Get available priorities.
*
* @return array
* @return array|false
*/
public function getPriorities() {
// Fetch priorities when the method is called for the first time.
if ($this->priorities === null) {
$priorities = [];
$result = $this->api(static::REQUEST_GET, '/rest/api/2/priority', [], true);
$result = $this->api(static::REQUEST_GET, '/rest/api/2/priority');

/* set hash key as custom field id */
foreach ($result as $priority) {
Expand All @@ -549,7 +549,7 @@ public function getStatuses() {
// Fetch statuses when the method is called for the first time.
if ($this->statuses === null) {
$statuses = [];
$result = $this->api(static::REQUEST_GET, '/rest/api/2/status', [], true);
$result = $this->api(static::REQUEST_GET, '/rest/api/2/status');

/* set hash key as custom field id */
foreach ($result as $status) {
Expand Down Expand Up @@ -643,7 +643,7 @@ public function createVersion($projectKey, $version, array $options = []) {
* @param int $version_id Version ID.
* @param array $params Key->Value list to update the version with.
*
* @return false
* @return array|false
*/
public function updateVersion($version_id, array $params = []) {
return $this->api(static::REQUEST_PUT, sprintf('/rest/api/2/version/%d', $version_id), $params);
Expand Down Expand Up @@ -690,7 +690,7 @@ public function createAttachment($issueKey, $filename, $name = null) {
static::REQUEST_POST,
sprintf('/rest/api/2/issue/%s/attachments', $issueKey),
$options,
false,
true,
true,
);
}
Expand Down Expand Up @@ -742,7 +742,7 @@ public function api(
$method,
$url,
$data = [],
$return_as_array = false,
$return_as_array = true,
$is_file = false,
$debug = false
) {
Expand Down Expand Up @@ -884,33 +884,33 @@ public function closeIssue($issueKey) {
*
* @param string $project_key Project key.
*
* @return array
* @return array|false
*/
public function getProjectComponents($project_key) {
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/components', $project_key), [], true);
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/components', $project_key));
}

/**
* Get all issue types with valid status values for a project.
*
* @param string $project_key Project key.
*
* @return array
* @return array|false
*/
public function getProjectIssueTypes($project_key) {
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/statuses', $project_key), [], true);
return $this->api(static::REQUEST_GET, sprintf('/rest/api/2/project/%s/statuses', $project_key));
}

/**
* Returns a list of all resolutions.
*
* @return array
* @return array|false
*/
public function getResolutions() {
// Fetch resolutions when the method is called for the first time.
if ($this->resolutions === null) {
$resolutions = [];
$result = $this->api(static::REQUEST_GET, '/rest/api/2/resolution', [], true);
$result = $this->api(static::REQUEST_GET, '/rest/api/2/resolution');

foreach ($result as $resolution) {
$resolutions[$resolution['id']] = $resolution;
Expand Down
Loading

0 comments on commit 369758e

Please sign in to comment.