1 | <?php namespace MaartenStaa\GameAnalytics; |
||
13 | class Client |
||
14 | { |
||
15 | const API_ENDPOINT = 'http://api.gameanalytics.com/'; |
||
16 | const API_ENDPOINT_SANDBOX = 'http://sandbox-api.gameanalytics.com/'; |
||
17 | const API_VERSION = 'v2'; |
||
18 | |||
19 | /** |
||
20 | * The game key from GameAnalytics. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $key; |
||
25 | |||
26 | /** |
||
27 | * The game's secret key from GameAnalytics. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $secret; |
||
32 | |||
33 | /** |
||
34 | * The HTTP handler that should be used. |
||
35 | * |
||
36 | * @var \Http\Client\HttpClient |
||
37 | */ |
||
38 | protected $http; |
||
39 | |||
40 | /** |
||
41 | * The HTTP message factory that should be used. |
||
42 | * |
||
43 | * @var \Http\Message\MessageFactory |
||
44 | */ |
||
45 | protected $factory; |
||
46 | |||
47 | /** |
||
48 | * Whether this client should communicate with the sandbox servers instead |
||
49 | * of the real API endpoints. |
||
50 | * |
||
51 | * @var bool |
||
52 | */ |
||
53 | protected $sandbox = false; |
||
54 | |||
55 | /** |
||
56 | * Constructor. |
||
57 | * |
||
58 | * @param string $key |
||
59 | * @param string $secret |
||
60 | * @param \Http\Client\HttpClient|null $http |
||
61 | * @param \Http\Message\MessageFactory|null $factory |
||
62 | */ |
||
63 | public function __construct($key, $secret, HttpClient $http = null, MessageFactory $factory = null) |
||
64 | { |
||
65 | $this->key = $key; |
||
66 | $this->secret = $secret; |
||
67 | $this->http = $http ?: HttpClientDiscovery::find(); |
||
68 | $this->factory = $factory ?: MessageFactoryDiscovery::find(); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Set whether this client should refer to the sandbox endpoint. |
||
73 | * |
||
74 | * @param bool $value |
||
75 | */ |
||
76 | public function sandbox($value) |
||
80 | |||
81 | /** |
||
82 | * Get the configured game's secret key from GameAnalytics. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getSecret() |
||
90 | |||
91 | /** |
||
92 | * Get the configured HTTP handler. |
||
93 | * |
||
94 | * @return \Http\Client\HttpAdapter |
||
|
|||
95 | */ |
||
96 | public function getHttp() |
||
100 | |||
101 | /** |
||
102 | * Get the configured HTTP message factory. |
||
103 | * |
||
104 | * @return \Http\Message\MessageFactory |
||
105 | */ |
||
106 | public function getMessageFactory() |
||
110 | |||
111 | /** |
||
112 | * Get the URL that events should be posted to. |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | public function getEndpoint($api) |
||
121 | |||
122 | /** |
||
123 | * Get a new init message. |
||
124 | * |
||
125 | * @return \MaartenStaa\GameAnalytics\Message |
||
126 | */ |
||
127 | public function init() |
||
131 | |||
132 | /** |
||
133 | * Get a new event message for the given category. |
||
134 | * |
||
135 | * @param string $category |
||
136 | * @return \MaartenStaa\GameAnalytics\Message |
||
137 | */ |
||
138 | public function event($category) |
||
145 | |||
146 | /** |
||
147 | * Create a "user" event. Shortcut for event('user'). |
||
148 | * |
||
149 | * @return \MaartenStaa\GameAnalytics\Message |
||
150 | */ |
||
151 | public function user() |
||
155 | |||
156 | /** |
||
157 | * Create a "session_end" event. Shortcut for event('session_end'). |
||
158 | * |
||
159 | * @return \MaartenStaa\GameAnalytics\Message |
||
160 | */ |
||
161 | public function sessionEnd() |
||
165 | |||
166 | /** |
||
167 | * Create a "business" event. Shortcut for event('business'). |
||
168 | * |
||
169 | * @return \MaartenStaa\GameAnalytics\Message |
||
170 | */ |
||
171 | public function business() |
||
175 | |||
176 | /** |
||
177 | * Create a "resource" event. Shortcut for event('resource'). |
||
178 | * |
||
179 | * @return \MaartenStaa\GameAnalytics\Message |
||
180 | */ |
||
181 | public function resource() |
||
185 | |||
186 | /** |
||
187 | * Create a "progression" event. Shortcut for event('progression'). |
||
188 | * |
||
189 | * @return \MaartenStaa\GameAnalytics\Message |
||
190 | */ |
||
191 | public function progression() |
||
195 | |||
196 | /** |
||
197 | * Create a "design" event. Shortcut for event('design'). |
||
198 | * |
||
199 | * @return \MaartenStaa\GameAnalytics\Message |
||
200 | */ |
||
201 | public function design() |
||
205 | |||
206 | /** |
||
207 | * Create a "error" event. Shortcut for event('error'). |
||
208 | * |
||
209 | * @return \MaartenStaa\GameAnalytics\Message |
||
210 | */ |
||
211 | public function error() |
||
215 | } |
||
216 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.