line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FixerIO::API; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
72515
|
use 5.006; |
|
2
|
|
|
|
|
8
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
50
|
|
5
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
6
|
2
|
|
|
2
|
|
1628
|
use HTTP::Tiny; |
|
2
|
|
|
|
|
109858
|
|
|
2
|
|
|
|
|
94
|
|
7
|
2
|
|
|
2
|
|
1497
|
use JSON 'decode_json'; |
|
2
|
|
|
|
|
22121
|
|
|
2
|
|
|
|
|
10
|
|
8
|
2
|
|
|
2
|
|
261
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
608
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
FixerIO::API - Access to the fixer.io currency exchange rate API. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.1.0 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.1.0'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use FixerIO::API; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $access_key = ; |
28
|
|
|
|
|
|
|
my $fixer = FixerIO::API->new( $access_key ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# get latest data |
31
|
|
|
|
|
|
|
my $ld = $fixer->latest; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use DDP hash_max=>5; |
34
|
|
|
|
|
|
|
p $ld, as=>"Latest Data:"; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Will print, |
37
|
|
|
|
|
|
|
Latest Data: |
38
|
|
|
|
|
|
|
{ |
39
|
|
|
|
|
|
|
success 1 (JSON::PP::Boolean), |
40
|
|
|
|
|
|
|
base "EUR", |
41
|
|
|
|
|
|
|
date "2023-09-03" (dualvar: 2023), |
42
|
|
|
|
|
|
|
timestamp 1693764783, |
43
|
|
|
|
|
|
|
rates { |
44
|
|
|
|
|
|
|
AED 3.965325, |
45
|
|
|
|
|
|
|
AFN 79.575894, |
46
|
|
|
|
|
|
|
ALL 108.330797, |
47
|
|
|
|
|
|
|
AMD 418.325847, |
48
|
|
|
|
|
|
|
ANG 1.954454, |
49
|
|
|
|
|
|
|
(...skipping 165 keys...) |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This is a Perl module for accessing the API provided by fixer.io. See, F<"http://fixer.io/documentation">. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This module doesn't export anything. Nor does it keep any data, other than your API access key. Your script will keep or do what it wants with the data. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
You have to obtain your own API key from the fixer.io web site. There is a free option. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 IMPLEMENTED ENDPOINTS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Please note that depending on your subscription plan, certain API endpoints may not be available. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 LATEST RATES |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Returns real-time exchange rate data for all available or a specific set of currencies. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Specifying symbols is not implemented. Changing the base is not implemented. The etags optimization is not implemented. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 EXPORT |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
No exports. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 new |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Instantiate a new API access object. Pass in your API access key as an argument. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub new { |
84
|
2
|
|
|
2
|
1
|
1480
|
my $class = shift; |
85
|
2
|
|
|
|
|
2
|
my $access_key = shift; |
86
|
2
|
100
|
|
|
|
8
|
return undef unless defined $access_key; |
87
|
1
|
|
|
|
|
5
|
return bless \$access_key, $class; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 api_call |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Perform the HTTP(S) request, return the response data. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub api_call { |
97
|
1
|
|
|
1
|
1
|
2
|
my ($self, $options, $defaults) = @_; |
98
|
1
|
|
|
|
|
10
|
my $ua = HTTP::Tiny->new( |
99
|
|
|
|
|
|
|
agent => sprintf '%s/%s ', 'FixerIO-API', $VERSION |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
my %options = ( |
102
|
1
|
|
|
|
|
3
|
%{$defaults}, |
103
|
1
|
|
|
|
|
134
|
%{$options}, |
|
1
|
|
|
|
|
5
|
|
104
|
|
|
|
|
|
|
); |
105
|
1
|
|
|
|
|
4
|
my $url = "http://data.fixer.io/api/latest?access_key=$$self"; |
106
|
1
|
|
|
|
|
9
|
while (my ($k, $v) = each %options) { |
107
|
1
|
|
|
|
|
7
|
$url .= sprintf '&%s=%s', $k, $v; # values always have no spaces |
108
|
|
|
|
|
|
|
} |
109
|
1
|
|
|
|
|
26
|
my $resp = $ua->get($url); |
110
|
1
|
50
|
|
|
|
204372
|
return $resp->{'content'} if $resp->{'success'}; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
#TODO: Handle HTTP exceptions |
113
|
0
|
|
|
|
|
0
|
croak 'HTTP Error!? How can that be?'; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 latest |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Return the latest data. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub latest { |
123
|
1
|
|
|
1
|
1
|
412
|
my ($self, %options) = @_; |
124
|
1
|
|
|
|
|
4
|
my $defaults = {format => 1}; |
125
|
1
|
|
|
|
|
3
|
my $json = $self->api_call( \%options, $defaults ); |
126
|
1
|
|
|
|
|
25
|
my $data = decode_json( $json );# could die |
127
|
1
|
|
|
|
|
7
|
return $data; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 INSTALLATION |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
To install this module, run the following commands: |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
perl Makefile.PL |
135
|
|
|
|
|
|
|
make |
136
|
|
|
|
|
|
|
make test |
137
|
|
|
|
|
|
|
make install |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 AUTHOR |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Harry Wozniak, C<< >> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 BUGS |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
146
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
147
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 SUPPORT |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
perldoc FixerIO::API |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
You can also look for information at: |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over 4 |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * CPAN Ratings |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * Search CPAN |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=back |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This software is copyright (c) 2023 by Harry Wozniak. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
183
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
'That is all.'; |