1 | <?php namespace MaartenStaa\GameAnalytics; |
||
8 | class Message |
||
9 | { |
||
10 | /** |
||
11 | * The URI of the endpoint that this message will be sent to. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $endpoint; |
||
16 | |||
17 | /** |
||
18 | * The GameAnalytics client that this message belongs to. |
||
19 | * |
||
20 | * @var \MaartenStaa\GameAnalytics\Client |
||
21 | */ |
||
22 | protected $client; |
||
23 | |||
24 | /** |
||
25 | * The parameters for this message. These will be JSON encoded into the request |
||
26 | * body when sending the message. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $payload = array(); |
||
31 | |||
32 | /** |
||
33 | * Constructor. |
||
34 | * |
||
35 | * @param string $endpoint |
||
36 | * @param \MaartenStaa\GameAnalytics\Client $client |
||
37 | */ |
||
38 | public function __construct($endpoint, Client $client) |
||
43 | |||
44 | /** |
||
45 | * Get the configured endpoint for this message. |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | public function getEndpoint() |
||
53 | |||
54 | /** |
||
55 | * Get the configured GameAnalytics client. |
||
56 | * |
||
57 | * @return \MaartenStaa\GameAnalytics\Client |
||
58 | */ |
||
59 | public function getClient() |
||
63 | |||
64 | /** |
||
65 | * Get the payload of all the parameters that are set on this message. |
||
66 | * |
||
67 | * @return array |
||
68 | */ |
||
69 | public function getPayload() |
||
73 | |||
74 | /** |
||
75 | * Set a value to be sent as part of this message. Use either as |
||
76 | * set($myKey, $myValue) or as set(array('key1' => 'value1', 'key2' => 'value2')). |
||
77 | * |
||
78 | * @param string|array $key |
||
79 | * @param mixed|null $value |
||
80 | * @return \MaartenStaa\GameAnalytics\Message |
||
81 | */ |
||
82 | public function set($key, $value = null) |
||
92 | |||
93 | /** |
||
94 | * Send this message to the configured endpoint using the HTTP adapter. |
||
95 | * |
||
96 | * @return \Psr\Http\Message\ResponseInterface |
||
97 | */ |
||
98 | public function send() |
||
104 | |||
105 | /** |
||
106 | * Build the request to send. |
||
107 | * |
||
108 | * @return \Psr\Http\Message\RequestInterface |
||
109 | */ |
||
110 | protected function buildRequest() |
||
122 | |||
123 | /** |
||
124 | * Get the GZipped JSON-encoded request body. |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | protected function getGzippedBody() |
||
134 | |||
135 | /** |
||
136 | * Get the contents of the Authorization header based on the given request |
||
137 | * body. Returns the base-64 encoded HMAC SHA-256 digest. |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | protected function getAuthorization($body) |
||
145 | } |
||
146 |