Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

alerts api method added

  • Loading branch information...
commit 35f76a309b327c24277014f935541438db2ed5ce 1 parent 170d35e
@freeman1988 freeman1988 authored
View
71 IronMQ.class.php
@@ -488,6 +488,77 @@ public function releaseMessage($queue_name, $message_id, $delay = 0)
}
/**
+ * Add alerts to a queue. This is for Pull Queue only.
+ *
+ * @param string $queue_name
+ * @param array $alerts_hash
+ * @return mixed
+ */
+ public function addAlerts($queue_name, $alerts_hash)
+ {
+ $this->setJsonHeaders();
+ $queue = rawurlencode($queue_name);
+ $url = "projects/{$this->project_id}/queues/$queue/alerts";
+ $options = array(
+ 'alerts' => $alerts_hash
+ );
+ return self::json_decode($this->apiCall(self::POST, $url, $options));
+ }
+
+ /**
+ * Replace current queue alerts with a given list of alerts. This is for Pull Queue only.
+ *
+ * @param string $queue_name
+ * @param array $alerts_hash
+ * @return mixed
+ */
+ public function updateAlerts($queue_name, $alerts_hash)
+ {
+ $this->setJsonHeaders();
+ $queue = rawurlencode($queue_name);
+ $url = "projects/{$this->project_id}/queues/$queue/alerts";
+ $options = array(
+ 'alerts' => $alerts_hash
+ );
+ return self::json_decode($this->apiCall(self::PUT, $url, $options));
+ }
+
+ /**
+ * Remove alerts from a queue. This is for Pull Queue only.
+ *
+ * @param string $queue_name
+ * @param array $alerts_ids
+ * @return mixed
+ */
+ public function deleteAlerts($queue_name, $alerts_ids)
+ {
+ $this->setJsonHeaders();
+ $queue = rawurlencode($queue_name);
+ $url = "projects/{$this->project_id}/queues/$queue/alerts";
+ $options = array(
+ 'alerts' => $alerts_ids
+ );
+ print_r(json_encode($options));
+ return self::json_decode($this->apiCall(self::DELETE, $url, $options));
+ }
+
+ /**
+ * Remove alert from a queue by its ID. This is for Pull Queue only.
+ *
+ * @param string $queue_name
+ * @param string $alert_id
+ * @return mixed
+ */
+ public function deleteAlertById($queue_name, $alert_id)
+ {
+ $this->setJsonHeaders();
+ $queue = rawurlencode($queue_name);
+ $url = "projects/{$this->project_id}/queues/$queue/alerts/$alert_id";
+
+ return self::json_decode($this->apiCall(self::DELETE, $url));
+ }
+
+ /**
* Delete a Message Queue
* This call deletes a message queue and all its messages.
*
View
BIN  iron_mq.phar
Binary file not shown
View
28 testMessages.php
@@ -51,6 +51,34 @@
$res = $ironmq->deleteMessages("test-queue-multi", $messageIds);
print_r($res);
+ echo "Adding alerts..\n";
+ $res = $ironmq->postMessage("test_alert_queue", "Test Message 1");
+ $first_alert = array(
+ 'type' => 'fixed',
+ 'direction' => 'desc',
+ 'trigger' => 1001,
+ 'snooze' => 10,
+ 'queue' => 'test_alert_queue');
+ $second_alert = array(
+ 'type' => 'fixed',
+ 'direction' => 'asc',
+ 'trigger' => 1000,
+ 'snooze' => 5,
+ 'queue' => 'test_alert_queue',);
+
+ $res = $ironmq->addAlerts("test_alert_queue", array($first_alert, $second_alert));
+ print_r($res);
+
+ echo "Deleting alerts with ids..\n";
+ $message = $ironmq->getQueue("test_alert_queue");
+ $alert_ids = array();
+ $alerts = $message-> alerts;
+ foreach($alerts as $alert) {
+ array_push($alert_ids, array('id'=>$alert->id));
+ }
+ print_r($alert_ids);
+ $res = $ironmq->deleteAlerts("test_alert_queue", $alert_ids);
+ print_r($res);
echo "\n------$i-------\n";
}
Please sign in to comment.
Something went wrong with that request. Please try again.