hamhamfonfon/astrobin-ws

Astrobin WebServices for PHP projects


README

Latest Stable Version Total Downloads License CI Status codecov.io

Astrobin API REST的WebServices

目录

版本 2.6.2

需求

  • PHP 8.2 最小版本或更高(旧版本不再支持)
  • Astrobin 的 API 密钥和 API 密码来自 Astrobin

介绍

Astrobin WebServices 是一个用于请求 Astrobin API REST 并获取在 Astrobin 上托管的美妙天体摄影的 PHP 库。请阅读“服务条款”中的 API 部分 "服务条款"

安装

您可以通过两种不同的方式安装此软件包。

  • 基本安装;只需从 composer 安装包

composer require hamhamfonfon/astrobin-ws

更新到最新版本

composer update hamhamfonfon/astrobin-ws

如果您正在使用旧版本的 PHP

  • 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

注意,这些版本不再维护。只有 2.6.* 版本将得到维护并将有新功能。

  • 如果您只想提出一些问题、做一些简单的测试等,只需克隆仓库

git clone git@github.com:HamHamFonFon/Astrobin-Webservices.git

使用

首先,将您的密钥设置在 .env 文件中

ASTROBIN_API_KEY=PutHereYourOwnApiKey
ASTROBIN_API_SECRET=PutHereYourOwnApiSecret

无框架示例

# 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');

有 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

该库公开了 3 个 WebServices,每个 WebServices 都有下面的方法。

GetImage

可以在 getImageBy() 中使用的过滤器列表

GetTodayImage

GetCollection

参数 $limit 是必需的,并且必须是整数。

GetUser

响应

图片

图片列表

收藏集

收藏集列表

今天

用户

贡献

我接受贡献,请fork该项目并提交 pull 请求。

错误和问题

如果您发现一些错误或对 Astrobin-WebServices 有任何疑问,请打开一个 issue,我会尽快回答您。

为调试安装包

检索代码源

从 GitHub 克隆仓库

git clone git@github.com:HamHamFonFon/Astrobin-WebServices.git

运行 docker

构建、编译并启动 docker 容器

docker-compose build --no-cache
docker-compose up -d
docker exec -ti php_astrobin_ws bash

安装

安装依赖

composer install

运行 Rector

# Init
./vendor/bin/rector init

# Run
./vendor/bin/rector process src --dry-run

运行 PHP CodeSnifer

php ./vendor/bin/phpcs -p -n --standard=PSR12 src

应用 PHPCBF(修复和美化 PHPCS 错误)

php ./vendor/bin/phpcbf src/path/to/file.php

作者

Stéphane Méaudre - balistik.fonfon@gmail.com - 2023

许可

本项目采用 MIT 许可证 - 详细信息请参阅 LICENSE.md 文件

其他版本