hamhamfonfon / astrobin-ws
Astrobin WebServices for PHP projects
Requires
- php: >=8.2.0
- ext-ctype: *
- ext-json: *
- guzzlehttp/guzzle: ^7.5
Requires (Dev)
- dg/bypass-finals: ^1.4
- phpunit/phpunit: ^10.0
- rector/rector: ^0.15.23
- squizlabs/php_codesniffer: 3.*
- dev-master
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.6
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.6
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.0
- 1.0.1
- 0.9.
- 0.8.0
- dev-update-php-8-2
- dev-pr-post-2.5.5
- dev-fix-typo-post-2.5.4
- dev-fix-typo-post-2.5.5
- dev-update-cpackage-rector
- dev-add-properties-views-and-likes
- dev-upgrade-php8.1
- dev-update-to-php74
- dev-fix-images-id-error
- dev-add-user-webservice
- dev-add-filters-for-image-webservices
- dev-add-histogram-and-skyplot
This package is auto-updated.
Last update: 2024-12-13 12:41:47 UTC
README
WebServices for Astrobin's API REST
Table of contents
- Requirements
- Introduction
- Installing
- WebServices
- Responses
- Running the tests
- Contributes
- Bugs and issues
- Authors
- Licence
Version 2.6.2
Requirements
- PHP 8.2 min or superior (oldest versions are no longer supported)
- API Key and API Secret from Astrobin
Introduction
Astrobin's WebServices is a PHP library for request Astrobin's API Rest and get amazing astrophotographies hosted on Astrobin. Please read API section in "Terms of service"
Installing
You can install this package in 2 different ways.
- Basic installation; just install package from composer :
composer require hamhamfonfon/astrobin-ws
Update to the newest version :
composer update hamhamfonfon/astrobin-ws
If you're using old PHP versions:
- PHP 8.1
composer require hamhamfonfon/astrobin-ws:2.5
- PHP 7.4 | 8.0
composer require hamhamfonfon/astrobin-ws:2.4
- PHP 7.3
composer require hamhamfonfon/astrobin-ws:2.3
Caution, these versions are not maintained anymore. Only 2.6.* will be maintained and will have new features.
- If you just want to make some issues, make some simple tests etc, juste clone the repository
git clone git@github.com:HamHamFonFon/Astrobin-Webservices.git
Usage
First, set your keys in .env file :
ASTROBIN_API_KEY=PutHereYourOwnApiKey ASTROBIN_API_SECRET=PutHereYourOwnApiSecret
Example without framework:
# Get variables $astrobinApiKey = getenv('ASTROBIN_API_KEY'); $astrobinApiSecret = getenv('ASTROBIN_API_SECRET'); # Get data from Astrobin $imageWs = new GetImage($astrobinApiKey, $astrobinApiSecret); $astrobinImage = $imageWs->getById('astrobinImageId');
Example with Symfony:
parameters: astrobinApiKey: '%env(ASTROBIN_API_KEY)%' astrobinApiSecret: '%env(ASTROBIN_API_SECRET)%' # default configuration for services in *this* file _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. bind: $astrobinApiKey: '%astrobinApiKey%' $astrobinApiSecret: '%astrobinApiSecret%'
use AstrobinWs\Response\DTO\AstrobinResponse;use AstrobinWs\Services\GetImage; final class MyImageService { private GetImage $astrobinImage; /** * MyImageService constructor. * @param string|null $astrobinApiKey * @param string|null $astrobinApiSecret */ public function __construct(?string $astrobinApiKey, ?string $astrobinApiSecret) { $this->astrobinImage = new GetImage($astrobinApiKey, $astrobinApiSecret); } public function getImageById(): ?AstrobinResponse { return $this->astrobinImage->getImageById('1234'); } public function getOrionNebula(): ?AstrobinResponse { $orionNebula = $this->astrobinImage->getImagesBySubject('m42', 10); // ... return $orionNebula; } public function getImagesOfSiovene(): ?AstrobinResponse { $imagesBySiovene = $this->astrobinImage->getImagesByUser('siovene', 10); return $imagesBySiovene; } public function getImagesByManyFilters(): ?AstrobinResponse { $filters = [ 'user' => 'toto', 'subjects' => 'm31', 'description__icontains' => 'wind' ]; $listImages = $this->astrobinImage->getImageBy($filters, 10); return $listImages; } }
WebServices
The library expose 3 WebServices, each with these methods below.
GetImage :
List of filters that can be used in getImageBy()
:
GetTodayImage :
GetCollection :
Parameter $limit
is mandatory and must be an integer.
GetUser
Responses
Image
ListImage
Collection
ListCollection
Today
User
Contributes
I accept contributions, please fork the project and submit pull requests.
Bugs and issues
In case you find some bugs or have question about Astrobin-WebServices, open an issue and I will answer you as soon as possible.
Install package for debugging
Retrieve code-source
Clone repository from GitHub
git clone git@github.com:HamHamFonFon/Astrobin-WebServices.git
Run docker
Build, compile and up docker container
docker-compose build --no-cache
docker-compose up -d
docker exec -ti php_astrobin_ws bash
Installation
Install dependencies
composer install
Run Rector
# Init ./vendor/bin/rector init # Run ./vendor/bin/rector process src --dry-run
Run PHP CodeSnifer
php ./vendor/bin/phpcs -p -n --standard=PSR12 src
Apply PHPCBF (fix and beautify PHPCS errors):
php ./vendor/bin/phpcbf src/path/to/file.php
Authors
Stéphane Méaudre - balistik.fonfon@gmail.com - 2023
Licence
This project is licensed under the MIT License - see the LICENSE.md file for details