library web-resource
A PHP interface for fetching HTTP resources from the web
hubgit/web-resource
A PHP interface for fetching HTTP resources from the web
- Tuesday, January 17, 2017
- by aeaton
- Repository
- 1 Watchers
- 0 Stars
- 12 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 1 Forks
- 1 Open issues
- 4 Versions
- 0 % Grown
Composer
composer require hubgit/web-resource
Usage
See examples., (*1)
Fetch a single resource
use WebResource\Resource;
$resource = new Resource('https://api.spotify.com/v1/artists/0gusqTJKxtU1UTmNRMHZcv');
$artist = $resource->get(); // `$artist` is an array
Fetch a paginated collection
use WebResource\Collection;
$collection = new Collection('https://api.github.com/users/hubgit/repos');
foreach ($collection as $repo) {
// do something with the `$repo` array
}
Fetch a paginated collection with custom processing and pagination
use WebResource\Collection;
class SpotifyCollection extends Collection {
// find the array of items in the JSON response
protected function items($data, $response) {
return $data['items'];
}
// find the URL of the next page in the JSON response
protected function next($data, $response) {
return isset($data['next']) ? $data['next'] : null;
}
}
// first parameter is a URL, second parameter is an array of query parameters
$collection = new SpotifyCollection('https://api.spotify.com/v1/artists/0gusqTJKxtU1UTmNRMHZcv/albums', [
'album_type' => 'single',
]);
foreach ($collection as $album) {
// do something with the `$album` array
}
dev-master
9999999-dev
A PHP interface for fetching HTTP resources from the web
Sources
Download
MIT
The Requires
by
Alf Eaton
v0.4
0.4.0.0
A PHP interface for fetching HTTP resources from the web
Sources
Download
MIT
The Requires
by
Alf Eaton
v0.3
0.3.0.0
A PHP interface for fetching HTTP resources from the web
Sources
Download
MIT
The Requires
by
Alf Eaton
v0.2
0.2.0.0
A PHP interface for fetching HTTP resources from the web
Sources
Download
MIT
The Requires
by
Alf Eaton