summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/SparkPost/MessageEvent.php31
-rw-r--r--lib/SparkPost/SparkPost.php2
2 files changed, 30 insertions, 3 deletions
diff --git a/lib/SparkPost/MessageEvent.php b/lib/SparkPost/MessageEvent.php
index a72fb49..e770642 100644
--- a/lib/SparkPost/MessageEvent.php
+++ b/lib/SparkPost/MessageEvent.php
@@ -2,8 +2,9 @@
namespace SparkPost;
/**
- * SDK class for querying message events API
- * @package SparkPost
+ * SDK class for querying the Message Events API
+ *
+ * @see https://developers.sparkpost.com/api/#/reference/message-events
*/
class MessageEvent extends APIResource
{
@@ -12,7 +13,7 @@ class MessageEvent extends APIResource
/**
* Method for issuing search requests to the Message Events API.
*
- * The method passes-through all of the query parameters listed at
+ * The method passes-through all of the query parameters - the valid ones are listed at
* @link https://developers.sparkpost.com/api/#/reference/message-events/events-documentation/search-for-message-events
*
* @param array $queryParams The query parameters. Note that a query parameter containing an array
@@ -22,6 +23,30 @@ class MessageEvent extends APIResource
*/
public function search(Array $queryParams)
{
+ // check for DateTime objects & replace them with the formatted string equivalent
+ foreach(["from", "to"] as $dateTimeParam) {
+ if (isset($queryParams[$dateTimeParam]) && $queryParams[$dateTimeParam] instanceof \DateTime) {
+ // the message events API doesn't allow the seconds or GMT offset, so strip them
+ $queryParams[$dateTimeParam] = substr($queryParams[$dateTimeParam]->format(\DateTime::ATOM), 0, 16);
+ }
+ }
+
return $this->get(null, $queryParams);
}
+
+ /**
+ * List descriptions of the event fields that could be included in a response from the MessageEvent::search() method.
+ *
+ * @return array The event field descriptions.
+ */
+ public function documentation() {
+ return $this->get("events/documentation");
+ }
+
+ /**
+ * List an example of the event data that will be included in a response from the MessageEvent::search() method.
+ */
+ public function samples() {
+ return $this->get("events/samples", ["events" => "bounce"]);
+ }
} \ No newline at end of file
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php
index 46623c9..0e576fe 100644
--- a/lib/SparkPost/SparkPost.php
+++ b/lib/SparkPost/SparkPost.php
@@ -6,6 +6,7 @@ use Ivory\HttpAdapter\HttpAdapterInterface;
class SparkPost {
public $transmission;
+ public $messageEvent;
/**
* Connection config for making requests.
@@ -45,6 +46,7 @@ class SparkPost {
$this->setHttpAdapter($httpAdapter);
$this->transmission = new Transmission($this);
+ $this->messageEvent = new MessageEvent($this);
}
/**