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.

Swader\Diffbot\Interfaces\Api::setTimeout($timeout = 30000)
Parameters:
  • $timeout (int) – The timeout value in milliseconds. Defaults to 30000 (30 seconds)
Returns:

$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.

Swader\Diffbot\Interfaces\Api::call()
Returns: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 usually Swader\Diffbot\Entity\Wildcard entities, unless otherwise specified via a custom implementation of Swader\Diffbot\Interfaces\EntityFactory.

Swader\Diffbot\Interfaces\Api::buildUrl()
Returns: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 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.

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 like Swader\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 in Swader\Diffbot\Entity\Wildcard entities after a call to this custom API, you might want to define a GameCard 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.

Swader\Diffbot\Interfaces\EntityFactory::createAppropriateIterator($response)
Parameters:
  • $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.
Returns:

Swader\Diffbot\Entity\EntityIterator

Returns the entity iterator containing the appropriate entities as built by the contents of $response.