This is a simple package that allows access to the Here Developer Weather API using a (mostly) fluent API.
Package create for Here Developer Weather
Documentation - https://developer.here.com/documentation/weather/topics/overview.html
Install the package using composer:
$ composer require medeirosdev/weather-here-developer
At the moment we only have framework compatibility for Laravel. However, we welcome PRs to add further framework specific behavior as long as it doesn't prevent the package working for others
If you are using Laravel then you can use our service provider. If you have Laravel >5.5 then the package
will be auto discovered upon install. Else, add the following to your config/app.php file:
'providers' => [
...
\MedeirosDev\WeatherHereDeveloper\Frameworks\Laravel\WeatherHereDeveloperServiceProvider::class,
]If you are using Laravel >5.5 then the facade will
be automatically discovered. Else, you can add it in your config/app.php file.
'aliases' => [
...
'WeatherHereDeveloper' => \MedeirosDev\WeatherHereDeveloper\Frameworks\Laravel\WeatherHereDeveloper::class,
]First, make sure you have copied the configuration file:
$ php artisan vendor:publish --tag=config --provider="MedeirosDev\WeatherHereDeveloper\Frameworks\Laravel\WeatherHereDeveloperServiceProvider"
This will make a config/here_developer.php file, this is where your API Key / License information is fetched from.
By default we use the .env configuration values to get your API key.
Use the App ID and App Code then you should add
the following to your .env:
HERE_DEVELOPER_APP_ID=MY-APP-ID
HERE_DEVELOPER_APP_CODE=MY-APP-CODE
Please, make sure you don't store your keys in version control!
Before making requests you need to create your License object. You will need is your API key, then you can create your license as follows:
$license = new License($appId, $appCode);Then, you can start making your request:
$request = new WeatherHereDeveloper($license);
// or
$request = WeatherHereDeveloper::license($license);
// or Laravel framework license is auto generated
$request = new WeatherHereDeveloper();$response = WeatherHereDeveloper::license($license)
->setProduct(Product::OBSERVATION)
->setLanguage(Language::PORTUGUESE_BR)
->setLocation(Location::byName('Campinas - SP - Brazil'))
->request();
// Get description of first node
$response->nodes[0]->description
// Or get description of first node based json response
$response->observations->location[0]->observaton[0]->description$response = (new WeatherHereDeveloper)
->setProduct(Product::OBSERVATION)
->setLanguage(Language::PORTUGUESE_BR)
->setLocation(Location::byName('Campinas - SP - Brazil'))
->request();- Product::
OBSERVATION - Product::
FORECAST_7DAYS - Product::
FORECAST_7DAYS_SIMPLE - Product::
FORECAST_HOURLY - Product::
FORECAST_ASTRONOMY - Product::
ALERTS - Product::
NWS_ALERTS
- Unit::
METRIC - Unit::
IMPERIAL
- Location::
byLatitudeLongitude($latitude, $longitude) - Location::
byName($cityOrOtherName) - Location::
byZipcode($zipcode)
src/Entities/Language.php
$response = WeatherHereDeveloper::license($license)
->setProduct(Product::OBSERVATION)
->setLanguage(Language::PORTUGUESE_BR)
->setLocation(Location::byName('Campinas - SP - Brazil'))
->request();
$observations = $response->nodes;$response = WeatherHereDeveloper::license($license)
->setProduct(Product::OBSERVATION)
->setLanguage(Language::PORTUGUESE_BR)
->setLocation(Location::byName('Campinas - SP - Brazil'))
->setOneObservation()
->request();
$observation = $response->nodes[0];$response = WeatherHereDeveloper::license($license)
->setProduct(Product::FORECAST_7DAYS)
->setLanguage(Language::PORTUGUESE_BR)
->setLocation(Location::byName('Campinas - SP - Brazil'))
->setOneObservation()
->request();
$node = $response->nodes[0];$response = WeatherHereDeveloper::license($license)
->setProduct(Product::OBSERVATION)
->setLocation(Location::byLatitudeLongitude('-22.907104', '-47.063240'))
->request();$response = WeatherHereDeveloper::license($license)
->setProduct(Product::OBSERVATION)
->setLocation(Location::byZipcode('13000-000'))
->request();$response = WeatherHereDeveloper::license($license)
->setProduct(Product::OBSERVATION)
->setLocation(Location::byZipcode('13000-000'))
->useImperial()
->request();