Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API endpoint URL query string parameters #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 47 additions & 23 deletions src/Jira/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ protected function clearLocalCaches()
$this->resolutions = null;
}

/**
* Helper method to formulate a query string from supplied parameter array.
*
* @param $params Array of URL parameters: [key => value]
* @return string
*/
protected function formulateQueryString($params)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is PHP built-in function, that does it: http://php.net/manual/en/function.http-build-query.php

{
$query_string = "?";
foreach ($params as $key => $value) {
$query_string .= "$key=$value&";
}
return rtrim($query_string, "&");
}

/**
* Get fields definitions.
*
Expand Down Expand Up @@ -206,17 +221,20 @@ public function getIssue($issue_key, $expand = '')
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/issue/%s', $issue_key), array('expand' => $expand));
}

/**
* Edits the issue.
*
* @param string $issue_key Issue key.
* @param array $params Params.
*
* @return Result|false
*/
public function editIssue($issue_key, array $params)
/**
* Edits the issue.
*
* @param string $issue_key Issue key.
* @param array $params Params.
* @param array $query_params Optional URL query string parameters
*
* @return Result|false
* @internal param array $queryParams Query-string params
*
*/
public function editIssue($issue_key, array $params, array $query_params = array())
{
return $this->api(self::REQUEST_PUT, sprintf('/rest/api/2/issue/%s', $issue_key), $params);
return $this->api(self::REQUEST_PUT, sprintf('/rest/api/2/issue/%s', $issue_key), $params, null, null, null, $query_params);
}

/**
Expand Down Expand Up @@ -696,26 +714,32 @@ public function createRemotelink(
return $this->api(self::REQUEST_POST, sprintf('/rest/api/2/issue/%s/remotelink', $issue_key), $options, true);
}

/**
* Send request to specified host.
*
* @param string $method Request method.
* @param string $url URL.
* @param array|string $data Data.
* @param boolean $return_as_array Return results as associative array.
* @param boolean $is_file Is file-related request.
* @param boolean $debug Debug this request.
*
* @return array|Result|false
*/
/**
* Send request to specified host.
*
* @param string $method Request method.
* @param string $url URL.
* @param array|string $data Data.
* @param boolean $return_as_array Return results as associative array.
* @param boolean $is_file Is file-related request.
* @param boolean $debug Debug this request.
* @param array $url_params Optional parameters to add to the URL
*
* @return array|Result|false
*/
public function api(
$method = self::REQUEST_GET,
$url,
$data = array(),
$return_as_array = false,
$is_file = false,
$debug = false
$debug = false,
$url_params = array()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method already has too many params, so adding another one makes it a nightmare. Any other implementations you can suggest?

My options are:

  1. having special key in $data array that won't match any parameter of existing in JIRA API (not necessary implemented in this library) for passing query parameters
  2. use http_build_query directly on editIssue method and not add any parameters here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in the #222.

) {
if ($url_params) {
$url .= $this->formulateQueryString($url_params);
}

$result = $this->client->sendRequest(
$method,
$url,
Expand Down