Skip to content

update with upstream #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
v1.1.1:
- Issue 28 - Fix for Cloud Front returning 403 with an empty json object for the request content
v1.1.0:
- Added support for the following API endpoints:
/survey_languages
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A simple SurveyMonkey API wrapper for version 3 of their API.
Add the following to your composer.json under require:

"require": {
"ghassani/surveymonkey-v3-api-php": "1.1.0"
"ghassani/surveymonkey-v3-api-php": "1.*"
},

# Usage
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ghassani/surveymonkey-v3-api-php",
"version" : "1.1.0",
"version" : "1.1.2",
"authors": [
{
"name": "Gassan Idriss",
Expand Down
12 changes: 5 additions & 7 deletions src/Api/CollectorsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,10 @@ public function createCollectorMessage($collectorId, array $data = [])
public function copyCollectorMessage($collectorId, $fromCollectorId, $fromMessageId, $includeRecipients = false)
{
return $this->sendRequest(
$this->createRequest('POST', sprintf('collectors/%s/messages', $collectorId), [
'query' => [
'from_collector_id' => $fromCollectorId,
'from_message_id' => $fromMessageId,
'include_recipients' => (bool)$includeRecipients,
]
$this->createRequest('POST', sprintf('collectors/%s/messages', $collectorId), [], [
'from_collector_id' => (string)$fromCollectorId,
'from_message_id' => (string)$fromMessageId,
'include_recipients' => (bool)$includeRecipients,
])
);
}
Expand Down Expand Up @@ -265,7 +263,7 @@ public function deleteCollectorMessage($collectorId, $messageId)
*/
public function sendCollectorMessage($collectorId, $messageId, \DateTime $scheduledDate = null)
{
$data = $scheduledDate ? [ 'scheduled_date' => $scheduledDate->format(DATE_ATOM) ] : [];
$data = $scheduledDate ? [ 'scheduled_date' => $scheduledDate->format(DATE_ATOM) ] : new \stdClass();

return $this->sendRequest(
$this->createRequest('POST', sprintf('collectors/%s/messages/%s/send', $collectorId, $messageId), [], $data)
Expand Down
9 changes: 5 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ public function sendRequest(RequestInterface $request)
private function createRequest($method, $uri, array $options = [], $body = null)
{
if (empty($body)) {
// Empty arrays and NULL data inputs both need casting to an empty JSON object.
// See https://stackoverflow.com/a/41150809/2803757
$bodyString = '{}';
} elseif (is_array($body)) {
// Survey Monkey moved to CloudFront on 2020-05-23
// CloudFront issues 403 Forbidden with empty json body
// Previously this was set to an empty json object string. See https://stackoverflow.com/a/41150809/2803757
$bodyString = null;
} elseif (is_array($body) || $body instanceof \stdClass) {
$bodyString = json_encode($body);
}

Expand Down