Skip to content

Instantly share code, notes, and snippets.

@dmpatierno
Created July 8, 2011 01:26
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmpatierno/1070917 to your computer and use it in GitHub Desktop.
Save dmpatierno/1070917 to your computer and use it in GitHub Desktop.
Creates a new poll with the Doodle API
<?php
$api = new DoodleAPI();
$api->createPoll(array(
'title' => 'Test Poll',
'description' => 'Test Description',
'fromName' => 'David Patierno',
'fromEmail' => 'dmpatierno@gmail.com',
'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;
}
}
@eyecatchup
Copy link

@xperseguers
Copy link

@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.

@webchoiceuk2021
Copy link

Thank you. We have used it on our application www.20x.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment