1 | <?php |
||
15 | class Client implements ClientInterface |
||
16 | { |
||
17 | /** |
||
18 | * The public api key issued by Marvel. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | private $publicApiKey; |
||
23 | |||
24 | /** |
||
25 | * The private api key issued by Marvel. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | private $privateApiKey; |
||
30 | |||
31 | /** |
||
32 | * Guzzle HTTP Client implementation. |
||
33 | * |
||
34 | * @var GuzzleClientInterface |
||
35 | */ |
||
36 | private $guzzleClient; |
||
37 | |||
38 | /** |
||
39 | * Cache implementation. |
||
40 | * |
||
41 | * @var Cache\CacheInterface |
||
42 | */ |
||
43 | private $cache; |
||
44 | |||
45 | /** |
||
46 | * The Marvel API url. |
||
47 | * |
||
48 | * @const string |
||
49 | */ |
||
50 | const BASE_URL = 'http://gateway.marvel.com/v1/public/'; |
||
51 | |||
52 | /** |
||
53 | * Construct a new Client. |
||
54 | * |
||
55 | * @param string $privateApiKey The private api key issued by Marvel. |
||
56 | * @param string $publicApiKey The public api key issued by Marvel. |
||
57 | * @param ClientInterface $guzzleClient Implementation of a Guzzle HTTP client. |
||
58 | * @param Cache\CacheInterface $cache Implementation of Cache. |
||
59 | */ |
||
60 | final public function __construct( |
||
73 | |||
74 | /** |
||
75 | * Execute a search request against the Marvel API. |
||
76 | * |
||
77 | * @param string $resource The API resource to search for. |
||
78 | * @param array $filters Array of search criteria to use in request. |
||
79 | * |
||
80 | * @return ResponseInterface |
||
81 | * |
||
82 | * @throws \InvalidArgumentException Thrown if $resource is empty or not a string. |
||
83 | */ |
||
84 | final public function search($resource, array $filters = []) |
||
98 | |||
99 | /** |
||
100 | * Execute a GET request against the Marvel API for a single resource. |
||
101 | * |
||
102 | * @param string $resource The API resource to search for. |
||
103 | * @param integer $id The id of the API resource. |
||
104 | * |
||
105 | * @return ResponseInterface |
||
106 | */ |
||
107 | final public function get($resource, $id) |
||
122 | |||
123 | /** |
||
124 | * Send the given API Request. |
||
125 | * |
||
126 | * @param RequestInterface $request The request to send. |
||
127 | * |
||
128 | * @return ResponseInterface |
||
129 | */ |
||
130 | final private function send(RequestInterface $request) |
||
145 | |||
146 | /** |
||
147 | * Retrieve the Response for the given Request from cache. |
||
148 | * |
||
149 | * @param RequestInterface $request The request to send. |
||
150 | * |
||
151 | * @return ResponseInterface|null Returns the cached Response or null if it does not exist. |
||
152 | */ |
||
153 | final private function getFromCache(RequestInterface $request) |
||
161 | |||
162 | /** |
||
163 | * Allow calls such as $client->characters(); |
||
164 | * |
||
165 | * @param string $name The name of the api resource. |
||
166 | * @param array $arguments The parameters to pass to get() or search(). |
||
167 | * |
||
168 | * @return Collection|EntityInterface |
||
169 | */ |
||
170 | final public function __call($name, array $arguments) |
||
192 | } |
||
193 |