-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoodleAPI.php
159 lines (131 loc) · 5.68 KB
/
DoodleAPI.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* @author decima
*
*/
require_once 'CurlExtend.php';
require_once 'DoodleData.php';
class DoodleAPI extends CurlExtend {
protected $key;
protected $secret;
const DOODLE_URL_API = "http://doodle.com/api1/";
const DOODLE_OAUTH_REQUEST_TOKEN = "oauth/requesttoken";
const DOODLE_OAUTH_ACCESS_TOKEN = "oauth/accesstoken";
const DOODLE_POLL_URL = "polls/";
public function __construct($key, $secret) {
$this->key = $key;
$this->secret = $secret;
}
protected function initiateDoodle($header = null) {
$in_params=array();
$in_params['oauth_consumer_key'] = $this->key;
$in_params['oauth_consumer_secret'] = $this->secret;
$url = self::DOODLE_URL_API . self::DOODLE_OAUTH_REQUEST_TOKEN;
$out = $this->getCurl($url, $in_params, $header);
$out = $this->parse_get_result($out);
$in_params['oauth_token'] = $out['oauth_token'];
$in_params['oauth_token_secret'] = $out['oauth_token_secret'];
$url = self::DOODLE_URL_API . self::DOODLE_OAUTH_ACCESS_TOKEN;
$out = $this->getCurl($url, $in_params, $header);
$out = $this->parse_get_result($out);
$in_params['oauth_token'] = $out['oauth_token'];
$in_params['oauth_token_secret'] = $out['oauth_token_secret'];
return $in_params;
}
public function getPoll($poll_id, $x_poll_id = null) {
$header = null;
if ($x_poll_id) {
$header[] = "X-DoodleKey:" . $x_poll_id;
}
$in_params = $this->initiateDoodle();
$url = self::DOODLE_URL_API . self::DOODLE_POLL_URL . $poll_id;
$r = $this->getCurl($url, $in_params, $header);
$r = $this->formate_get_result($r);
return $r;
}
public function createPoll($xml_string) {
$in_params = $this->initiateDoodle();
$url = self::DOODLE_URL_API . self::DOODLE_POLL_URL;
$res = $this->postCurl($url, $in_params, $xml_string);
$results = $this->formate_post_result($res);
if (stristr($results[0], "201"))
return $results;
else
throw new Exception($results[0]);
}
public function updatePoll($poll_id, $x_poll_id, $xml_string) {
$header = "X-DoodleKey:" . $x_poll_id;
$in_params = $this->initiateDoodle();
$url = self::DOODLE_URL_API . self::DOODLE_POLL_URL . $poll_id;
$res = $this->putCurl($url, $in_params, $xml_string, $header);
$results = $this->formate_post_result($res);
if (stristr($results[0], "200"))
return $results;
else
throw new Exception($results[0]);
}
public function deletePoll($poll_id, $x_poll_id) {
$header = "X-DoodleKey:" . $x_poll_id;
$in_params = $this->initiateDoodle();
$url = self::DOODLE_URL_API . self::DOODLE_POLL_URL . $poll_id;
$res = $this->deleteCurl($url, $in_params, $header);
$results = $this->formate_post_result($res);
if (stristr($results[0], "204"))
return $results;
else
throw new Exception($results[0]);
}
public function addParticipant($poll_id, $xml_string) {
$in_params = $this->initiateDoodle();
$url = self::DOODLE_URL_API . self::DOODLE_POLL_URL . $poll_id . "/participants";
$res = $this->postCurl($url, $in_params, $xml_string);
$results = $this->formate_post_result($res);
if (stristr($results[0], "201"))
return $results;
else
throw new Exception($results[0]);
}
public function updateParticipant($poll_id, $x_poll_id, $participant_id, $xml_string) {
$header = "X-DoodleKey:" . $x_poll_id;
$in_params = $this->initiateDoodle();
$url = self::DOODLE_URL_API . self::DOODLE_POLL_URL . $poll_id . "/participants/" . $participant_id;
$res = $this->putCurl($url, $in_params, $xml_string, $header);
$results = $this->formate_post_result($res);
if (stristr($results[0], "200"))
return $results;
else
throw new Exception($results[0]);
}
public function deleteParticipant($poll_id, $x_poll_id, $participant_id) {
$header = "X-DoodleKey:" . $x_poll_id;
$in_params = $this->initiateDoodle();
$url = self::DOODLE_URL_API . self::DOODLE_POLL_URL . $poll_id . "/participants/" . $participant_id;
$res = $this->deleteCurl($url, $in_params, $header);
$results = $this->formate_post_result($res);
if (stristr($results[0], "204"))
return $results;
else
throw new Exception($results[0]);
}
public function addComment($poll_id, $xml_string) {
$in_params = $this->initiateDoodle();
$url = self::DOODLE_URL_API . self::DOODLE_POLL_URL . $poll_id . "/comments";
$res = $this->postCurl($url, $in_params, $xml_string);
$results = $this->formate_post_result($res);
if (stristr($results[0], "201"))
return $results;
else
throw new Exception($results[0]);
}
public function deleteComment($poll_id, $x_poll_id, $comment_id) {
$header = "X-DoodleKey:" . $x_poll_id;
$in_params = $this->initiateDoodle();
$url = self::DOODLE_URL_API . self::DOODLE_POLL_URL . $poll_id . "/comments/" . $comment_id;
$res = $this->deleteCurl($url, $in_params, $header);
$results = $this->formate_post_result($res);
if (stristr($results[0], "204"))
return $results;
else
throw new Exception($results[0]);
}
}