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