API Abstract

API Abstract klasa je apstraktna klasa na kojoj su izgradene sve druge API klase, kako bi naslijedile neke zajednicke funkcionalnosti. Koristite ovu klasu kako biste izgradili API klase bazirane na Custom API-ju definiranom u Diffbotovom sucelju.

class Swader\Diffbot\Abstracts\Api

Swader\Diffbot\Abstracts\Api::__construct($url)
Parametri:
  • $url (string) – URL web stranice koju treba obraditi
Throws:

InvalidArgumentException if the URL is invalid AND not the word “crawl”

This class takes a single argument during construction, the URL of the page to process. Alternatively, the argument can be “crawl”, if the API is to be used in conjunction with the Swader\Diffbot\Api\Crawl API.

Swader\Diffbot\Abstracts\Api::setTimeout($timeout = 30000)
Parametri:
  • $timeout (int) – Izostavljiv argument. Vrijeme cekanja na uspjesan odaziv API pozivu, u milisekundama. Default je 30000, ili 30 sekundi.
Vraća:

$this

Throws:

InvalidArgumentException if the timeout value is invalid (negative or not an integer)

Zadavanje timeout vrijednosti definira koliko dugo da Diffbot ceka na uspjesnu obradu. Neuspjeh u obradi moze biti posrijedi problema s Diffbotovim serverima, veoma spore stranice koja se procesuira, i drugo.

Koristenje:

$api->setTimeout(40000);

Swader\Diffbot\Abstracts\Api::call()
Vraća:Swader\Diffbot\Entity\EntityIterator The return value will be an iterable collection of appropriate entities. Refer to each API’s documentation for details on entities returned from each API call.

Kad je API instanca podesena, ova metoda izvrsava poziv na server.

Koristenje:

$result = $api->call();
foreach ($result as $entity) { /* ... */ }

Swader\Diffbot\Abstracts\Api::buildUrl()
Vraća:string

This method is called automatically when Swader\Diffbot\Abstracts\Api::call is called. It builds the URL which is to be called by the HTTPClient in Swader\Diffbot\Diffbot::setHttpClient, and returns it. This method can be used to get the URL for the purposes of testing in third party API clients like Postman.

Koristenje:

$api-> // ... set up API
$myUrl = $api->buildUrl();