1 | <?php |
||
10 | class Client |
||
11 | { |
||
12 | /** |
||
13 | * MonkeyLearn API base uri. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | const BASE_URI = 'https://api.monkeylearn.com/v2/'; |
||
18 | |||
19 | /** |
||
20 | * HTTP client used for communication. |
||
21 | * |
||
22 | * @var HttpClientInterface |
||
23 | */ |
||
24 | protected $httpClient; |
||
25 | |||
26 | /** |
||
27 | * MonkeyLearn API token. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $token; |
||
32 | |||
33 | /** |
||
34 | * Map group name to class names. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $map = [ |
||
39 | 'classification' => 'Classification', |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * Assign dependencies. |
||
44 | * |
||
45 | * @param string $token |
||
46 | * @param HttpClientInterface $httpClient |
||
47 | */ |
||
48 | 26 | public function __construct($token, HttpClientInterface $httpClient = null) |
|
54 | |||
55 | /** |
||
56 | * Retrieve the API group to call a method within. |
||
57 | * |
||
58 | * @api |
||
59 | * |
||
60 | * @param string $group |
||
61 | * |
||
62 | * @throws InvalidArgumentException |
||
63 | * |
||
64 | * @return ApiInterface |
||
65 | */ |
||
66 | 8 | public function api($group) |
|
80 | |||
81 | /** |
||
82 | * Get the client to use for HTTP communication. |
||
83 | * |
||
84 | * @internal |
||
85 | * |
||
86 | * @return HttpClientInterface |
||
87 | */ |
||
88 | 14 | public function getHttpClient() |
|
102 | |||
103 | /** |
||
104 | * Enables debug data in responses. |
||
105 | * |
||
106 | * @return $this |
||
107 | */ |
||
108 | 2 | public function debug() |
|
109 | { |
||
110 | 2 | $this->getHttpClient()->addConfigOption('debug'); |
|
111 | |||
112 | 2 | return $this; |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * Enables sandbox mode for custom modules. |
||
117 | * |
||
118 | * @return $this |
||
119 | */ |
||
120 | 2 | public function sandbox() |
|
121 | { |
||
122 | 2 | $this->getHttpClient()->addConfigOption('sandbox'); |
|
123 | |||
124 | 2 | return $this; |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * Magic method to call API groups directly via property. |
||
129 | * |
||
130 | * @param string $group |
||
131 | * |
||
132 | * @return ApiInterface |
||
133 | */ |
||
134 | 4 | public function __get($group) |
|
138 | |||
139 | /** |
||
140 | * Get Api Group object. |
||
141 | * |
||
142 | * @param string $group |
||
143 | * |
||
144 | * @throws BadMethodCallException |
||
145 | * |
||
146 | * @return ApiInterface |
||
147 | */ |
||
148 | 4 | protected function getApiObject($group) |
|
158 | } |
||
159 |