3 * StatusNet, the distributed open-source microblogging tool
5 * Class to ping an rssCloud endpoint when a feed has been updated
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
34 class RSSCloudNotifier {
36 function challenge($endpoint, $feed)
38 $code = common_confirmation_code(128);
39 $params = array('url' => $feed, 'challenge' => $code);
40 $url = $endpoint . '?' . http_build_query($params);
43 $client = new HTTPClient();
44 $response = $client->get($url);
45 } catch (HTTP_Request2_Exception $e) {
46 common_log(LOG_INFO, 'RSSCloud plugin - failure testing notify handler ' .
47 $endpoint . ' - ' . $e->getMessage());
51 // Check response is betweet 200 and 299 and body contains challenge data
53 $status = $response->getStatus();
54 $body = $response->getBody();
56 if ($status >= 200 && $status < 300) {
58 if (strpos($body, $code) !== false) {
59 common_log(LOG_INFO, 'RSSCloud plugin - ' .
60 "success testing notify handler: $endpoint");
63 common_log(LOG_INFO, 'RSSCloud plugin - ' .
64 'challenge/repsonse failed for notify handler ' .
66 common_debug('body = ' . var_export($body, true));
70 common_log(LOG_INFO, 'RSSCloud plugin - ' .
71 "failure testing notify handler: $endpoint " .
72 ' - got HTTP ' . $status);
73 common_debug('body = ' . var_export($body, true));
78 function postUpdate($endpoint, $feed) {
81 $postdata = array('url' => $feed);
84 $client = new HTTPClient();
85 $response = $client->post($endpoint, $headers, $postdata);
86 } catch (HTTP_Request2_Exception $e) {
87 common_log(LOG_INFO, 'RSSCloud plugin - failure notifying ' .
88 $endpoint . ' that feed ' . $feed .
89 ' has changed: ' . $e->getMessage());
93 $status = $response->getStatus();
95 if ($status >= 200 && $status < 300) {
96 common_log(LOG_INFO, 'RSSCloud plugin - success notifying ' .
97 $endpoint . ' that feed ' . $feed . ' has changed.');
100 common_log(LOG_INFO, 'RSSCloud plugin - failure notifying ' .
101 $endpoint . ' that feed ' . $feed .
102 ' has changed: got HTTP ' . $status);
103 common_debug('body = ' . var_export($response->getBody(), true));