-
Notifications
You must be signed in to change notification settings - Fork 123
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
{ | ||
$query_string = "?"; | ||
foreach ($params as $key => $value) { | ||
$query_string .= "$key=$value&"; | ||
} | ||
return rtrim($query_string, "&"); | ||
} | ||
|
||
/** | ||
* Get fields definitions. | ||
* | ||
|
@@ -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); | ||
} | ||
|
||
/** | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
There was a problem hiding this comment.
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