Ambassador is a small and extensible PHP 5.3 library which makes it easy to fetch and display data from various web services, like Twitter or Tumblr.
Notice: This library is not under active development anymore and may be deleted soonish.
Clone or download this repository. Move the /ambassador directory to your website or
application and include the bootstrap.php
file.
<?php
require 'ambassador/bootstrap.php';
use ambassador\core\Ambassador;
?>
Ambassador's default configuration should be fine in most cases. However, changing the configuration is easy:
Ambassador::config(array(
'cache_dir' => 'custom/path/to/cache',
'max_requests' => 2
));
The first step is to configure one or more adapters you want to use to fetch data. This is
done using Ambassador::add()
which takes three parameters:
- Name of the configuration. Can be anything but you should only use letters, digits and underscores since this will also be the name of the cache file.
- Name of the adapter you want to configure.
- Actual configuration of the adapter. The parameters may be different for every adapter but most will require at least one parameter (e.g. a Twitter username).
Example configuration for the Twitter adapter:
Ambassador::add('tweets', 'Twitter', array('name' => 'johndoe'));
After configuring an adapter you can use Ambassador::fetch()
to get the data.
$latest_tweets = Ambassador::fetch('tweets');
You may also fetch data from several adapters at once (great for creating activity streams).
Ambassador::add('tweets', 'Twitter', array('name' => 'johndoe'));
Ambassador::add('posts', 'Tumblr', array('name' => 'johndoe'));
$stream = Ambassador::fetch(array('tweets', 'posts'));
Creating your own adapters is easy. Please refer to the provided adapters for now, a detailed documentation will follow later.
Ambassador uses PHPUnit for testing. To run
all tests open a terminal, change to the /ambassador directory and enter $ phpunit tests
.
MIT License (see LICENSE file)