From 75614bf29411fa2d6ee69f86dee243a9c03ce32e Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 19 Jul 2016 14:58:31 +0200 Subject: [PATCH 1/3] Build a string query form array Fix issue #122 --- src/Mailgun/Connection/RestClient.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index 1cdc2ee..a89884f 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -62,7 +62,7 @@ class RestClient /** * @param string $method * @param string $uri - * @param array $body + * @param mixed $body * @param array $files * @param array $headers * @@ -81,6 +81,8 @@ class RestClient if (!empty($files)) { $body = new MultipartStream($files); $headers['Content-Type'] = 'multipart/form-data; boundary='.$body->getBoundary(); + } elseif (is_array($body)) { + $body = http_build_query($body); } $request = new Request($method, $this->getApiUrl($uri), $headers, $body); @@ -101,7 +103,7 @@ class RestClient * @throws MissingEndpoint * @throws MissingRequiredParameters */ - public function post($endpointUrl, $postData = array(), $files = array()) + public function post($endpointUrl, array $postData = array(), $files = array()) { $postFiles = []; @@ -171,7 +173,7 @@ class RestClient /** * @param string $endpointUrl - * @param array $putData + * @param mixed $putData * * @return \stdClass * From 1cdfc3c204827b2d5ab1f4ee01dbae50bc78f831 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 19 Jul 2016 15:00:29 +0200 Subject: [PATCH 2/3] Added header --- src/Mailgun/Connection/RestClient.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index a89884f..d0f851a 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -83,6 +83,7 @@ class RestClient $headers['Content-Type'] = 'multipart/form-data; boundary='.$body->getBoundary(); } elseif (is_array($body)) { $body = http_build_query($body); + $headers['Content-Type'] = 'application/x-www-form-urlencoded'; } $request = new Request($method, $this->getApiUrl($uri), $headers, $body); From aaf61b4466446c46758ec6cc7601052f28b44de7 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 19 Jul 2016 15:06:49 +0200 Subject: [PATCH 3/3] test fix --- tests/Mailgun/Tests/Mock/Connection/TestBroker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Mailgun/Tests/Mock/Connection/TestBroker.php b/tests/Mailgun/Tests/Mock/Connection/TestBroker.php index 6652aa5..b1dee7e 100644 --- a/tests/Mailgun/Tests/Mock/Connection/TestBroker.php +++ b/tests/Mailgun/Tests/Mock/Connection/TestBroker.php @@ -19,7 +19,7 @@ class TestBroker extends RestClient $this->apiEndpoint = $apiHost; } - public function post($endpointUrl, $postData = array(), $files = array()) + public function post($endpointUrl, array $postData = array(), $files = array()) { return $this->testResponseHandler($endpointUrl, $httpResponseCode = 200); }