File Coverage

lib/EveOnline/Api.pm
Criterion Covered Total %
statement 16 18 88.8
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 24 91.6


line stmt bran cond sub pod time code
1             package EveOnline::Api;
2              
3 1     1   16801 use strict;
  1         3  
  1         36  
4 1     1   5 use warnings;
  1         1  
  1         25  
5 1     1   11 use v5.12;
  1         6  
  1         66  
6 1     1   524 use HTTP::Request::Common qw(POST);
  1         23607  
  1         80  
7 1     1   720 use LWP::UserAgent;
  1         17986  
  1         33  
8 1     1   272 use XML::Simple;
  0            
  0            
9             use Time::Local;
10             use Moose;
11             use namespace::autoclean;
12             use EveOnline::Character;
13             use EveOnline::CharacterInfo;
14             use EveOnline::AccountStatus;
15             use EveOnline::SkillQueue;
16             use EveOnline::Contact;
17              
18             =head1 NAME
19              
20             EveOnline::Api - the Perl version of the Eve Online API system.
21              
22             =head1 VERSION
23              
24             Version 0.05
25              
26             =cut
27              
28             our $VERSION = '0.05';
29              
30             has 'apiroot' => (
31             is => 'rw',
32             isa => 'Str',
33             default => 'https://api.eveonline.com'
34             );
35              
36             has 'keyid' => (
37             is => 'rw',
38             isa => 'Int'
39             );
40              
41             has 'vcode' => (
42             is => 'rw',
43             isa => 'Str'
44             );
45              
46             =head1 SYNOPSYS
47              
48             my $eve = EveOnline::Api->new(keyid => 'XXXXXXX', vcode => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
49              
50             # return char list
51             my @list = $eve->get_character_list();
52              
53             =head1 DESCRIPTION
54              
55             The module allows to programatically access to the Eve Online Game API system. Currently, there are several methods available for
56             information retieval and this module only cover a few o them.
57              
58             =head1 SUBROUTINES/METHODS
59              
60             =head2 get_character_list
61              
62             Access the complete character list of a given account. Returns a list of Character objects.
63            
64             my @list = $eve->get_characer_list();
65              
66             =cut
67              
68             sub get_character_list {
69             my $self = shift;
70             #my $keyID = shift;
71             #my $vCode = shift;
72              
73             my $path = '/account/Characters.xml.aspx';
74             my $char = undef;
75              
76             my $text = &connect($self, $self->keyid, $self->vcode, $path, $char);
77              
78             my $xml = XMLin($text, KeepRoot => 1, KeyAttr => {rowset => '+name', row => '+characterID'}, ForceArray => [ 'row' ]);
79             $xml->{eveapi}{$xml->{eveapi}{result}{rowset}{name}} = $xml->{eveapi}{result}{rowset}; delete $xml->{eveapi}{result};
80              
81             my @result;
82              
83             for my $id ( keys %{ $xml->{eveapi}{characters}{row} } ) {
84              
85             my $char = EveOnline::Character->new();
86            
87             $char->name($xml->{eveapi}{characters}{row}{$id}{name});
88             $char->characterID($xml->{eveapi}{characters}{row}{$id}{characterID});
89             $char->corporationID($xml->{eveapi}{characters}{row}{$id}{corporationID});
90             $char->corporationName($xml->{eveapi}{characters}{row}{$id}{corporationName});
91             $char->allianceID($xml->{eveapi}{characters}{row}{$id}{allianceID});
92             $char->allianceName($xml->{eveapi}{characters}{row}{$id}{allianceName});
93             $char->factionID($xml->{eveapi}{characters}{row}{$id}{factionID});
94             $char->factionName($xml->{eveapi}{characters}{row}{$id}{factionName});
95             $char->cachedUntil($xml->{eveapi}->{cachedUntil});
96              
97             push(@result, $char);
98              
99             }
100              
101             return \@result;
102             }
103              
104             =head2 get_char_info_list
105              
106             Access the descritive information from a character. Returns a list of CharacterInfo objects.
107              
108             my @list = $eve->get_char_info_list();
109              
110             =cut
111              
112             sub get_char_info_list {
113             my $self = shift;
114             my $charlist = shift;
115              
116             my @charlist = @{$charlist};
117             my @charinfolist;
118             my $path = '/eve/CharacterInfo.xml.aspx';
119              
120             for my $char ( @charlist ) {
121              
122             my $text = &connect($self, $self->keyid, $self->vcode, $path, $char);
123             my $xml = XMLin($text, KeepRoot => 1);
124             my $charinfo = EveOnline::CharacterInfo->new();
125             my $data = $xml->{eveapi}->{result};
126              
127             while ( my ($key, $value) = each(%$data) ) {
128              
129             $charinfo->characterID($value) if $key eq 'characterID';
130             $charinfo->characterName($value) if $key eq 'characterName';
131             $charinfo->race($value) if $key eq 'race';
132             $charinfo->bloodline($value) if $key eq 'bloodline';
133             $charinfo->accountBalance($value) if $key eq 'accountBalance';
134             $charinfo->skillPoints($value) if $key eq 'skillPoints';
135             $charinfo->shipName($value) if $key eq 'shipName';
136             $charinfo->shipTypeID($value) if $key eq 'shipTypeID';
137             $charinfo->shipTypeName($value) if $key eq 'shipTypeName';
138             $charinfo->corporationID($value) if $key eq 'corporationID';
139             $charinfo->corporation($value) if $key eq 'corporation';
140             $charinfo->corporationDate($value) if $key eq 'corporationDate';
141             $charinfo->allianceID($value) if $key eq 'allianceID';
142             $charinfo->alliance($value) if $key eq 'alliance';
143             $charinfo->allianceDate($value) if $key eq 'allianceDate';
144             $charinfo->lastKnownLocation($value) if $key eq 'lastKnownLocation';
145             $charinfo->securityStatus($value) if $key eq 'securityStatus';
146             $charinfo->cachedUntil($xml->{eveapi}->{cachedUntil});
147              
148             }
149            
150             push(@charinfolist, $charinfo);
151             }
152              
153             return \@charinfolist;
154              
155             }
156              
157             =head2 get_account_status
158              
159             Access the status of the account. Returns an AccountStatus object.
160            
161             my $obj = $eve->get_account_status();
162              
163             =cut
164              
165             sub get_account_status {
166             my $self = shift;
167              
168             my $path = '/account/AccountStatus.xml.aspx';
169             my $char = undef;
170              
171             my $text = &connect($self, $self->keyid, $self->vcode, $path, $char);
172             my $obj = EveOnline::AccountStatus->new();
173             my $xml = XMLin($text, KeepRoot => 1);
174             my $data = $xml->{eveapi}->{result};
175            
176             while ( my ($key, $value ) = each (%$data) ) {
177              
178             $obj->paidUntil($value) if $key eq 'paidUntil';
179             $obj->createDate($value) if $key eq 'createDate';
180             $obj->logonCount($value) if $key eq 'logonCount';
181             $obj->logonMinutes($value) if $key eq 'logonMinutes';
182              
183             }
184              
185             $obj->cachedUntil($xml->{eveapi}->{cachedUntil});
186              
187             return $obj;
188             }
189              
190              
191             sub get_char_skill_queue {
192             my $self = shift;
193             my $charlist = shift;
194              
195             # TODO #
196              
197             my @charlist = @{$charlist};
198             my @skillQueueList;
199             my $path = '/char/SkillQueue.xml.aspx';
200              
201             for my $char ( @charlist ) {
202            
203             my $text = &connect($self, $self->keyid, $self->vcode, $path, $char);
204              
205             my $xml = XMLin($text, KeepRoot => 1);
206              
207             my $obj;
208              
209             for my $id ( keys %{ $xml->{eveapi}{result}{rowset}{row} } ) {
210            
211             $obj = EveOnline::SkillQueue->new();
212              
213             $obj->characterID($char->characterID);
214             $obj->queuePosition($xml->{eveapi}{result}{rowset}{row}{queuePosition});
215             $obj->typeID($xml->{eveapi}{result}{rowset}{row}{typeID});
216             $obj->level($xml->{eveapi}{result}{rowset}{row}{level});
217             $obj->startSP($xml->{eveapi}{result}{rowset}{row}{startSP});
218             $obj->endSP($xml->{eveapi}{result}{rowset}{row}{endSP});
219             $obj->startTime($xml->{eveapi}{result}{rowset}{row}{startTime});
220             $obj->endTime($xml->{eveapi}{result}{rowset}{row}{endTime});
221             $obj->cachedUntil($xml->{eveapi}->{cachedUntil});
222             }
223              
224             push(@skillQueueList, $obj);
225            
226             }
227            
228             return \@skillQueueList;
229             }
230              
231             sub get_contact_list {
232             my $self = shift;
233             my $charlist = shift;
234              
235             my @charlist = @{$charlist};
236             my $path = '/char/ContactList.xml.aspx';
237              
238             # TODO #
239              
240             # my $text = &connect($self, $keyID, $vCode, $path, $char);
241             # my $obj = EveOnline::Contact->new();
242             # my $xml = XMLin($text, KeepRoot => 1);
243             # my $data = $xml->{eveapi}->{result};
244              
245             return;
246             }
247              
248             #=head2 connect
249              
250             #This is the most impotant method of the API. The method recieves the API keys and verification codes from the class and execute a request to the Eve Server.
251              
252             #=cut
253              
254             sub connect {
255             my ($self, $keyID, $vCode, $path, $char) = @_;
256              
257             my $ua = LWP::UserAgent->new;
258             my $req;
259              
260             if ( $char ) {
261              
262             $req = POST $self->apiroot.$path, [ keyID => $keyID, vCode => $vCode, characterID => $char->characterID ];
263              
264             } else {
265            
266             $req = POST $self->apiroot.$path, [ keyID => $keyID, vCode => $vCode ];
267              
268             }
269              
270             my $res = $ua->request($req);
271              
272             unless ( $res->is_success ) {
273              
274             die "Error: " . $res->status_line . "\n";
275              
276             }
277              
278             my $text = $res->decoded_content;
279            
280             return $text;
281             }
282              
283             1;
284              
285             =head1 AUTHOR
286              
287             Felipe da Veiga Leprevost, C<< <leprevost@cpan.org> >>
288              
289             =head1 BUGS
290              
291             Please report any bugs or feature requests to C<bug-myapp at rt.cpan.org>, or through
292             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MyApp>. I will be notified, and then you'll
293             automatically be notified of progress on your bug as I make changes.
294              
295             =head1 SUPPORT
296              
297             You can find documentation for this module with the perldoc command.
298              
299             perldoc EveOnline::Api
300              
301              
302             You can also look for information at:
303              
304             =over 4
305              
306             =item * RT: CPAN's request tracker (report bugs here)
307              
308             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=EveOnline-Api>
309              
310             =item * AnnoCPAN: Annotated CPAN documentation
311              
312             L<http://annocpan.org/dist/EveOnline-Api>
313              
314             =item * CPAN Ratings
315              
316             L<http://cpanratings.perl.org/d/EveOnline-Api>
317              
318             =item * Search CPAN
319              
320             L<http://search.cpan.org/dist/EveOnline-Api/>
321              
322             =back
323              
324              
325             =head1 ACKNOWLEDGEMENTS
326              
327              
328             =head1 LICENSE AND COPYRIGHT
329              
330             Copyright 2014 Felipe da Veiga Leprevost.
331              
332             This program is free software; you can redistribute it and/or modify it
333             under the terms of the the Artistic License (2.0). You may obtain a
334             copy of the full license at:
335              
336             L<http://www.perlfoundation.org/artistic_license_2_0>
337              
338             Any use, modification, and distribution of the Standard or Modified
339             Versions is governed by this Artistic License. By using, modifying or
340             distributing the Package, you accept this license. Do not use, modify,
341             or distribute the Package, if you do not accept this license.
342              
343             If your Modified Version has been derived from a Modified Version made
344             by someone other than you, you are nevertheless required to ensure that
345             your Modified Version complies with the requirements of this license.
346              
347             This license does not grant you the right to use any trademark, service
348             mark, tradename, or logo of the Copyright Holder.
349              
350             This license includes the non-exclusive, worldwide, free-of-charge
351             patent license to make, have made, use, offer to sell, sell, import and
352             otherwise transfer the Package with respect to any patent claims
353             licensable by the Copyright Holder that are necessarily infringed by the
354             Package. If you institute patent litigation (including a cross-claim or
355             counterclaim) against any party alleging that the Package constitutes
356             direct or contributory patent infringement, then this Artistic License
357             to you shall terminate on the date that such litigation is filed.
358              
359             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
360             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
361             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
362             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
363             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
364             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
365             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
366             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
367              
368              
369             =cut
370              
371             1; # End of EveOnline::Api