Download the PHP package rich2k/laravel-weatherkit without Composer
On this page you can find all versions of the php package rich2k/laravel-weatherkit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rich2k/laravel-weatherkit
More information about rich2k/laravel-weatherkit
Files in rich2k/laravel-weatherkit
Package laravel-weatherkit
Short Description Provides a Wrapper for the Apple WeatherKit API
License MIT
Homepage https://github.com/rich2k/laravel-weatherkit
Informations about the package laravel-weatherkit
Laravel WeatherKit
This provides a Laravel style wrapper for Apple's WeatherKit api, which replaced the DarkSky API.
For more information see https://developer.apple.com/weatherkit/get-started/
Please note, Apple requires attribution to use this API in your code https://developer.apple.com/weatherkit/get-started/#attribution-requirements and up to 500,000 calls/month are included with your apple developer account membership.
Install
Require this package with composer using the following command:
Providers
This library works out-of-the-box with Laravel's Service Providers and will be loaded automatically in Laravel >= 5.5
.
You can, of course, add it manually to your providers
array in config/app.php
if you'd prefer
Facade
To register a facade accessor, add the following to config/app.php
aliases
array
Configuration
See Authentication section on how to use these environment variables.
Variable name | Default | Description |
---|---|---|
WEATHERKIT_AUTH_TYPE |
jwt |
jwt or p8 token generation |
---------------------------- | --------------------------------- | --------------------------------- |
WEATHERKIT_JWT_TOKEN |
A pre-generated JWT token. | |
---------------------------- | --------------------------------- | --------------------------------- |
WEATHERKIT_KEY |
Path to the .p8 key file or key as a string |
|
WEATHERKIT_KEY_ID |
Key ID for you .p8 file |
|
WEATHERKIT_TEAM_ID |
Your Apple Team ID | |
WEATHERKIT_BUNDLE_ID |
Bundle ID of your App | |
WEATHERKIT_TOKEN_TTL |
3600 |
Expiry time of token in seconds |
---------------------------- | --------------------------------- | --------------------------------- |
WEATHERKIT_LANGUAGE_CODE |
config('app.locale', 'en') |
Language code |
WEATHERKIT_TIMEZONE |
config('app.timezone', 'UTC') |
Timezone for timestamps |
If you wish to change the default configuration, you can publish the configuration file to your project.
Authentication
There are two ways to authenticate with WeatherKit using this library. You'll need to generate the key file first for whichever method you choose.
Generate Key File
If you wish to generate and manage your own JWT Token yourself then you'll need to first generate a JWT token to access WeatherKit APIs.
You'll need to be enrolled in the paid Apple Developer Program, and register a new App ID and create a key.
Create new App ID
Create an App Identifier on the Identifiers section of your account. Enter a short description and give your app a unique bundle ID (e.g. com.myapp.weather).
Make sure you check the WeatherKit option under BOTH the Capabilities and App Services tabs. Click on Continue.
Create a Key
Go to the Keys page in your developer account.
Give the key a name, e.g. WeatherKit, and make sure to enable WeatherKit. Then click the Continue button. Then you'll be taken to a page with a Register button.
Remember to download the key file you get at the end!
Required Information
Whichever authentication method you decide to use, we are going to need some additional information first.
- You Apple Team ID
- The App Bundle ID that you created earlier (reverse DNS).
- The Key ID of the key, that you created in the Create new key section, you can get this at any point after generation.
- The physical key file ending in
.p8
you downloaded.
Manual JWT Token Generation
Once you've generated and downloaded your .p8
key file above, we now need to generate your JWT token and public/private keys
Create your private key in a PEM format using openssl
openssl pkcs8 -nocrypt -in AuthKey_ABC1235XS.p8 -out AuthKey_ABC1235XS.pem
Note: the option -nocrypt
is required!
A public key is also required for signing JWT tokens
openssl ec -in AuthKey_ABC1235XS.pem -pubout > AuthKey_ABC1235XS.pub
You should now have two files, a public and a private key. These will be used to sign your JWT token.
Use a JWT token generator such as https://jwt.io/
For the header you want
The payload
E.g.
Copy and paste your private and public key into the signature verification, and the output is what you need to add to your configuration WEATHERKIT_JWT_TOKEN
.
Configuration
Add the following lines to the .env file:
Dynamic Token Generation
Starting with library version >=1.2
you can dynamically generate your JWT token direct
Configuration
Add the following lines to the .env file:
Usage
For full details of response formats, visit: https://developer.apple.com/documentation/weatherkitrestapi/get_api_v1_weather_language_latitude_longitude
There are two endpoints available at present, availability and weather.
Availability allows you to retrieve which data sets are available for a given location. If you call the availability function before the weather one, we will automatically set the requested datasets to this available.
availability()
and weather()
functions will return their results as a Laravel Collection
Required
location(lat, lon)
Pass in latitude and longitude coordinates for a basic response
Optional Parameters
language(lang)
Pass in a language code to return text based responses in the requested language. By default this is en_US
dataSets([])
Specify which data sets to use to reduce data transfer.
By default we will try to call 'currentWeather', 'forecastDaily', 'forecastHourly', 'forecastNextHour'
, however you can set these manually with dataSets()
function. You can also dynamically set this by calling availability()
before weather()
when not using through a facade.
currentAsOf(t)
Pass in a Carbon object of time to obtain current conditions. Defaults to now.
dailyStart(t)/dailyEnd(t)
dailyStart()
: The time to start the daily forecast. If this parameter is absent, daily forecasts start on the current day.
dailyEnd()
: The time to end the daily forecast. If this parameter is absent, daily forecasts run for 10 days.
hourlyStart(t)/hourlyEnd(t)
hourlyStart()
: The time to start the hourly forecast. If this parameter is absent, hourly forecasts start on the current hour.
hourlyEnd()
: The time to end the hourly forecast. If this parameter is absent, hourly forecasts run 24 hours or the length of the daily forecast, whichever is longer.
timezone(timezone)
The name of the timezone to use for rolling up weather forecasts into daily forecasts. Defaults to unset, as this is not required unless calling daily forecasts
Helpers
The following are shorthand helpers to add readability equivalent to using dataSets
set to a single object.
For example, these two statements are the same
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-weatherkit with dependencies
ext-json Version *
ext-openssl Version *
firebase/php-jwt Version ~5.5|^6.3
guzzlehttp/guzzle Version ~7.0
illuminate/support Version ~7.0|~8.0|~9.0|~10.0|~11.0
nesbot/carbon Version ~1.0|~2.0|~3.4