1 | <?php |
||
12 | class Client implements ClientInterface |
||
13 | { |
||
14 | /** |
||
15 | * The default ttl for cached responses (24 hours). |
||
16 | * |
||
17 | * @link http://developer.marvel.com/documentation/attribution Marvel's rules for caching. |
||
18 | * |
||
19 | * @const integer |
||
20 | */ |
||
21 | const MAX_TTL = 86400; |
||
22 | |||
23 | /** |
||
24 | * The public api key issued by Marvel. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | private $publicApiKey; |
||
29 | |||
30 | /** |
||
31 | * The private api key issued by Marvel. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | private $privateApiKey; |
||
36 | |||
37 | /** |
||
38 | * Guzzle HTTP Client implementation. |
||
39 | * |
||
40 | * @var GuzzleHttp\ClientInterface |
||
41 | */ |
||
42 | private $guzzleClient; |
||
43 | |||
44 | /** |
||
45 | * Cache implementation. |
||
46 | * |
||
47 | * @var CacheInterface |
||
48 | */ |
||
49 | private $cache; |
||
50 | |||
51 | /** |
||
52 | * The Marvel API url. |
||
53 | * |
||
54 | * @const string |
||
55 | */ |
||
56 | const BASE_URL = 'http://gateway.marvel.com/v1/public/'; |
||
57 | |||
58 | /** |
||
59 | * Construct a new Client. |
||
60 | * |
||
61 | * @param string $privateApiKey The private api key issued by Marvel. |
||
62 | * @param string $publicApiKey The public api key issued by Marvel. |
||
63 | * @param GuzzleHttp\ClientInterface $guzzleClient Implementation of a Guzzle HTTP client. |
||
64 | * @param CacheInterface $cache Implementation of Cache. |
||
65 | */ |
||
66 | final public function __construct( |
||
77 | |||
78 | /** |
||
79 | * Execute a search request against the Marvel API. |
||
80 | * |
||
81 | * @param string $resource The API resource to search for. |
||
82 | * @param array $filters Array of search criteria to use in request. |
||
83 | * |
||
84 | * @return null|DataWrapper |
||
85 | * |
||
86 | * @throws \InvalidArgumentException Thrown if $resource is empty or not a string. |
||
87 | */ |
||
88 | final public function search(string $resource, array $filters = []) |
||
103 | |||
104 | /** |
||
105 | * Execute a GET request against the Marvel API for a single resource. |
||
106 | * |
||
107 | * @param string $resource The API resource to search for. |
||
108 | * @param integer $id The id of the API resource. |
||
109 | * |
||
110 | * @return null|DataWrapper |
||
111 | */ |
||
112 | final public function get(string $resource, int $id) |
||
129 | |||
130 | /** |
||
131 | * Send the given API url request. |
||
132 | * |
||
133 | * @param string $url The URL to request. |
||
134 | * |
||
135 | * @return ResponseInterface |
||
136 | */ |
||
137 | final private function send(string $url) : ResponseInterface |
||
155 | |||
156 | /** |
||
157 | * Allow calls such as $client->characters(); |
||
158 | * |
||
159 | * @param string $name The name of the api resource. |
||
160 | * @param array $arguments The parameters to pass to get() or search(). |
||
161 | * |
||
162 | * @return Collection|EntityInterface|null |
||
163 | */ |
||
164 | final public function __call(string $name, array $arguments) |
||
181 | } |
||
182 |