Skip to content

Commit e9f3dd4

Browse files
committed
Merge pull request kbsali#58 from nerdo/master
Added the ability to set the name of the header used for authentication ...
2 parents 428d365 + 5f189e5 commit e9f3dd4

File tree

12 files changed

+91
-36
lines changed

12 files changed

+91
-36
lines changed

lib/Redmine/Api/AbstractApi.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public function __construct(Client $client)
2626
$this->client = $client;
2727
}
2828

29+
/**
30+
* Returns whether or not the last api call failed.
31+
*
32+
* @return bool
33+
*/
34+
public function lastCallFailed() {
35+
$clientResponseCode = $this->client->getResponseCode();
36+
return $clientResponseCode < 200 || $clientResponseCode >= 400;
37+
}
38+
2939
/**
3040
* {@inheritDoc}
3141
*/

lib/Redmine/Api/Group.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function listing($forceUpdate = false)
5050
* @link http://www.redmine.org/projects/redmine/wiki/Rest_Groups#POST
5151
*
5252
* @param array $params the new group data
53-
* @return \SimpleXMLElement
53+
* @return SimpleXMLElement
5454
*/
5555
public function create(array $params = array())
5656
{
@@ -65,7 +65,7 @@ public function create(array $params = array())
6565
throw new \Exception('Missing mandatory parameters');
6666
}
6767

68-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><group></group>');
68+
$xml = new SimpleXMLElement('<?xml version="1.0"?><group></group>');
6969
foreach ($params as $k => $v) {
7070
$xml->addChild($k, $v);
7171
}
@@ -111,7 +111,7 @@ public function remove($id)
111111
*/
112112
public function addUser($id, $userId)
113113
{
114-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><user_id>'.$userId.'</user_id>');
114+
$xml = new SimpleXMLElement('<?xml version="1.0"?><user_id>'.$userId.'</user_id>');
115115

116116
return $this->post('/groups/'.$id.'/user/users.xml', $xml->asXML());
117117
}

