Custom API¶
The Custom API is user defined in the Diffbot UI.
For a tutorial on creating a Custom API in the Diffbot UI, see here.
Custom API Class¶
-
class
Swader\Diffbot\Api\
Custom
¶ When you have a Custom API ready on Diffbot’s end, you instantiate the Custom API class and pass in the Custom API name, along with the URL to process. Everything from that point on is identical to the other APIs, except the fact that instead of specific entities being returned, all Custom API calls return an iterator of
Swader\Diffbot\Entity\Wildcard
entities.
__construct¶
Swader\Diffbot\Api\Custom::
__construct
($url, $name)¶
Parametri:
- $url (string) – The URL to process
- $name (string) – The name of the API
The construct method is identical to the one in
Swader\Diffbot\Abstracts\Api
with one difference - it also needs the name of the Custom API in question, so that it can build the API URL to which the call will be dispatched whenSwader\Diffbot\Abstracts\Api::call
is called:<?php require_once '../vendor/autoload.php'; use Swader\Diffbot\Diffbot; $diffbot = new Diffbot($my_token); $url = 'http://sitepoint.com/author/bskvorc'; $api = $diffbot->createCustomApi($url, "AuthorFolio"); $result = $api->call(); echo $result->getBio(); // "Bruno is a coder from Croatia..."In the example above, AuthorFolio is a custom API from this tutorial, which processes a SitePoint author’s portfolio. The
getBio
call works because of the magic methods inSwader\Diffbot\Abstracts\Entity
whichSwader\Diffbot\Entity\Wildcard
inherits.
Wildcard Entity Class¶
-
class
Swader\Diffbot\Entity\
Wildcard
¶ The Wildcard entity is returned when the type of a processed post does not match a type defined in the currently set EntityFactory (see
Swader\Diffbot\Factory\Entity
andSwader\Diffbot\Diffbot::setEntityFactory
).It is nothing more than a concretization of
Swader\Diffbot\Abstracts\Entity
and as such contains no additional methods.In the example above, the
getBio
method is called on a Wilcard instance, returned by the call to the AuthorFolio. custom API.