cbzink / launchlibrary
An unofficial SDK for Launch Library 2.
Requires
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.9
- mockery/mockery: ^1.5
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-12-06 23:11:40 UTC
README
A simple SDK for interacting with the Launch Library 2 API.
Table of Contents
Requirements
- PHP >= 7.4
- A LL2 API token (Optional)
Installation
Install this library via Composer.
composer require cbzink/launchlibrary
Usage
Setup
Instantiate an instance of the LL2 class
use cbzink\LaunchLibrary\LL2; $client = new LL2($apiToken, $apiEndpoint);
Pagination limits
You can change the pagination limit (default 10
) using setPaginationLimit
.
$client->setPaginationLimit(30); $client->getPaginationLimit() // (int) 30
Resources
Currently available resources include Agencies, Astronauts, Docking Events, Events, Expeditions, Launchers, Launches, Locations, Pads, Space Stations, and Spacecraft.
Searching for resources
You can search for resources using the parameters specified in the LL2 API docs.
$results = $client->agencies()->search([ 'country_code' => 'US', ]);
Pagination
Searches are often paginated. An array of resources is available under the results
property, and next()
and previous()
methods are available for moving through pagination.
$agencies = $client->agencies()->search(); // Array of Agency resources. $resources = $agencies->results; // Fetch the next page of results $agencies = $agencies->next();
Retrieving resources
You can retrieve detailed resources by their ID.
$results = $client->agencies()->fetch(123);
Special cases
Events and Launches
Events and Launches have additional Previous and Upcoming endpoints you can access using the SDK. search()
and fetch()
are available on both.
// Previous $results = $client->events()->previous()->search(); // Upcoming $results = $client->launches()->upcoming()->search();
Spacecraft
Spacecraft have an additional Flights endpoint you can access using the SDK. search()
and fetch()
are available on both.
$results = $client->spacecraft()->flights()->search();
Acknowledgements
Inspiration for the design of this SDK was taken from laravel/forge-sdk and KnpLabs/php-github-api.
License
Launch Library 2 SDK for PHP is open source software licensed under the MIT license.