Created
July 8, 2011 01:26
-
-
Save dmpatierno/1070917 to your computer and use it in GitHub Desktop.
Creates a new poll with the Doodle API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$api = new DoodleAPI(); | |
$api->createPoll(array( | |
'title' => 'Test Poll', | |
'description' => 'Test Description', | |
'fromName' => 'David Patierno', | |
'fromEmail' => '[email protected]', | |
'dates' => array( | |
'2011-07-08', | |
'2011-07-09', | |
'2011-07-10', | |
'2011-07-11' | |
) | |
)); | |
class DoodleAPI { | |
public function createPoll($options) { | |
$dates = ""; | |
foreach ($options['dates'] as $date) | |
$dates .= <<<EOT | |
<option date="{$date}" /> | |
EOT; | |
$xml = <<<EOT | |
<poll xmlns="http://doodle.com/xsd1"> | |
<type>DATE</type> | |
<hidden>false</hidden> | |
<levels>2</levels> | |
<title>{$options['title']}</title> | |
<description>{$options['description']}</description> | |
<initiator> | |
<name>{$options['fromName']}</name> | |
<email>{$options['fromEmail']}</email> | |
</initiator> | |
<options> | |
{$dates} | |
</options> | |
</poll> | |
EOT; | |
$poll = $this->API("polls", $xml); | |
echo "http://doodle-test.com/{$poll}\n"; | |
} | |
private function API($action, $xml) { | |
//$ch = curl_init("https://doodle.com/api1/{$action}"); | |
$ch = curl_init("http://doodle-test.com/api1WithoutAccessControl/{$action}"); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HEADER, true); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/xml")); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); | |
$results = curl_exec($ch); | |
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
// Check status code and parse doodle poll id | |
if ($code == 201 && preg_match("/Content-Location: (\w+)/", $results, $m)) | |
return $m[1]; | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@eyecatchup: please have a look at this project: https://github.com/xperseguers/doodle_client, currently not providing creation of doodle but could easily be done.