1 | <?php |
||
19 | class HttpClient |
||
20 | { |
||
21 | /** |
||
22 | * User agent for the client. |
||
23 | */ |
||
24 | const PHP_GA_MEASUREMENT_PROTOCOL_USER_AGENT = |
||
25 | 'THE ICONIC GA Measurement Protocol PHP Client (https://github.com/theiconic/php-ga-measurement-protocol)'; |
||
26 | |||
27 | /** |
||
28 | * Timeout in seconds for the request connection and actual request execution. |
||
29 | * Using the same value you can find in Google's PHP Client. |
||
30 | */ |
||
31 | const REQUEST_TIMEOUT_SECONDS = 100; |
||
32 | |||
33 | /** |
||
34 | * HTTP client. |
||
35 | * |
||
36 | * @var Client |
||
37 | */ |
||
38 | private $client; |
||
39 | |||
40 | /** |
||
41 | * Holds the promises (async responses). |
||
42 | * |
||
43 | * @var PromiseInterface[] |
||
44 | */ |
||
45 | private static $promises = []; |
||
46 | |||
47 | /** |
||
48 | * We have to unwrap and send all promises at the end before analytics objects is destroyed. |
||
49 | */ |
||
50 | public function __destruct() |
||
54 | |||
55 | /** |
||
56 | * Sets HTTP client. |
||
57 | * |
||
58 | * @internal |
||
59 | * @param Client $client |
||
60 | */ |
||
61 | public function setClient(Client $client) |
||
65 | |||
66 | /** |
||
67 | * Gets HTTP client for internal class use. |
||
68 | * |
||
69 | * @return Client |
||
70 | */ |
||
71 | private function getClient() |
||
81 | |||
82 | /** |
||
83 | * Sends request to Google Analytics. |
||
84 | * |
||
85 | * @internal |
||
86 | * @param string $url |
||
87 | * @param array $options |
||
88 | * @return AnalyticsResponse |
||
89 | */ |
||
90 | public function post($url, array $options = []) |
||
111 | |||
112 | |||
113 | /** |
||
114 | * @param array $options |
||
115 | * @return array |
||
116 | */ |
||
117 | public function prepareAsyncOptions(array $options) |
||
131 | |||
132 | /** |
||
133 | * Parse the given options and fill missing fields with default values. |
||
134 | * |
||
135 | * @param array $options |
||
136 | * @return array |
||
137 | */ |
||
138 | private function parseOptions(array $options) |
||
161 | |||
162 | /** |
||
163 | * Creates an analytics response object. |
||
164 | * |
||
165 | * @param RequestInterface $request |
||
166 | * @param ResponseInterface|PromiseInterface $response |
||
167 | * @return AnalyticsResponse |
||
168 | */ |
||
169 | protected function getAnalyticsResponse(RequestInterface $request, $response) |
||
173 | } |
||
174 |