protected function PuSHSubscriber::request in Feeds 7
Same name and namespace in other branches
- 6 libraries/PuSHSubscriber.inc \PuSHSubscriber::request()
- 7.2 libraries/PuSHSubscriber.inc \PuSHSubscriber::request()
Issue a subscribe or unsubcribe request to a PubsubHubbub hub.
@todo Make concurrency safe.
Parameters
$hub: The URL of the hub's subscription endpoint.
$topic: The topic URL of the feed to subscribe to.
$mode: 'subscribe' or 'unsubscribe'.
$callback_url: The subscriber's notifications callback URL.
Compare to http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.2.html#...
2 calls to PuSHSubscriber::request()
- PuSHSubscriber::subscribe in libraries/
PuSHSubscriber.inc - Subscribe to a given URL. Attempt to retrieve 'hub' and 'self' links from document at $url and issue a subscription request to the hub.
- PuSHSubscriber::unsubscribe in libraries/
PuSHSubscriber.inc - @todo Unsubscribe from a hub. @todo Make sure we unsubscribe with the correct topic URL as it can differ from the initial subscription URL.
File
- libraries/
PuSHSubscriber.inc, line 244 - Pubsubhubbub subscriber library.
Class
- PuSHSubscriber
- PubSubHubbub subscriber.
Code
protected function request($hub, $topic, $mode, $callback_url) {
$secret = hash('sha1', uniqid(rand(), true));
$post_fields = array(
'hub.callback' => $callback_url,
'hub.mode' => $mode,
'hub.topic' => $topic,
'hub.verify' => 'sync',
'hub.lease_seconds' => '',
// Permanent subscription.
'hub.secret' => $secret,
'hub.verify_token' => md5(session_id() . rand()),
);
$sub = new $this->subscription_class($this->domain, $this->subscriber_id, $hub, $topic, $secret, $mode, $post_fields);
$sub
->save();
// Issue subscription request.
$request = curl_init($hub);
curl_setopt($request, CURLOPT_POST, TRUE);
curl_setopt($request, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($request, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($request);
$code = curl_getinfo($request, CURLINFO_HTTP_CODE);
if (in_array($code, array(
202,
204,
))) {
$this
->log("Positive response to \"{$mode}\" request ({$code}).");
}
else {
$sub->status = $mode . ' failed';
$sub
->save();
$this
->log("Error issuing \"{$mode}\" request to {$hub} ({$code}).", 'error');
}
curl_close($request);
}