Browse files

Merge pull request #14 from nuams/master

Minor changes to better support Redmine REST API
  • Loading branch information...
2 parents 892bb5b + 4446417 commit aeccf2fc6d49bfbe17bbeda4580593445ce012dc @jbroadway committed Jun 17, 2012
Showing with 11 additions and 11 deletions.
  1. +11 −11 ActiveResource.php
View
22 ActiveResource.php
@@ -251,7 +251,7 @@ function find ($id = false, $options = array ()) {
*/
function get ($method, $options = array ()) {
$req = $this->site . $this->element_name_plural;
- if ($this->_data['id']) {
+ if (isset($this->_data['id']) && $this->_data['id']) {
$req .= '/' . $this->_data['id'];
}
$req .= '/' . $method . '.xml';
@@ -266,26 +266,29 @@ function get ($method, $options = array ()) {
*
* POST /collection/id/method.xml
*/
- function post ($method, $options = array ()) {
+ function post ($method, $options = array (), $start_tag=FALSE) {
$req = $this->site . $this->element_name_plural;
if ($this->_data['id']) {
$req .= '/' . $this->_data['id'];
}
$req .= '/' . $method . '.xml';
- return $this->_send_and_receive ($req, 'POST', $options);
+ return $this->_send_and_receive ($req, 'POST', $options, $start_tag);
}
/**
* Puts to a specified custom method on the current object via:
*
* PUT /collection/id/method.xml
*/
- function put ($method, $options = array ()) {
+ function put ($method, $options = array (), $options_as_xml=FALSE, $start_tag=FALSE) {
$req = $this->site . $this->element_name_plural;
if ($this->_data['id']) {
$req .= '/' . $this->_data['id'];
}
$req .= '/' . $method . '.xml';
+ if ($options_as_xml) {
+ return $this->_send_and_receive ($req, 'PUT', $options, $start_tag);
+ }
if (count ($options) > 0) {
$req .= '?' . http_build_query ($options);
}
@@ -413,6 +416,7 @@ function _xml_entities ($s, $hex = true) {
// just return it
return $s;
}
+ $s = (string)$s;
// create the return string
$r = '';
@@ -424,7 +428,7 @@ function _xml_entities ($s, $hex = true) {
// get the value of the character
$o = $this->_unicode_ord($s, $i);
- // valid cahracters
+ // valid characters
$v = (
// \t \n <vertical tab> <form feed> \r
($o >= 9 && $o <= 13) ||
@@ -493,9 +497,9 @@ function _xml_entities ($s, $hex = true) {
/**
* Build the request, call _fetch() and parse the results.
*/
- function _send_and_receive ($url, $method, $data = array ()) {
+ function _send_and_receive ($url, $method, $data = array (), $start_tag=FALSE) {
$params = '';
- $el = $this->element_name; // Singular this time
+ $el = $start_tag ? $start_tag : $this->element_name; // Singular this time
if ($this->request_format == 'url') {
foreach ($data as $k => $v) {
if ($k != 'id' && $k != 'created-at' && $k != 'updated-at') {
@@ -512,18 +516,14 @@ function _send_and_receive ($url, $method, $data = array ()) {
}
$params .= '</' . $el . '>';
}
-
if ($this->extra_params !== false)
{
$url = $url . $this->extra_params;
}
-
$this->request_body = $params;
$this->request_uri = $url;
$this->request_method = $method;
-
$res = $this->_fetch ($url, $method, $params);
-
if ($res === false)
{
return $this;

0 comments on commit aeccf2f

Please sign in to comment.