Giter VIP home page Giter VIP logo

astrobin-webservices's Introduction

Latest Stable Version Total Downloads License CI Status codecov.io

WebServices for Astrobin's API REST

Table of contents

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 [email protected]: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 :

Function name Parameter Response
getById() $id Image
getImageById() $id Image
getImagesBySubject() $subjectId $limit ListImage,Image
getImagesByTitle() $title $limit ListImage,Image
getImagesByDescription() $description $limit ListImage,Image
getImagesByUser() $userName $limit ListImage,Image
getImagesByRangeDate() $dateFromStr (ex: 2018-04-01), $dateToStr (2018-04-31 or null) ListImage,Image
getImageBy() $filters $limit ListImage,Image
getImageById() is an alias of getById() for version 1.0.0. retro-compatibility.

List of filters that can be used in getImageBy() :

Filter name Comment
subjects Used in getImagesBySubject() method, search by subject
user Used in getImagesByUser() method, search by username
title__icontains Used in getImagesByTitle() method, search by case-insensitive, partial title
description__icontains Used in getImagesByDescription() method, search by case-insensitive, partial description
__startswith
__endswith
__contains
__istartswith
__iendswith

GetTodayImage :

Function name Parameter Response
getDayImage() $offset , limit = 1 ListToday
getTodayImage() Today

GetCollection :

Function name Parameter Response
getById() $id Collection
DEPRECATED getCollectionByUser() $user,$limit ListCollection

Parameter $limit is mandatory and must be an integer.

GetUser

Function name Parameter Response
getById() $id User
getByUername() $username User
/!\ For all webservices, parameter $id must be a string and not an integer or float.

Responses

Image

Parameter Description
title Title of image
subjects Keywords
description Description
url_gallery URL of image for gallery
url_thumb URL of image , thumb size
url_regular URL of image
user Username
url_histogram URL to histogram
url_skyplot URL to skyplot
url_solution
url_advanced_skyplot_small URL to advanced skyplot
views Count of views
likes Count of likes

ListImage

Parameter Description
listImages List of images

Collection

Parameter Description
id Identifier
name Name of collection
description Description
user User name
date_created Date of creation
date_updated Date of modification
images Path of WS Image

ListCollection

Parameter Description
listCollection List of collection with list of images

Today

Parameter Description
date Date of image (Y-m-d format)
image instance of Image::class as today
resource_uri URI of today image

User

Parameter Description
id
username
avatar
about
image_count
job
hobbies
language
website

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 [email protected]: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 - [email protected] - 2023

Licence

This project is licensed under the MIT License - see the LICENSE.md file for details

Other versions

astrobin-webservices's People

Contributors

astro-otter-space avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

astrobin-webservices's Issues

Change variable env

In .env file, change keys name "API_" by "ASTROBIN_API_" and change it in code

Replace components

  • Replace Guzzle by HttpClient symfony component
  • Refactoring hydrattion with Serializer symfony component

Update README

Update install procedure with composer only :

composer require hamhamfonfon/astrobin-ws

Add others filters for search

Create a new method getImageBy(...$filters, $limit) with the possibility of theses filters :

  • __startswith=

  • __endswith=

  • __contains=

  • __istartswith=

  • __iendswith=

  • __lt=

  • __lte=

  • __gt=

  • __gte=

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.