rgsystemes / apimapper
API wrapper
Installs: 34 999
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- php: >=5.6
- kriswallsmith/buzz: 1.2.0
Requires (Dev)
- phpunit/phpunit: 6.5.*
README
ApiMapper is a simple wrapper arround Buzz to perform API calls.
Dependencies
This library requires pecl_http to be installed and enabled.
Using APT (Debian/Ubuntu) :
sudo apt-get install -y php-pecl-http
Using PEAR :
sudo pecl install --alldeps pecl_http
Getting started
<?php $browser = new Buzz\Browser(); $mapper = new ApiMapper\ApiMapper($browser, 'https://api.baseurl.com/api'); $mapper->addEventListener(new AuthenticationListener($sessionManager)); $mapper->addQueryParameter('apiKey', new ApiKeyProvider('someApiKey')); $mapper->addRouteParameter('{token}', new AuthenticationProvider($sessionManager)); // https://api.baseurl.com/api/auth?apiKey=someApiKey&userName=$userName&password=$password $response = $mapper->get('auth', array( "userName" => $userName, "password" => $password )); // There is no need here to provide the token since it has been // wrapped when calling auth. // https://api.baseurl.com/api/1234/some/obscure/12/route $response = $mapper->get('{token}/some/obscure/{someId}/route', array( "{someId}" => 12 ));