@@ -181,96 +181,6 @@ public function get(
181181 return $ this ->performRequest ($ curlSession , $ deserializationType );
182182 }
183183
184- /**
185- * Performs a PUT operation (i.e. an update) on a resource.
186- *
187- * @param string $resourcePath the path of the resource to PUT
188- * @param string $payload the payload data to PUT, i.e. the data to update the current state of the resource with
189- * @param array $queryParameters any additional query parameters
190- * @param string $mimeType the acceptable response MIME type
191- * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' )
192- * to deserialize arrays of a type.
193- *
194- * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
195- *
196- * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
197- */
198- public function put (
199- $ resourcePath ,
200- $ payload = '' ,
201- $ queryParameters = [],
202- $ mimeType = 'application/vnd.maileon.api+xml ' ,
203- $ deserializationType = null
204- ) {
205- $ curlSession = $ this ->prepareSession ($ resourcePath , $ queryParameters , $ mimeType );
206-
207- /*
208- * PUT does not work as expected when passing post data, see
209- * http://developers.sugarcrm.com/wordpress/2011/11/22/howto-do-put-requests-with-php-curl-without-writing-to-a-file/
210- * Because of this, we use a custom request here.
211- */
212- curl_setopt ($ curlSession , CURLOPT_CUSTOMREQUEST , 'PUT ' );
213- curl_setopt ($ curlSession , CURLOPT_POSTFIELDS , $ payload );
214-
215- return $ this ->performRequest ($ curlSession , $ deserializationType );
216- }
217-
218- /**
219- * Performs a POST operation (i.e. creates a new instance) on a resource.
220- *
221- * @param string $resourcePath the path of the resource to POST. This is typically the parent (or owner) resource of the resource
222- * instance to create.
223- * @param string $payload the data to POST, i.e. the contents of the new resource instance
224- * @param array $queryParameters any additional query parameters
225- * @param string $mimeType the acceptable response MIME type
226- * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) to
227- * deserialize arrays of a type.
228- *
229- * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
230- *
231- * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
232- */
233- public function post (
234- $ resourcePath ,
235- $ payload = '' ,
236- $ queryParameters = [],
237- $ mimeType = 'application/vnd.maileon.api+xml ' ,
238- $ deserializationType = null ,
239- $ contentType = null ,
240- $ contentLength = null
241- ) {
242- $ curlSession = $ this ->prepareSession ($ resourcePath , $ queryParameters , $ mimeType , $ contentType , $ contentLength );
243- curl_setopt ($ curlSession , CURLOPT_POST , true );
244- curl_setopt ($ curlSession , CURLOPT_POSTFIELDS , $ payload );
245-
246- return $ this ->performRequest ($ curlSession , $ deserializationType );
247- }
248-
249- /**
250- * Performs a DELETE operation on a resource.
251- *
252- * @param string $resourcePath the resource to DELETE
253- * @param array $queryParameters any additional query parameters
254- * @param string $mimeType the acceptable response MIME type
255- * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) to
256- * deserialize arrays of a type.
257- *
258- * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
259- *
260- * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
261- */
262- public function delete (
263- $ resourcePath ,
264- $ queryParameters = [],
265- $ mimeType = 'application/vnd.maileon.api+xml ' ,
266- $ deserializationType = null
267- ) {
268- $ curlSession = $ this ->prepareSession ($ resourcePath , $ queryParameters , $ mimeType );
269- curl_setopt ($ curlSession , CURLOPT_CUSTOMREQUEST , 'DELETE ' );
270-
271- return $ this ->performRequest ($ curlSession , $ deserializationType );
272- }
273-
274184 /**
275185 * @param $resourcePath
276186 * @param $queryParameters
@@ -422,30 +332,6 @@ private function performRequest(
422332 }
423333 }
424334
425- protected function appendArrayFields (
426- $ params ,
427- $ name ,
428- $ fieldValues
429- ) {
430- if (is_array ($ fieldValues ) && ! empty ($ fieldValues )) {
431- $ params [(string ) $ name ] = [];
432-
433- foreach ($ fieldValues as $ value ) {
434- if ($ value === true ) {
435- $ params [(string ) $ name ] [] = 'true ' ;
436- } elseif ($ value === false ) {
437- $ params [(string ) $ name ] [] = 'false ' ;
438- } elseif ($ value instanceof PreferenceCategory) {
439- $ params [$ name ] = urlencode ((string ) $ value ->name );
440- } else {
441- $ params [(string ) $ name ] [] = urlencode ($ value );
442- }
443- }
444- }
445-
446- return $ params ;
447- }
448-
449335 private function printDebugInformation (
450336 $ curlSession ,
451337 $ result = null ,
@@ -506,4 +392,118 @@ private function printDebugInformation(
506392 $ this ->verboseOut = null ;
507393 }
508394 }
395+
396+ /**
397+ * Performs a PUT operation (i.e. an update) on a resource.
398+ *
399+ * @param string $resourcePath the path of the resource to PUT
400+ * @param string $payload the payload data to PUT, i.e. the data to update the current state of the resource with
401+ * @param array $queryParameters any additional query parameters
402+ * @param string $mimeType the acceptable response MIME type
403+ * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' )
404+ * to deserialize arrays of a type.
405+ *
406+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
407+ *
408+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
409+ */
410+ public function put (
411+ $ resourcePath ,
412+ $ payload = '' ,
413+ $ queryParameters = [],
414+ $ mimeType = 'application/vnd.maileon.api+xml ' ,
415+ $ deserializationType = null
416+ ) {
417+ $ curlSession = $ this ->prepareSession ($ resourcePath , $ queryParameters , $ mimeType );
418+
419+ /*
420+ * PUT does not work as expected when passing post data, see
421+ * http://developers.sugarcrm.com/wordpress/2011/11/22/howto-do-put-requests-with-php-curl-without-writing-to-a-file/
422+ * Because of this, we use a custom request here.
423+ */
424+ curl_setopt ($ curlSession , CURLOPT_CUSTOMREQUEST , 'PUT ' );
425+ curl_setopt ($ curlSession , CURLOPT_POSTFIELDS , $ payload );
426+
427+ return $ this ->performRequest ($ curlSession , $ deserializationType );
428+ }
429+
430+ /**
431+ * Performs a POST operation (i.e. creates a new instance) on a resource.
432+ *
433+ * @param string $resourcePath the path of the resource to POST. This is typically the parent (or owner) resource of the resource
434+ * instance to create.
435+ * @param string $payload the data to POST, i.e. the contents of the new resource instance
436+ * @param array $queryParameters any additional query parameters
437+ * @param string $mimeType the acceptable response MIME type
438+ * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) to
439+ * deserialize arrays of a type.
440+ *
441+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
442+ *
443+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
444+ */
445+ public function post (
446+ $ resourcePath ,
447+ $ payload = '' ,
448+ $ queryParameters = [],
449+ $ mimeType = 'application/vnd.maileon.api+xml ' ,
450+ $ deserializationType = null ,
451+ $ contentType = null ,
452+ $ contentLength = null
453+ ) {
454+ $ curlSession = $ this ->prepareSession ($ resourcePath , $ queryParameters , $ mimeType , $ contentType , $ contentLength );
455+ curl_setopt ($ curlSession , CURLOPT_POST , true );
456+ curl_setopt ($ curlSession , CURLOPT_POSTFIELDS , $ payload );
457+
458+ return $ this ->performRequest ($ curlSession , $ deserializationType );
459+ }
460+
461+ /**
462+ * Performs a DELETE operation on a resource.
463+ *
464+ * @param string $resourcePath the resource to DELETE
465+ * @param array $queryParameters any additional query parameters
466+ * @param string $mimeType the acceptable response MIME type
467+ * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) to
468+ * deserialize arrays of a type.
469+ *
470+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
471+ *
472+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
473+ */
474+ public function delete (
475+ $ resourcePath ,
476+ $ queryParameters = [],
477+ $ mimeType = 'application/vnd.maileon.api+xml ' ,
478+ $ deserializationType = null
479+ ) {
480+ $ curlSession = $ this ->prepareSession ($ resourcePath , $ queryParameters , $ mimeType );
481+ curl_setopt ($ curlSession , CURLOPT_CUSTOMREQUEST , 'DELETE ' );
482+
483+ return $ this ->performRequest ($ curlSession , $ deserializationType );
484+ }
485+
486+ protected function appendArrayFields (
487+ $ params ,
488+ $ name ,
489+ $ fieldValues
490+ ) {
491+ if (is_array ($ fieldValues ) && ! empty ($ fieldValues )) {
492+ $ params [(string ) $ name ] = [];
493+
494+ foreach ($ fieldValues as $ value ) {
495+ if ($ value === true ) {
496+ $ params [(string ) $ name ] [] = 'true ' ;
497+ } elseif ($ value === false ) {
498+ $ params [(string ) $ name ] [] = 'false ' ;
499+ } elseif ($ value instanceof PreferenceCategory) {
500+ $ params [$ name ] = urlencode ((string ) $ value ->name );
501+ } else {
502+ $ params [(string ) $ name ] [] = urlencode ($ value );
503+ }
504+ }
505+ }
506+
507+ return $ params ;
508+ }
509509}
0 commit comments