承接 lfischer/open-weather-map-api 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lfischer/open-weather-map-api

Composer 安装命令:

composer require lfischer/open-weather-map-api

包简介

A simple PHP library for querying the Open Weather Map API.

关键字:

README 文档

README

This library will help you integrate the Open Weather Map API to your webservice. It is lightweight and provides all necessary code including a lot of convenience methods.

Quick start

Using the API is very easy - you'll only need to provide a API key (Get one here) in order to use it. There are endpoints for retrieving different weather data by predefined conditions, like "by country and city", "by latitude and longitude", "by airport code" or even "by IP address".

Simply create a API instance and get the endpoint you need. These endpoints will contain convenience methods with typed parameters to receive the desired data.

use lfischer\openWeatherMap\API;

// Get weather data by a city and (optional) country name.
$weather = (new API('<API-key here>'))
    ->getCurrentWeather()
    ->byCityName('Dusseldorf,Germany');

// Get weather data by a "city ID".
$weather = (new API('<API-key here>'))
    ->getCurrentWeather()
    ->byCityId(524901);

Default options

Most endpoints can define a language to get API responses in your language. For more details scroll down :)

By default you will receive an array with the data you like. Some endpoints can be used with different modes like "XML" and "HTML".

Also it is possible to use different units like "metric" and "imperial".

API endpoints for data collection

The goal is to implement PHP classes for every data collection API endpoint. The main API class has accessor methods for each available endpoint.

  • $api->getClimateForecast() returns an instance of ClimateForecastEndpoint.
  • $api->getCurrentWeather() returns an instance of CurrentWeatherEndpoint.
  • $api->getHourlyForecast() returns an instance of HourlyForecastEndpoint.
  • $api->getDailyForecast() returns an instance of DailyForecastEndpoint.
  • $api->getOneCall() returns an instance of OneCallEndpoint.

Sadly some endpoints require a paid subscription which I don't have. If anyone likes to contribute or test the affected endpoints please let me know!

More convenience

The API client provides convenience methods and classes to set different modes (xml, json or html), units (metric or imperial) or languages (49 languages available).

Use the constants located in Mode, Unit and Language to get the correct values and autocompletion in your IDE.

// Get weather data by a city and (optional) country name.
use lfischer\openWeatherMap\API;
use lfischer\openWeatherMap\Parameter\Language;
use lfischer\openWeatherMap\Parameter\Mode;
use lfischer\openWeatherMap\Parameter\Unit;

$weather = (new API('<API-key here>'))
    ->getCurrentWeather()
    ->setMode(Mode::XML)
    ->setUnit(Unit::METRIC)
    ->setLanguage(Language::ENGLISH)
    ->byCityName('Dusseldorf,Germany');

Different Request options

The API client can use three different request adapters, according to your environment and possible other libraries.

cURL

In case you can not use file_get_contents, you can use the 'Curl' request adapter. For this your environment needs to provide the curl PHP extension.

Dump

The Dump request adapter can be used to return the prepared URL in case you have your own request library to work with. This is also used for testing.

Guzzle

If you are a fan of the great Guzzle library, you can use this adapter and make use of all its great features :)

Simple

The 'Simple' request adapter makes use of file_get_contents (just as the previous versions). For this adapter you will need to activate the fopen wrappers.

Response types

According to the mode option the response will be returned in a different Response class. Every response type has a getResponse method that returns the specific set of data.

  • HtmlResponse->getResponse() returns a string
  • JsonResponse->getResponse() returns a array
  • XmlResponse->getResponse() returns a SimpleXMLElement

Each type also contains a getRawResponse method which will return the raw string response from the API, in case you'd like to process the response on your own.

Contribution

As mentioned before I do not have a paid subscription in order to develop and test every data collection. For this I need YOUR help ;)

If anyone likes to contribute or test the affected endpoints please let me know!

lfischer/open-weather-map-api 适用场景与选型建议

lfischer/open-weather-map-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 140 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 02 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「weather」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 lfischer/open-weather-map-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 lfischer/open-weather-map-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 lfischer/open-weather-map-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 140
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-01