Giter VIP home page Giter VIP logo

openweather-laravel-api's Introduction

Laravel Open Weather API

Packagist GitHub stars GitHub forks GitHub issues GitHub license

Laravel OpenWeather API (openweather-laravel-api) is a Laravel package to connect Open Weather Map APIs ( https://openweathermap.org/api ) and access free API services (current weather, weather forecast, weather history) easily.

Supported APIs

APIs Get data by
Current Weather By city name, city ID, geographic coordinates, ZIP code
One Call API By geographic coordinates
4 Day 3 Hour Forecast By city name, city ID, geographic coordinates, ZIP code
5 Day Historical By geographic coordinates
Air Pollution By geographic coordinates
Geocoding API By geographic coordinates

Installation

Install the package through Composer. On the command line:

composer require rakibdevs/openweather-laravel-api

Configuration

If Laravel > 7, no need to add provider

Add the following to your providers array in config/app.php:

'providers' => [
    // ...
    RakibDevs\Weather\WeatherServiceProvider::class,
],
'aliases' => [
    //...
    'Weather' => RakibDevs\Weather\Weather::class,	
];

Add API key and desired language in .env

OPENWEATHER_API_KEY=
OPENWEATHER_API_LANG=en

Publish the required package configuration file using the artisan command:

	$ php artisan vendor:publish

Edit the config/openweather.php file and modify the api_key value with your Open Weather Map api key.

	return [
	    'api_key' 	        => env('OPENWEATHER_API_KEY', ''),
    	    'onecall_api_version' => '2.5',
            'historical_api_version' => '2.5',
            'forecast_api_version' => '2.5',
            'polution_api_version' => '2.5',
            'geo_api_version' => '1.0',
	    'lang' 		=> env('OPENWEATHER_API_LANG', 'en'),
	    'date_format'       => 'm/d/Y',
	    'time_format'       => 'h:i A',
	    'day_format'        => 'l',
	    'temp_format'       => 'c'         // c for celcius, f for farenheit, k for kelvin
	];

Now you can configure API version from config as One Call API is upgraded to version 3.0. Please set available api version in config.

Usage

Here you can see some example of just how simple this package is to use.

use RakibDevs\Weather\Weather;

$wt = new Weather();

$info = $wt->getCurrentByCity('dhaka');    // Get current weather by city name

Access current weather data for any location on Earth including over 200,000 cities! OpenWeather collect and process weather data from different sources such as global and local weather models, satellites, radars and vast network of weather stations

// By city name
$info = $wt->getCurrentByCity('dhaka'); 

// By city ID - download list of city id here http://bulk.openweathermap.org/sample/
$info = $wt->getCurrentByCity(1185241); 

// By Zip Code - string with country code 
$info = $wt->getCurrentByZip('94040,us');  // If no country code specified, us will be default

// By coordinates : latitude and longitude
$info = $wt->getCurrentByCord(23.7104, 90.4074);

Output:

{
  "coord": {
    "lon": 90.4074
    "lat": 23.7104
  }
  "weather":[
    0 => { 
      "id": 721
      "main": "Haze"
      "description": "haze"
      "icon": "50d"
    }
  ]
  "base": "stations"
  "main": {
    "temp": 26
    "feels_like": 25.42
    "temp_min": 26
    "temp_max": 26
    "pressure": 1009
    "humidity": 57
  }
  "visibility": 3500
  "wind": {
    "speed": 4.12
    "deg": 280
  }
  "clouds": {
    "all": 85
  }
  "dt": "01/09/2021 04:16 PM"
  "sys": {
    "type": 1
    "id": 9145
    "country": "BD"
    "sunrise": "01/09/2021 06:42 AM"
    "sunset": "01/09/2021 05:28 PM"
  }
  "timezone": 21600
  "id": 1185241
  "name": "Dhaka"
  "cod": 200
}

Make just one API call and get all your essential weather data for a specific location with OpenWeather One Call API.

// By coordinates : latitude and longitude
$info = $wt->getOneCallByCord(23.7104, 90.4074);

4 day forecast is available at any location or city. It includes weather forecast data with 3-hour step.

// By city name
$info = $wt->get3HourlyByCity('dhaka'); 

// By city ID - download list of city id here http://bulk.openweathermap.org/sample/
$info = $wt->get3HourlyByCity(1185241); 

// By Zip Code - string with country code 
$info = $wt->get3HourlyByZip('94040,us');  // If no country code specified, us will be default

// By coordinates : latitude and longitude
$info = $wt->get3HourlyByCord(23.7104, 90.4074);

Get access to historical weather data for the previous 5 days.

// By coordinates : latitude, longitude and date
$info = $wt->getHistoryByCord(23.7104, 90.4074, '2020-01-09');

Air Pollution API provides current, forecast and historical air pollution data for any coordinates on the globe

Besides basic Air Quality Index, the API returns data about polluting gases, such as Carbon monoxide (CO), Nitrogen monoxide (NO), Nitrogen dioxide (NO2), Ozone (O3), Sulphur dioxide (SO2), Ammonia (NH3), and particulates (PM2.5 and PM10).

Air pollution forecast is available for 5 days with hourly granularity. Historical data is accessible from 27th November 2020.

// By coordinates : latitude, longitude and date
$info = $wt->getAirPollutionByCord(23.7104, 90.4074);

Geocoding API is a simple tool that we have developed to ease the search for locations while working with geographic names and coordinates. -> Direct geocoding converts the specified name of a location or area into the exact geographical coordinates; -> Reverse geocoding converts the geographical coordinates into the names of the nearby locations.

// By city name
$info = $wt->getGeoByCity('dhaka');

// By coordinates : latitude, longitude and date
$info = $wt->getGeoByCity(23.7104, 90.4074);
  • 60 calls/minute
  • 1,000,000 calls/month
  • 1000 calls/day when using Onecall requests

License

Laravel Open Weather API is licensed under The MIT License (MIT).

openweather-laravel-api's People

Contributors

joshuadegier avatar rakibdevs avatar waghabond avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

openweather-laravel-api's Issues

I see this problem

Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires rakibdevs/openweather-laravel-api ^1.0 -> satisfiable by rakibdevs/openweather-laravel-api[v1.0].
- rakibdevs/openweather-laravel-api v1.0 requires guzzlehttp/guzzle ^7 -> found guzzlehttp/guzzle[dev-master, 7.0.0-beta.1, ..., 7.2.0] but it conflicts with your root composer.json require (^6.3).

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Read.me, about .env keys

Hi, I don't know where to put this comment, so on 'Issues' is an easy place. What do you think about changing OPENWAETHER_API_KEY and OPENW_AE_THER_API_LANG to OPENWEATHER_API_KEY and OPENWEATHER_API_LANG?
In short, changing AE to EA.
Thank you for your great work.

Upgrade to 3.0 API

When I first tried I got "Invalid API key" and it seems my newly created account is only valid for the newer 3.0 API. After changing 2.5 to 3.0 in the $url in WeatherClient everything works fine. I guess maybe this should be a config option?

error to install

i try to install i run only composer require rakibdevs/openweather-laravel-api
and recive this message
There was no api_key specified. You must provide a valid API KEY to get weather data from Open Weather.

I got error message when a ran compose update

Hi ! I got error message when a ran compose update (laravel 7)
ErrorException

Undefined property: stdClass::$date_format

at G:\server\htdocs\my-project\vendor\rakibdevs\openweather-laravel-api\src\Weather.php:110

I couldnt find any fixes, maybe you already have a solution?? Thanks in advance

Wrong cities

After I try to get a weather of an not existing city, a page with json "cod" : "404" etc. is forced and i can't change it. Is there a way to work around it?

One Call API Historical data json response schema has canged in version 3.0

The One Call API's historical data schema has changed as of version 3.0 are there any plans to add support for this?

for reference: https://openweathermap.org/api/one-call-api#history
vs: https://openweathermap.org/api/one-call-3#history

The TLDR of the change is that now it returns only the data for the specified timestamp under the "data" field in the JSON response. previously this data was in the "current" field of the JSON response and there was also an additional hourly field with hourly data for the day.

WeatherException.php does not comply with psr-4 autoloading standard

Hi,

Great package, thanks!

When installing this package by composer, I got the error
Class RakibDevs\Weather\Src\Exceptions\WeatherException located in ./vendor/rakibdevs/openweather-laravel-api/src/Exceptions/WeatherException.php does not comply with psr-4 autoloading standard. Skipping.

It looks like it is because of the wrong namespace:
RakibDevs\Weather\Src\Exceptions;

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.