marcelomx / zemanta
Zemanta PHP API
Installs: 219
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 1
pkg:composer/marcelomx/zemanta
Requires
- php: >= 5.3.3
- guzzle/guzzle: v3.7.4
Requires (Dev)
- phpunit/phpunit: 3.7
This package is not auto-updated.
Last update: 2016-12-14 22:47:57 UTC
README
More info about API and to retrieve API key, see http://developer.zemanta.com
Usage:
use Zemanta\Zemanta;
$zemanta = new Zemanta('your_api_key');
$params = array(
'method' => 'zemanta.suggest',
'text' => 'Your text'
);
$suggest = $zemanta->api($params);
The api method also support API method parameter as first argument and optional API parameters as array in second or third argument.
$params = array('format' => 'json');
$zemanta->api('zemanta.suggest', $params);
// or with text
$zemanta->api('zemanta.suggest', 'Your text', $params);
To suggest and suggestMarkup API methods, you could use the direct methos on Zemanta instance.
// Suggest
$response = $zemanta->suggest('Your text');
// Markup
$response = $zemanta->suggestMarkup('Your text');
To request with raw parameters, use request method with array of parameters.
$args = array(
'method' => 'zemanta.suggest',
'text' => 'Your text',
'format' => 'json'
)
$response = $zemanta->request($args);
The API supports json, wnjson, xml and rdfxml as ouput formats. If format parameter is not informed, xml format is used as default.
Either api or request method returns a Zemanta\Response instance. To print or parse raw response body, you could use getBody method.
echo $response->getBody();
// Zemanta\Response supports __toString() magic method, so you could print it direct.
echo $response;
To json format, you could export response to array.
$array = $response->toArray();