From c925659959fe026942659939f7a78239a707b36e Mon Sep 17 00:00:00 2001 From: Ricardo Perez Date: Fri, 15 Aug 2014 13:25:23 -0500 Subject: [PATCH] Added PHP version requirement to package definition Added throw exception when API body is empty Added support for files API attachments --- ActiveCollab/Connectors/Curl.php | 13 ++++++++++--- composer.json | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ActiveCollab/Connectors/Curl.php b/ActiveCollab/Connectors/Curl.php index 8969e2d..64ee600 100644 --- a/ActiveCollab/Connectors/Curl.php +++ b/ActiveCollab/Connectors/Curl.php @@ -41,9 +41,14 @@ function post($url, $post_data = null, $files = null) { $counter = 1; - foreach($files as $file) { - $post_data['attachment_' . $counter++] = '@' . $file . ';type=application/octet-stream'; - } // foreach + // Support for "File" API endpoint. This endpoint is expecting a single attachment on the request... + if( count( $files ) == 1 ){ + $post_data['attachment'] = '@' . $files['attachment_1'] . ';type=application/octet-stream'; + } else { + foreach($files as $file) { + $post_data['attachment_' . $counter++] = '@' . $file . ';type=application/octet-stream'; + } // foreach + } // if } // if curl_setopt($http, CURLOPT_POST, 1); @@ -103,6 +108,8 @@ private function execute(&$http) { case 503: if(is_string($result) && substr($result, 0, 1) === '{') { throw new AppException($status, $result); // Known application exception + } else { + throw new AppException($status); // API not always returns JSON body } // if } // switch diff --git a/composer.json b/composer.json index 753db05..58e60d3 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ } ], "require": { - + "php": ">=5.3.0" }, "autoload": { "psr-0": {