1 | <?php |
||
28 | class Diffbot |
||
29 | { |
||
30 | /** @var string The API access token */ |
||
31 | protected static $token = null; |
||
32 | |||
33 | /** @var string The instance token, settable once per new instance */ |
||
34 | protected $instanceToken; |
||
35 | |||
36 | /** @var Client The HTTP clients to perform requests with */ |
||
37 | protected $client; |
||
38 | |||
39 | /** @var EntityFactory The Factory which created Entities from Responses */ |
||
40 | protected $factory; |
||
41 | |||
42 | /** |
||
43 | * @param string|null $token The API access token, as obtained on diffbot.com/dev |
||
44 | * @throws DiffbotException When no token is provided |
||
45 | */ |
||
46 | 131 | public function __construct($token = null) |
|
59 | |||
60 | /** |
||
61 | * Sets the token for all future new instances |
||
62 | * @param string $token The API access token, as obtained on diffbot.com/dev |
||
63 | * @return void |
||
64 | */ |
||
65 | 14 | public static function setToken($token) |
|
70 | |||
71 | 139 | private static function validateToken($token) |
|
81 | |||
82 | /** |
||
83 | * Returns the token that has been defined. |
||
84 | * @return null|string |
||
85 | */ |
||
86 | 92 | public function getToken() |
|
90 | |||
91 | /** |
||
92 | * Sets the client to be used for querying the API endpoints |
||
93 | * |
||
94 | * @param Client $client |
||
95 | * @see http://php-http.readthedocs.org/en/latest/utils/#httpmethodsclient |
||
96 | * @return $this |
||
97 | */ |
||
98 | 124 | public function setHttpClient(Client $client = null) |
|
109 | |||
110 | /** |
||
111 | * Returns either the instance of the Guzzle client that has been defined, or null |
||
112 | * @return Client|null |
||
113 | */ |
||
114 | 123 | public function getHttpClient() |
|
118 | |||
119 | /** |
||
120 | * Sets the Entity Factory which will create the Entities from Responses |
||
121 | * @param EntityFactory $factory |
||
122 | * @return $this |
||
123 | */ |
||
124 | 123 | public function setEntityFactory(EntityFactory $factory = null) |
|
132 | |||
133 | /** |
||
134 | * Returns the Factory responsible for creating Entities from Responses |
||
135 | * @return EntityFactory |
||
136 | */ |
||
137 | 123 | public function getEntityFactory() |
|
141 | |||
142 | |||
143 | /** |
||
144 | * Creates a Product API interface |
||
145 | * |
||
146 | * @param string $url Url to analyze |
||
147 | * @return Product |
||
148 | */ |
||
149 | 5 | public function createProductAPI($url) |
|
160 | |||
161 | /** |
||
162 | * Creates an Article API interface |
||
163 | * |
||
164 | * @param string $url Url to analyze |
||
165 | * @return Article |
||
166 | */ |
||
167 | 10 | public function createArticleAPI($url) |
|
178 | |||
179 | /** |
||
180 | * Creates an Image API interface |
||
181 | * |
||
182 | * @param string $url Url to analyze |
||
183 | * @return Image |
||
184 | */ |
||
185 | 6 | public function createImageAPI($url) |
|
196 | |||
197 | /** |
||
198 | * Creates an Analyze API interface |
||
199 | * |
||
200 | * @param string $url Url to analyze |
||
201 | * @return Analyze |
||
202 | */ |
||
203 | 57 | public function createAnalyzeAPI($url) |
|
214 | |||
215 | /** |
||
216 | * Creates an Discussion API interface |
||
217 | * |
||
218 | * @param string $url Url to analyze |
||
219 | * @return Discussion |
||
220 | */ |
||
221 | 8 | public function createDiscussionAPI($url) |
|
232 | |||
233 | /** |
||
234 | * Creates a generic Custom API |
||
235 | * |
||
236 | * Does not have predefined Entity, so by default returns Wildcards |
||
237 | * |
||
238 | * @param string $url Url to analyze |
||
239 | * @param string $name Name of the custom API, required to finalize URL |
||
240 | * @return Custom |
||
241 | */ |
||
242 | 6 | public function createCustomAPI($url, $name) |
|
253 | |||
254 | /** |
||
255 | * Creates a new Crawljob with the given name. |
||
256 | * |
||
257 | * @see https://www.diffbot.com/dev/docs/crawl/ |
||
258 | * |
||
259 | * @param string $name Name of the crawljob. Needs to be unique. |
||
260 | * @param Api $api Optional instance of an API - if omitted, must be set |
||
261 | * later manually |
||
262 | * @return Crawl |
||
263 | */ |
||
264 | 61 | public function crawl($name = null, Api $api = null) |
|
275 | |||
276 | /** |
||
277 | * Search query. |
||
278 | * @see https://www.diffbot.com/dev/docs/search/#query |
||
279 | * @param string $q |
||
280 | * @return Search |
||
281 | */ |
||
282 | 14 | public function search($q) |
|
293 | } |