Package Data | |
---|---|
Maintainer Username: | rjvandoesburg |
Maintainer Contact: | rjvandoesburg@gmail.com (Robert-John van Doesburg) |
Package Create Date: | 2017-05-19 |
Package Last Update: | 2017-05-19 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:15:09 |
Package Statistics | |
---|---|
Total Downloads: | 255 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This package adds a facade and a dependency injectable class you can use to make easy calls to the api
You can install the package via composer:
composer require rjvandoesburg/laravel-apixu-client
You must install the following service provider:
// config/app.php
'providers' => [
...
Rjvandoesburg\Apixu\ApixuServiceProvider::class,
...
];
This package requires an API key that can be stored in the .env
file. You can get your key here: https://www.apixu.com/
The following settings are available for your .env
file:
APIXU_KEY={your-key-here}
APIXU_URL=https://api.apixu.com/v1
APIXU_CACHE_LENGTH=30
The cache length is how long before new data is fetched from the server, this because you might want to limit the API calls
These settings are set in a config file that you can edit yourself, should you desire to do so. Execute the following command to get the config file
php artisan vendor:publish --provider="Rjvandoesburg\Apixu\ApixuServiceProvider"
A file named apixu.php
will be created in the config directory.
The API has 4 endpoint
Each request needs certain parameters, read more about those here
To build op the filters you need to use a FiltersClass and all parameters you can set for the API are defined as properties. To use the facade to get the current weather, use the following:
$filters = new \Rjvandoesburg\Apixu\Filters([
'q' => 'London',
]);
$response = \Apixu::current($filters);
This will return a CurrentResponse
which contains all properties returned.
You can use this response to easily output the response.
The available methods are:
\Apixu::current($filters);
\Apixu::forecast($filters);
\Apixu::history($filters);
\Apixu::search($filters);
or use the dependency injection method
public function getWeather(\Rjvandoesburg\Apixu\ApixuClient $apixu)
{
$filters = new \Rjvandoesburg\Apixu\Filters([
'q' => 'London',
]);
return $apixu->current($filters)
}
The MIT License (MIT). Please see License File for more information.