Interfaces¶
This document contains the descriptions for all interfaces used in the client.
Api¶
-
interface
Swader\Diffbot\Interfaces\
Api
¶ The API interface is there as a contract for developing custom APIs, not unlike the
Swader\Diffbot\Api\Custom
class.
setTimeout¶
Swader\Diffbot\Interfaces\Api::
setTimeout
($timeout = 30000)¶
Parametri:
- $timeout (int) – The timeout value in milliseconds. Defaults to 30000 (30 seconds)
Vraća: $this
All Diffbot API endpoints support a timeout parameter which tells them after how many milliseconds to stop expecting a response from the page being processed.
call¶
Swader\Diffbot\Interfaces\Api::
call
()¶
Vraća: Swader\Diffbot\Entity\EntityIterator
The call method should execute the remote call to the API. It must return an instance of
Swader\Diffbot\Entity\EntityIterator
containing the set of appropriate entities for the return value of said API. In custom APIs, these are usuallySwader\Diffbot\Entity\Wildcard
entities, unless otherwise specified via a custom implementation ofSwader\Diffbot\Interfaces\EntityFactory
.
buildUrl¶
Swader\Diffbot\Interfaces\Api::
buildUrl
()¶
Vraća: string This method is called automatically when
Swader\Diffbot\Interfaces\Api::call
is called. It builds the URL which is to be called by the HTTPClient inSwader\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.
EntityFactory¶
-
interface
Swader\Diffbot\Interfaces\
EntityFactory
¶ The EntityFactory interface is there as a contract for developing custom Entity Factories. For example, you may want to make sure that a call to an API returns specific entities rather than
Swader\Diffbot\Entity\Wildcard
, or some of the predefined ones likeSwader\Diffbot\Entity\Product
. A specific example would be having a custom API which processes a site with board game cards. Each card has a specific value at a specific location, and these values may correspond. Rather than manually process data inSwader\Diffbot\Entity\Wildcard
entities after a call to this custom API, you might want to define aGameCard
entity and give it fields and methods specific to the context. A custom entity factory is then used to bind the newly defined entity with the custom API.
createAppropriateIterator¶
Swader\Diffbot\Interfaces\EntityFactory::
createAppropriateIterator
($response)¶
Parametri:
- $response (GuzzleHttp\Message\ResponseInterface) – The response received from the API call. Must be of the GuzzleHttp v5 type. Automatic if the Guzzle client is used, but version 5 only.
Vraća: Returns the entity iterator containing the appropriate entities as built by the contents of
$response
.