Skip to content

Commit 7b5a6a2

Browse files
committed
Do not include unset parameters in query string
Fixes #1
1 parent 1213f89 commit 7b5a6a2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Subscriber.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,22 @@ private function change_subscription($mode, $topic_url, $http_function = false)
148148
throw new InvalidArgumentException('The specified topic url does not appear to be valid: ' . $topic_url);
149149
}
150150

151-
// set the mode subscribe/unsubscribe
151+
// set the required parameters
152152
$post_string = 'hub.mode=' . $mode;
153153
$post_string .= '&hub.callback=' . urlencode($this->callback_url);
154-
$post_string .= '&hub.verify=' . $this->verify;
155-
$post_string .= '&hub.verify_token=' . $this->verify_token;
156-
$post_string .= '&hub.lease_seconds=' . $this->lease_seconds;
157-
158-
// append the topic url parameters
159154
$post_string .= '&hub.topic=' . urlencode($topic_url);
160155

156+
// add any optional parameter
157+
if (!is_null($this->verify)) {
158+
$post_string .= '&hub.verify=' . $this->verify;
159+
}
160+
if (!is_null($this->verify_token)) {
161+
$post_string .= '&hub.verify_token=' . $this->verify_token;
162+
}
163+
if (!is_null($this->lease_seconds)) {
164+
$post_string .= '&hub.lease_seconds=' . $this->lease_seconds;
165+
}
166+
161167
// make the http post request and return true/false
162168
// easy to over-write to use your own http function
163169
if ($http_function) {

0 commit comments

Comments
 (0)