22namespace SparkPost ;
33
44/**
5- * SDK class for querying message events API
6- * @package SparkPost
5+ * SDK class for querying the Message Events API
6+ *
7+ * @see https://developers.sparkpost.com/api/#/reference/message-events
78 */
89class MessageEvent extends APIResource
910{
@@ -12,7 +13,7 @@ class MessageEvent extends APIResource
1213 /**
1314 * Method for issuing search requests to the Message Events API.
1415 *
15- * The method passes-through all of the query parameters listed at
16+ * The method passes-through all of the query parameters - the valid ones are listed at
1617 * @link https://developers.sparkpost.com/api/#/reference/message-events/events-documentation/search-for-message-events
1718 *
1819 * @param array $queryParams The query parameters. Note that a query parameter containing an array
@@ -22,6 +23,30 @@ class MessageEvent extends APIResource
2223 */
2324 public function search (Array $ queryParams )
2425 {
26+ // check for DateTime objects & replace them with the formatted string equivalent
27+ foreach (["from " , "to " ] as $ dateTimeParam ) {
28+ if (isset ($ queryParams [$ dateTimeParam ]) && $ queryParams [$ dateTimeParam ] instanceof \DateTime) {
29+ // the message events API doesn't allow the seconds or GMT offset, so strip them
30+ $ queryParams [$ dateTimeParam ] = substr ($ queryParams [$ dateTimeParam ]->format (\DateTime::ATOM ), 0 , 16 );
31+ }
32+ }
33+
2534 return $ this ->get (null , $ queryParams );
2635 }
36+
37+ /**
38+ * List descriptions of the event fields that could be included in a response from the MessageEvent::search() method.
39+ *
40+ * @return array The event field descriptions.
41+ */
42+ public function documentation () {
43+ return $ this ->get ("events/documentation " );
44+ }
45+
46+ /**
47+ * List an example of the event data that will be included in a response from the MessageEvent::search() method.
48+ */
49+ public function samples () {
50+ return $ this ->get ("events/samples " , ["events " => "bounce " ]);
51+ }
2752}
0 commit comments