lib/Redmine/Api/Issue.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public function show($id, array $params = array())
5656
/**
5757
* Build the XML for an issue
5858
* @param array $params for the new/updated issue data
59-
* @return \SimpleXMLElement
59+
* @return SimpleXMLElement
6060
*/
6161
private function buildXML(array $params = array())
6262
{
63-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><issue></issue>');
63+
$xml = new SimpleXMLElement('<?xml version="1.0"?><issue></issue>');
6464

6565
foreach ($params as $k => $v) {
6666
if ('custom_fields' === $k && is_array($v)) {
@@ -100,7 +100,7 @@ private function buildXML(array $params = array())
100100
* @link http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Creating-an-issue
101101
*
102102
* @param array $params the new issue data
103-
* @return \SimpleXMLElement
103+
* @return SimpleXMLElement
104104
*/
105105
public function create(array $params = array())
106106
{
@@ -142,7 +142,7 @@ public function create(array $params = array())
142142
*
143143
* @param string $id the issue number
144144
* @param array $params
145-
* @return \SimpleXMLElement
145+
* @return SimpleXMLElement
146146
*/
147147
public function update($id, array $params)
148148
{

lib/Redmine/Api/IssueCategory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function show($id)
8282
*
8383
* @param string|int $project project id or literal identifier
8484
* @param array $params the new issue category data
85-
* @return \SimpleXMLElement
85+
* @return SimpleXMLElement
8686
*/
8787
public function create($project, array $params = array())
8888
{
@@ -97,7 +97,7 @@ public function create($project, array $params = array())
9797
throw new \Exception('Missing mandatory parameters');
9898
}
9999

100-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><issue_category></issue_category>');
100+
$xml = new SimpleXMLElement('<?xml version="1.0"?><issue_category></issue_category>');
101101
foreach ($params as $k => $v) {
102102
$xml->addChild($k, $v);
103103
}
@@ -111,7 +111,7 @@ public function create($project, array $params = array())
111111
*
112112
* @param string $id the issue category id
113113
* @param array $params
114-
* @return \SimpleXMLElement
114+
* @return SimpleXMLElement
115115
*/
116116
public function update($id, array $params)
117117
{
@@ -121,7 +121,7 @@ public function update($id, array $params)
121121
);
122122
$params = array_filter(array_merge($defaults, $params));
123123

124-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><issue_category></issue_category>');
124+
$xml = new SimpleXMLElement('<?xml version="1.0"?><issue_category></issue_category>');
125125
foreach ($params as $k => $v) {
126126
$xml->addChild($k, $v);
127127
}

lib/Redmine/Api/Membership.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function all($project, array $params = array())
3333
*
3434
* @param string|int $project project id or literal identifier
3535
* @param array $params the new membership data
36-
* @return \SimpleXMLElement
36+
* @return SimpleXMLElement
3737
*/
3838
public function create($project, array $params = array())
3939
{
@@ -60,7 +60,7 @@ public function create($project, array $params = array())
6060
*
6161
* @param int $id id of the membership
6262
* @param array $params the new membership data
63-
* @return \SimpleXMLElement
63+
* @return SimpleXMLElement
6464
*/
6565
public function update($id, array $params = array())
6666
{
@@ -92,11 +92,11 @@ public function remove($id)
9292
/**
9393
* Build the XML for a membership
9494
* @param array $params for the new/updated membership data
95-
* @return \SimpleXMLElement
95+
* @return SimpleXMLElement
9696
*/
9797
private function buildXML(array $params = array())
9898
{
99-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><membership></membership>');
99+
$xml = new SimpleXMLElement('<?xml version="1.0"?><membership></membership>');
100100

101101
foreach ($params as $k => $v) {
102102
if ('role_ids' === $k && is_array($v)) {

lib/Redmine/Api/Project.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function show($id)
7979
*
8080
* @param array $params the new project data
8181
* @throws \Exception
82-
* @return \SimpleXMLElement
82+
* @return SimpleXMLElement
8383
*/
8484
public function create(array $params = array())
8585
{
@@ -101,7 +101,7 @@ public function create(array $params = array())
101101
throw new \Exception('Missing mandatory parameters');
102102
}
103103

104-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><project></project>');
104+
$xml = new SimpleXMLElement('<?xml version="1.0"?><project></project>');
105105
foreach ($params as $k => $v) {
106106
if ('tracker_ids' == $k && is_array($v)) {
107107
$trackers = $xml->addChild('tracker_ids', '');
@@ -123,7 +123,7 @@ public function create(array $params = array())
123123
*
124124
* @param string $id the project id
125125
* @param array $params
126-
* @return \SimpleXMLElement
126+
* @return SimpleXMLElement
127127
*/
128128
public function update($id, array $params)
129129
{
@@ -135,7 +135,7 @@ public function update($id, array $params)
135135
);
136136
$params = array_filter(array_merge($defaults, $params));
137137

138-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><project></project>');
138+
$xml = new SimpleXMLElement('<?xml version="1.0"?><project></project>');
139139
foreach ($params as $k => $v) {
140140
$xml->addChild($k, $v);
141141
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Redmine\Api;
4+
5+
class SimpleXMLElement extends \SimpleXMLElement {
6+
public function addChild() {
7+
$args = func_get_args();
8+
if (count($args) > 1 && is_string($args[1])) {
9+
// use the property assignment to set the text correctly
10+
$text = $args[1];
11+
$node = call_user_func_array(array('parent', 'addChild'), $args);
12+
$node->{0} = $text;
13+
} else {
14+
$node = call_user_func_array(array('parent', 'addChild'), $args);
15+
}
16+
17+
return $node;
18+
}
19+
}

lib/Redmine/Api/TimeEntry.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function show($id)
4242
* @link http://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries
4343
*
4444
* @param array $params the new time entry data
45-
* @return \SimpleXMLElement
45+
* @return SimpleXMLElement
4646
*/
4747
public function create(array $params = array())
4848
{
@@ -62,7 +62,7 @@ public function create(array $params = array())
6262
throw new \Exception('Missing mandatory parameters');
6363
}
6464

65-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><time_entry></time_entry>');
65+
$xml = new SimpleXMLElement('<?xml version="1.0"?><time_entry></time_entry>');
6666
foreach ($params as $k => $v) {
6767
$xml->addChild($k, $v);
6868
}
@@ -76,7 +76,7 @@ public function create(array $params = array())
7676
*
7777
* @param id $id
7878
* @param array $params
79-
* @return \SimpleXMLElement
79+
* @return SimpleXMLElement
8080
*/
8181
public function update($id, array $params)
8282
{
@@ -91,7 +91,7 @@ public function update($id, array $params)
9191
);
9292
$params = array_filter(array_merge($defaults, $params));
9393

94-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><time_entry></time_entry>');
94+
$xml = new SimpleXMLElement('<?xml version="1.0"?><time_entry></time_entry>');
9595
foreach ($params as $k => $v) {
9696
$xml->addChild($k, $v);
9797
}

lib/Redmine/Api/User.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function show($id)
8989
* @link http://www.redmine.org/projects/redmine/wiki/Rest_Users#POST
9090
*
9191
* @param array $params the new user data
92-
* @return \SimpleXMLElement
92+
* @return SimpleXMLElement
9393
*/
9494
public function create(array $params = array())
9595
{
@@ -111,7 +111,7 @@ public function create(array $params = array())
111111
throw new \Exception('Missing mandatory parameters');
112112
}
113113

114-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><user></user>');
114+
$xml = new SimpleXMLElement('<?xml version="1.0"?><user></user>');
115115
foreach ($params as $k => $v) {
116116
if ('custom_fields' === $k) {
117117
$this->attachCustomFieldXML($xml, $v);
@@ -129,7 +129,7 @@ public function create(array $params = array())
129129
*
130130
* @param string $id the user id
131131
* @param array $params
132-
* @return \SimpleXMLElement
132+
* @return SimpleXMLElement
133133
*/
134134
public function update($id, array $params)
135135
{
@@ -144,7 +144,7 @@ public function update($id, array $params)
144144
);
145145
$params = array_filter(array_merge($defaults, $params));
146146

147-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><user></user>');
147+
$xml = new SimpleXMLElement('<?xml version="1.0"?><user></user>');
148148
foreach ($params as $k => $v) {
149149
if ('custom_fields' === $k) {
150150
$this->attachCustomFieldXML($xml, $v);

lib/Redmine/Api/Version.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function show($id)
8383
*
8484
* @param string|int $project project id or literal identifier
8585
* @param array $params the new issue category data
86-
* @return \SimpleXMLElement
86+
* @return SimpleXMLElement
8787
*/
8888
public function create($project, array $params = array())
8989
{
@@ -103,7 +103,7 @@ public function create($project, array $params = array())
103103
$this->validateStatus($params);
104104
$this->validateSharing($params);
105105

106-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><version></version>');
106+
$xml = new SimpleXMLElement('<?xml version="1.0"?><version></version>');
107107
foreach ($params as $k => $v) {
108108
$xml->addChild($k, $v);
109109
}
@@ -117,7 +117,7 @@ public function create($project, array $params = array())
117117
*
118118
* @param string $id the issue category id
119119
* @param array $params
120-
* @return \SimpleXMLElement
120+
* @return SimpleXMLElement
121121
*/
122122
public function update($id, array $params)
123123
{
@@ -132,7 +132,7 @@ public function update($id, array $params)
132132
$this->validateStatus($params);
133133
$this->validateSharing($params);
134134

135-
$xml = new \SimpleXMLElement('<?xml version="1.0"?><version></version>');
135+
$xml = new SimpleXMLElement('<?xml version="1.0"?><version></version>');
136136
foreach ($params as $k => $v) {
137137
$xml->addChild($k, $v);
138138
}

0 commit comments

Comments
 (0)