A simple PHP wrapper for making requests to the API of TheBigDB.com. Full API documentation.
First, you need to initialize the class with:
require("thebigdb.php");
$thebigdb = new TheBigDB;
The following actions return a dict object from the parsed JSON the server answered.
Search (api doc)
# Usage: $thebigdb->search($nodes, $other_params = array());
$thebigdb->search(array("subject" => array("match" => "James"), "property" => "job", "answer" => "President of the United States"));
$thebigdb->search(array("subject" => "London", "property" => "population"), array("period" => array("on" => "2007-06-05")));
$thebigdb->search("iPhone"); # will fulltext search "iPhone" in all fields
Create (api doc)
# Usage: $thebigdb->create($nodes, $other_params = array());
$thebigdb->create(array("subject" => "iPhone 5", "property" => "weight", "answer" => "112 grams"));
$thebigdb->create(array("subject" => "Bill Clinton", "property" => "job", "answer" => "President of the United States"), array("period" => array("from" => "1993-01-20 12:00:00", "to" => "2001-01-20 12:00:00")))
$thebigdb->show("id-of-the-sentence");
$thebigdb->upvote("id-of-the-sentence"); # don't forget to set your API key
$thebigdb->downvote("id-of-the-sentence"); # don't forget to set your API key
That's it!
Each action returns an object translating the JSON answered by the server.
Example:
# Will print the id of the first statement matching that search
$response = $thebigdb->search(array("subject" => array("match" => "James"), "property" => "job", "answer" => "President of the United States"));
var_dump($response->statements[0]->id);
You can access other parts of the API in the same way as statements:
# $thebigdb->user($action, $params);
# Examples
$response = $thebigdb->user("show", array("login" => "christophe"));
$response->user->karma;
- PHP 5.2+
- curl extension
Don't hesitate to send a pull request !
This software is distributed under the MIT License. Copyright (c) 2013, Christophe Maximin [email protected]