iankok/surf-forecast-api-client

surf-forecast.com 的抓取器包装器 SDK

1.0.6 2019-04-03 01:18 UTC

This package is auto-updated.

Last update: 2024-09-29 05:08:49 UTC


README

一个用于从 surf-forecast 获取波浪信息 的 PHP 库。

安装

composer require iankok/surf-forecast-api-client

特性

  • 完全异步,速度极快
  • 按国家搜索
  • 服务提供商,可在 Laravel 中使用
  • 一切皆按照 DDD 设计。因此,每次调用都返回一个类型化的类数组。如果您需要不同的变量:请随意提交 PR 或分支。

示例

它应该非常容易使用并在 Laravel 中实现。请确保将 IanKok\SurfForecastApiClient\SurfForecastApiClientServiceProvider:class, 添加到您的 app.php 中的 providers 部分;

最终示例是如何利用此包的异步功能。

// Get the 48 hrs forcast for canggu
$client = new SurfForecastClient('http://www.surf-forecast.com/');
$forecastRepository = new ForecastRepository($client, new ForecastMapper());
$forecastRepository->get48HrsAsync('Canggu')->wait();


// Get all available Countries
$countryRepository = new CountryRepository($client, new CountryMapper());
$countryRepository->listAsync()->wait();

// Get all wavebreaks by country id and their forecasts
$waveBreakRepository = new WaveBreakRepositoryAdapter(
    new WaveBreakMapper(new Dom()),
    new RegionMapper(new Dom()),
    $client,
    new ResponseInterpreter()
);
$waveBreaks = $waveBreakRepository->getByCountryIdAsync('213')->wait()
$foreCasts = array_map(function ($waveBreak) {
        return $forecastRepository->get48HrsAsync($waveBreak->getSlug);
    },$waveBreaks
)
all($foreCasts)->wait();
$foreCasts = array_map(function ($waveBreak) {
    return $waveBreak->wait();
    }, $waveBreaks
)