mirror of
https://github.com/holidayapi/holidayapi-php.git
synced 2025-06-21 04:16:31 +00:00
feat: include all endpoints
* Reworked interfacing to drop the versioning in the class name. * Refactored / cleaned up existing code. * Stuck with support for PHP 5.3+ since PHP 5.x still seems to hold majority. * Abstracted request logic to another class for mocking. * Added test suite and hit full code coverage. * Updated readme, included migration guide and the full gamut of examples. * Wired up travis-ci and coveralls for testing and coverage.
This commit is contained in:
parent
ad4f80f626
commit
e97edee508
12 changed files with 1024 additions and 94 deletions
215
README.md
215
README.md
|
@ -1,30 +1,211 @@
|
|||
# php-holidayapi
|
||||
Official PHP library for [Holiday API](https://holidayapi.com)
|
||||
# Holiday API PHP Library
|
||||
|
||||
[](https://github.com/holidayapi/holidayapi-php/blob/master/LICENSE)
|
||||

|
||||

|
||||
[](https://coveralls.io/github/holidayapi/holidayapi-php?branch=master)
|
||||
|
||||
Official PHP library for [Holiday API](https://holidayapi.com) providing quick
|
||||
and easy access to holiday information from applications written in PHP.
|
||||
|
||||
## Migrating from 1.x
|
||||
|
||||
Please note, version 2.x of this library is a full rewrite of the 1.x series.
|
||||
The interfacing to the library has been simplified and existing applications
|
||||
upgrading to 2.x will need to be updated.
|
||||
|
||||
| Version 1.x Syntax (Old) | Version 2.x Syntax (New) |
|
||||
|--------------------------------------------|-----------------------------------------------------------|
|
||||
| `$holiday_api = new \HolidayAPI\v1($key);` | `$holiday_api = new \HolidayAPI\Client(['key' => $key]);` |
|
||||
|
||||
Version 1.x of the library can still be found
|
||||
[here](https://github.com/joshtronic/php-holidayapi).
|
||||
|
||||
## Documentation
|
||||
|
||||
Full documentation of the Holiday API endpoints is available
|
||||
[here](https://holidayapi.com/docs).
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
composer require "joshtronic/php-holidayapi:dev-master"
|
||||
composer require holidayapi/holidayapi-php
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```php
|
||||
$hapi = new HolidayAPI\v1('_YOUR_API_KEY_');
|
||||
$key = 'Insert your API key here';
|
||||
$holiday_api = new \HolidayAPI\Client(['key' => $key]);
|
||||
|
||||
$parameters = array(
|
||||
// Required
|
||||
'country' => 'US',
|
||||
'year' => 2016,
|
||||
// Optional
|
||||
// 'month' => 7,
|
||||
// 'day' => 4,
|
||||
// 'previous' => true,
|
||||
// 'upcoming' => true,
|
||||
// 'public' => true,
|
||||
// 'pretty' => true,
|
||||
);
|
||||
try {
|
||||
// Fetch supported countries and subdivisions
|
||||
$countries = $holiday_api->countries();
|
||||
|
||||
$response = $hapi->holidays($parameters);
|
||||
// Fetch supported languages
|
||||
$languages = $holiday_api->languages();
|
||||
|
||||
// Fetch holidays with minimum parameters
|
||||
$holidays = $holiday_api->holidays([
|
||||
'country' => 'US',
|
||||
'year' => 2019,
|
||||
]);
|
||||
|
||||
var_dump($countries, $languages, $holidays);
|
||||
} catch (Exception $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Countries
|
||||
|
||||
#### Fetch all supported countries
|
||||
|
||||
```php
|
||||
$holiday_api->countries();
|
||||
```
|
||||
|
||||
#### Search for a country by code or name
|
||||
|
||||
```php
|
||||
$holiday_api->countries([
|
||||
'search' => 'united',
|
||||
]);
|
||||
```
|
||||
|
||||
### Languages
|
||||
|
||||
#### Fetch all supported languages
|
||||
|
||||
```php
|
||||
$holiday_api->languages();
|
||||
```
|
||||
|
||||
#### Search for a language by code or name
|
||||
|
||||
```php
|
||||
$holiday_api->languages([
|
||||
'search' => 'Chinese',
|
||||
]);
|
||||
```
|
||||
|
||||
### Holidays
|
||||
|
||||
#### Fetch holidays for a specific year
|
||||
|
||||
```php
|
||||
$holiday_api->holidays([
|
||||
'country' => 'US',
|
||||
'year' => 2019,
|
||||
]);
|
||||
```
|
||||
|
||||
#### Fetch holidays for a specific month
|
||||
|
||||
```php
|
||||
$holiday_api->holidays([
|
||||
'country' => 'US',
|
||||
'year' => 2019,
|
||||
'month' => 7,
|
||||
]);
|
||||
```
|
||||
|
||||
#### Fetch holidays for a specific day
|
||||
|
||||
```php
|
||||
$holiday_api->holidays([
|
||||
'country' => 'US',
|
||||
'year' => 2019,
|
||||
'month' => 7,
|
||||
'day' => 4,
|
||||
]);
|
||||
```
|
||||
|
||||
#### Fetch upcoming holidays based on a specific date
|
||||
|
||||
```php
|
||||
$holiday_api->holidays([
|
||||
'country' => 'US',
|
||||
'year' => 2019,
|
||||
'month' => 7,
|
||||
'day' => 4,
|
||||
'upcoming' => true,
|
||||
]);
|
||||
```
|
||||
|
||||
#### Fetch previous holidays based on a specific date
|
||||
|
||||
```php
|
||||
$holiday_api->holidays([
|
||||
'country' => 'US',
|
||||
'year' => 2019,
|
||||
'month' => 7,
|
||||
'day' => 4,
|
||||
'previous' => true,
|
||||
]);
|
||||
```
|
||||
|
||||
#### Fetch only public holidays
|
||||
|
||||
```php
|
||||
$holiday_api->holidays([
|
||||
'country' => 'US',
|
||||
'year' => 2019,
|
||||
'public' => true,
|
||||
]);
|
||||
```
|
||||
|
||||
#### Fetch holidays for a specific subdivision
|
||||
|
||||
```php
|
||||
$holiday_api->holidays([
|
||||
'country' => 'GB-ENG',
|
||||
'year' => 2019,
|
||||
]);
|
||||
```
|
||||
|
||||
#### Include subdivision holidays with countrywide holidays
|
||||
|
||||
```php
|
||||
$holiday_api->holidays([
|
||||
'country' => 'US',
|
||||
'year' => 2019,
|
||||
'subdivisions' => true,
|
||||
]);
|
||||
```
|
||||
|
||||
#### Search for a holiday by name
|
||||
|
||||
```php
|
||||
$holiday_api->holidays([
|
||||
'country' => 'US',
|
||||
'year' => 2019,
|
||||
'search' => 'New Year',
|
||||
]);
|
||||
```
|
||||
|
||||
#### Translate holidays to another language
|
||||
|
||||
```php
|
||||
$holiday_api->holidays([
|
||||
'country' => 'US',
|
||||
'year' => 2019,
|
||||
'language' => 'zh', // Chinese (Simplified)
|
||||
]);
|
||||
```
|
||||
|
||||
#### Fetch holidays for multiple countries
|
||||
|
||||
```php
|
||||
$holiday_api->holidays([
|
||||
'country' => 'US,GB,NZ',
|
||||
'year' => 2019,
|
||||
]);
|
||||
|
||||
$holiday_api->holidays([
|
||||
'country' => ['US', 'GB', 'NZ'],
|
||||
'year' => 2019,
|
||||
]);
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue