mirror of
https://github.com/holidayapi/holidayapi-perl6.git
synced 2025-06-21 04:36:32 +00:00
initial version, tested locally with my API key
This commit is contained in:
parent
ae616db8a7
commit
b7d4f9fa05
1 changed files with 40 additions and 0 deletions
40
README.md
40
README.md
|
@ -1,2 +1,42 @@
|
||||||
# perl6-holidayapi
|
# perl6-holidayapi
|
||||||
Official Perl 6 library for Holiday API
|
Official Perl 6 library for Holiday API
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Required module
|
||||||
|
|
||||||
|
``` perl6
|
||||||
|
$ zef install HTTP::UserAgent
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Retrieve holidays for a single year and country (result is a single
|
||||||
|
JSON file):
|
||||||
|
|
||||||
|
|
||||||
|
```perl6
|
||||||
|
use HTTP::UserAgent
|
||||||
|
|
||||||
|
my $ua = HTTP::UserAgent.new;
|
||||||
|
$ua.timeout = 10;
|
||||||
|
|
||||||
|
my $HOLAPI-KEY = 'my-key';
|
||||||
|
my $data-location = 'https://holidayapi.com/v1/holidays';
|
||||||
|
my $options = '&pretty';
|
||||||
|
my $year = 2017;
|
||||||
|
my $country = 'US';
|
||||||
|
my $json-data = "holiday-data-{$country}-{$year}.json";
|
||||||
|
|
||||||
|
my $query = "key={$HOLAPI-KEY}{$options}&country={$country}&year={$year}";
|
||||||
|
my $api-uri = "{$data-location}?{$query}";
|
||||||
|
my $response = $ua.get($api-uri);
|
||||||
|
if $response.is-success {
|
||||||
|
say "Working year '$year'...";
|
||||||
|
spurt $json-data, $response.content;
|
||||||
|
say "See JSON data file '$json-data'.";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
die $response.status-line;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue