Permalink
Browse files

Clean up loadSubscription() and make it public, add subscribed() query.

  • Loading branch information...
1 parent b6476cb commit 9206d8d471075ec7a9a27fc707b5c5d9ac13f4b3 Alex Barth committed Sep 12, 2010
Showing with 21 additions and 5 deletions.
  1. +21 −5 PuSHSubscriber.inc
View
@@ -108,7 +108,7 @@ class PuSHSubscriber {
* The callback to unsubscribe.
*/
public function unsubscribe($topic_url, $callback_url) {
- if ($sub = $this->loadSubscription()) {
+ if ($sub = $this->subscription()) {
$this->request($sub->hub, $sub->topic, 'unsubscribe', $callback_url);
$sub->delete();
}
@@ -156,7 +156,7 @@ class PuSHSubscriber {
if ($ignore_signature) {
return $raw;
}
- if (isset($_SERVER['HTTP_X_HUB_SIGNATURE']) && ($sub = $this->loadSubscription())) {
+ if (isset($_SERVER['HTTP_X_HUB_SIGNATURE']) && ($sub = $this->subscription())) {
$result = array();
parse_str($_SERVER['HTTP_X_HUB_SIGNATURE'], $result);
if (isset($result['sha1']) && $result['sha1'] == hash_hmac('sha1', $raw, $sub->secret)) {
@@ -192,7 +192,7 @@ class PuSHSubscriber {
*
* In all other cases confirm negative.
*/
- if ($sub = $this->loadSubscription()) {
+ if ($sub = $this->subscription()) {
if ($_GET['hub_verify_token'] == $sub->post_fields['hub.verify_token']) {
if ($_GET['hub_mode'] == 'subscribe' && $sub->status == 'subscribe') {
$sub->status = 'subscribed';
@@ -273,13 +273,29 @@ class PuSHSubscriber {
}
/**
- * Helper for loading a subscription.
+ * Get the subscription associated with this subscriber.
+ *
+ * @return
+ * A PuSHSubscriptionInterface object if a subscription exist, NULL
+ * otherwise.
*/
- protected function loadSubscription() {
+ public function subscription() {
return call_user_func(array($this->subscription_class, 'load'), $this->domain, $this->subscriber_id);
}
/**
+ * Determine whether this subscriber is successfully subscribed or not.
+ */
+ public function subscribed() {
+ if ($sub = $this->subscription()) {
+ if ($sub->status == 'subscribed') {
+ return TRUE;
+ }
+ }
+ return FALSE;
+ }
+
+ /**
* Helper for messaging.
*/
protected function msg($msg, $level = 'status') {

0 comments on commit 9206d8d

Please sign in to comment.