api-clients / travis
Async first TravisCI PHP API Client
Installs: 50 692
Dependents: 1
Suggesters: 1
Security: 0
Stars: 6
Watchers: 5
Forks: 4
Open Issues: 3
Requires
- php: ^7.0
- api-clients/client-services: ^1.3
- api-clients/foundation: ^1.0
- api-clients/middleware-json: ^3.0
- api-clients/middleware-token-authorization: ^3.0
- api-clients/middleware-user-agent: ^2.0
- api-clients/pusher: ^1.0
- api-clients/rx: ^2.2
- api-clients/rx-operators: ^2.0
- api-clients/transport: ^3.0
Requires (Dev)
Suggests
- api-clients/middleware-delay: Add a delay between requests to not hammer Travis
- api-clients/middleware-pool: Keep your request count under control
This package is auto-updated.
Last update: 2024-10-15 19:42:33 UTC
README
Install
To install via Composer, use the command below, it will automatically detect the latest version and bind it with ^
.
composer require api-clients/travis
Usage
The client needs two things, the ReactPHP event loop, and optionally an authentication token. Once you created the client you can call the user
method to show the currently authenticated user.
use React\EventLoop\Factory; use ApiClients\Client\Travis\AsyncClient; use ApiClients\Client\Travis\Resource\UserInterface; use function ApiClients\Foundation\resource_pretty_print; $loop = Factory::create(); $client = AsyncClient::create( $loop, 'your travis key from https://blog.travis-ci.com/2013-01-28-token-token-token/' ); $client->user()->then(function (UserInterface $user) { resource_pretty_print($user); }); $loop->run();
Results stream
The above example used a promise, when there is more then one result an observabe is returned instead. RxPHP
is used for the observables. This means you can apply a huge list of methods to the stream of results
use React\EventLoop\Factory; use ApiClients\Client\Travis\AsyncClient; use ApiClients\Client\Travis\Resource\BroadcastInterface; use function ApiClients\Foundation\resource_pretty_print; $loop = Factory::create(); $client = AsyncClient::create($loop, 'your key'); $client->broadcasts()->subscribe(function (BroadcastInterface $broadcast) { resource_pretty_print($broadcast); }); $loop->run();
Synchronous usage
The synchronous client works nearly the same as the asynchronous, infact it wraps the asynchronous client to do all the work. This examples does the same as the asynchronous usage example.
use ApiClients\Client\Travis\Client; use function ApiClients\Foundation\resource_pretty_print; $client = Client::create('your travis key'); resource_pretty_print($client->user());
Synchronous results stream
Synchronous results streams are returned as an array.
use ApiClients\Client\Travis\Client; use function ApiClients\Foundation\resource_pretty_print; $client = Client::create('your travis key'); foreach ($client->broadcasts() as $broadcast) { resource_pretty_print($broadcast); };
Examples
The examples
directory is filled with all kinds of examples for this package.
License
The MIT License (MIT)
Copyright (c) 2017 Cees-Jan Kiewiet
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.