-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from cmuench/components-endpoint
Add service to handle components
- Loading branch information
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
namespace JiraRestApi\Component; | ||
|
||
use JiraRestApi\JiraException; | ||
use JiraRestApi\Project\Component; | ||
|
||
class ComponentService extends \JiraRestApi\JiraClient | ||
{ | ||
private $uri = '/component'; | ||
|
||
/** | ||
* Function to create a new compoonent. | ||
* | ||
* @param Component|array $component | ||
* | ||
* @throws \JiraRestApi\JiraException | ||
* @throws \JsonMapper_Exception | ||
* | ||
* @return Component class | ||
*/ | ||
public function create($component) | ||
{ | ||
$data = json_encode($component); | ||
|
||
$this->log->info("Create Component=\n".$data); | ||
|
||
$ret = $this->exec($this->uri, $data, 'POST'); | ||
|
||
return $this->json_mapper->map( | ||
json_decode($ret), | ||
new Component() | ||
); | ||
} | ||
|
||
/** | ||
* get component. | ||
* | ||
* @param $id component id | ||
* | ||
* @return Component | ||
*/ | ||
public function get($id) | ||
{ | ||
$ret = $this->exec($this->uri.'/'.$id); | ||
|
||
$this->log->info('Result='.$ret); | ||
|
||
return $this->json_mapper->map( | ||
json_decode($ret), | ||
new Component() | ||
); | ||
} | ||
|
||
/** | ||
* @param Component $component | ||
* | ||
* @throws JiraException | ||
* | ||
* @return Component | ||
*/ | ||
public function update(Component $component) | ||
{ | ||
if (!$component->id || !is_numeric($component->id)) { | ||
throw new JiraException($component->id.' is not a valid component id.'); | ||
} | ||
|
||
$data = json_encode($component); | ||
$ret = $this->exec($this->uri.'/'.$component->id, $data, 'PUT'); | ||
|
||
return $this->json_mapper->map( | ||
json_decode($ret), | ||
new Component() | ||
); | ||
} | ||
|
||
/** | ||
* @param Component $component | ||
* @param Component|false $moveIssuesTo | ||
* | ||
* @throws JiraException | ||
* | ||
* @return bool | ||
*/ | ||
public function delete(Component $component, $moveIssuesTo = false) | ||
{ | ||
if (!$component->id || !is_numeric($component->id)) { | ||
throw new JiraException($component->id.' is not a valid component id.'); | ||
} | ||
|
||
$data = []; | ||
$paramArray = []; | ||
|
||
if ($moveIssuesTo && $moveIssuesTo instanceof Component) { | ||
$paramArray['moveIssuesTo'] = $moveIssuesTo->id; | ||
} | ||
|
||
$ret = $this->exec($this->uri.'/'.$component->id.$this->toHttpQueryParameter($paramArray), json_encode($data), 'DELETE'); | ||
|
||
return $ret; | ||
} | ||
} |