blob: d44a30f50cf6e6ba15b5c28e0d0e5672d867876a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<?php
namespace SparkPost;
/**
* SDK class for querying the Message Events API.
*
* @see https://developers.sparkpost.com/api/#/reference/message-events
*/
class MessageEvents extends APIResource
{
/**
* @var string
*/
public $endpoint = 'message-events';
/**
* Method for issuing search requests to the Message Events API.
*
* 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
* is collapsed into a comma-separated list.
*
* @return array The result of the query.
*/
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 examples of the event data that will be included in a response from the MessageEvent::search() method.
*
* @param array $events (optional) Event types for which to get a sample payload. If not provided, samples
* for all events will be returned.
*
* @return array Sample events.
*/
public function samples(array $events = [])
{
return $this->get('events/samples', ['events' => $events]);
}
}
|