Skip to content

Commit

Permalink
Added onecall api support and data struct refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dnsimmons committed Jun 29, 2020
1 parent b45ecf6 commit bc58fa2
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 161 deletions.
121 changes: 20 additions & 101 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ OpenWeather is a [Laravel](https://laravel.com) package simplifying working with
The package supports the following free Open Weather Map APIs:

- [Current Weather](https://openweathermap.org/current)
- [5 Day 3 Hour Forecast](https://openweathermap.org/forecast5)
- [4 Day 3 Hour Forecast](https://openweathermap.org/api/hourly-forecast)
- [Onecall Forecast](https://openweathermap.org/api/one-call-api)
- 5 Day Historical (coming soon)

### Free API Limitations

- 60 calls/minute up to 1,000,000 calls/month
- 1000 calls/day when using Onecall requests

### Requirements

Expand Down Expand Up @@ -48,115 +55,25 @@ Publish the required package configuration file using the artisan command:
Edit the `config/openweather.php` file in your Laravel instance and modify the `api_key` value with your Open Weather Map api key (App ID).

return [
'api_key' => 'your-api-key',
'api_endpoint_current' => 'http://api.openweathermap.org/data/2.5/weather?',
'api_endpoint_forecast' => 'http://api.openweathermap.org/data/2.5/forecast?',
'api_lang' => 'en',
'api_key' => 'your-api-key',
'api_endpoint_current' => 'https://api.openweathermap.org/data/2.5/weather?',
'api_endpoint_forecast' => 'https://api.openweathermap.org/data/2.5/forecast?',
'api_endpoint_onecall' => 'https://api.openweathermap.org/data/2.5/onecall?',
'api_endpoint_icons' => 'https://openweathermap.org/img/w/',
'api_lang' => 'en',
'format_date' => 'm/d/Y',
'format_time' => 'h:i A',
'format_day' => 'l'
];

## Usage

### Current Weather
In the example below we fetch the current weather by postal code.

$weather = new OpenWeather();
$current = $weather->getCurrentWeatherByPostal('02111');
print_r($current);

**Output**

Array
(
[timestamp] => 1551160643
[location] => Array
(
[name] => Boston
[country] => US
[latitude] => 42.36
[longitude] => -71.06
)

[condition] => Array
(
[name] => Clear
[desc] => clear sky
[icon] => http://openweathermap.org/img/w/01n.png
)

[forecast] => Array
(
[temp] => 26
[temp_min] => 24
[temp_max] => 28
[pressure] => 1016
[humidity] => 42
[sunrise] => 1551180262
[sunset] => 1551220226
)

)

### 5 Day 3 Hour Forecast

$weather = new OpenWeather();
$forecast = $weather->getForecastWeatherByPostal('02111');
print_r($forecast);

**Output**

Array
(
[location] => Array
(
[name] => Boston
[country] => US
[latitude] => 42.3603
[longitude] => -71.0583
)

[forecast] => Array
(
[0] => Array
(
[timestamp] => 1551160800
[condition] => Array
(
[name] => Clear
[desc] => clear sky
[icon] => http://openweathermap.org/img/w/01n.png
)

[forecast] => Array
(
[temp] => 25
[temp_min] => 25
[temp_max] => 29
[pressure] => 1014
[humidity] => 100
)

)

[1] => Array
(
[timestamp] => 1551171600
[condition] => Array
(
[name] => Clear
[desc] => clear sky
[icon] => http://openweathermap.org/img/w/01n.png
)

[forecast] => Array
(
[temp] => 24
[temp_min] => 24
[temp_max] => 27
[pressure] => 1017
[humidity] => 100
)

)
...

## Methods

Expand All @@ -177,3 +94,5 @@ Units can be imperial (default), metric, or kelvin. All methods return an array
**getForecastWeatherByCoords**(*string $latitude*, *string $longitude*, *string $units*)

**getForecastWeatherByPostal**(*string $postal*, *string $units*)

**getOnecallWeatherByCoords**(*string $latitude*, *string $longitude*, *string $units*, *string $exclude*)
Loading

0 comments on commit bc58fa2

Please sign in to comment.