Api.pm

filter: Statementstmt 30.1% 47 / 156 Branchbran 0.0% 0 / 50 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 14 / 20 Podpod 50.0% 3 / 6 totaltotal 27.5% 64 / 232 CC 30 SCAR 51.9
CC
30
Cov
23%
get_char_info_list
420.0
get_account_status
42.0
get_char_skill_queue
12.0
CRAP 178.6
↑ Summary AccountStatus.pm »
1 package EveOnline::Api;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use HTTP::Request::Common qw(POST);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use EveOnline::Character;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use EveOnline::CharacterInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use EveOnline::AccountStatus;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use EveOnline::SkillQueue;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use EveOnline::Contact;
Subroutine BEGIN: called CC=1 SCAR=0.0
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.051
25  
26 =cut
27  
28 1 our $VERSION = '0.051';
29  
30 1 has 'apiroot' => (
31 is => 'rw',
32 isa => 'Str',
33 default => 'https://api.eveonline.com'
34 );
35  
36 1 has 'keyid' => (
37 is => 'rw',
38 isa => 'Int'
39 );
40  
41 1 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 0 ▶sub get_character_list {
Subroutine get_character_list: not called CC=2 SCAR=17.9
Pod documented
69 0 my $self = shift;
70 #my $keyID = shift;
71 #my $vCode = shift;
72  
73 0 my $path = '/account/Characters.xml.aspx';
74 0 my $char = undef;
75  
76 0 my $text = &connect($self, $self->keyid, $self->vcode, $path, $char);
77  
78 0 my $xml = XMLin($text, KeepRoot => 1, KeyAttr => {rowset => '+name', row => '+characterID'}, ForceArray => [ 'row' ]);
79 0 $xml->{eveapi}{$xml->{eveapi}{result}{rowset}{name}} = $xml->{eveapi}{result}{rowset}; delete $xml->{eveapi}{result};
80  
81 0 my @result;
82  
83 0 for my $id ( keys %{ $xml->{eveapi}{characters}{row} } ) {
84  
85 0 my $char = EveOnline::Character->new();
86
87 0 $char->name($xml->{eveapi}{characters}{row}{$id}{name});
88 0 $char->characterID($xml->{eveapi}{characters}{row}{$id}{characterID});
89 0 $char->corporationID($xml->{eveapi}{characters}{row}{$id}{corporationID});
90 0 $char->corporationName($xml->{eveapi}{characters}{row}{$id}{corporationName});
91 0 $char->allianceID($xml->{eveapi}{characters}{row}{$id}{allianceID});
92 0 $char->allianceName($xml->{eveapi}{characters}{row}{$id}{allianceName});
93 0 $char->factionID($xml->{eveapi}{characters}{row}{$id}{factionID});
94 0 $char->factionName($xml->{eveapi}{characters}{row}{$id}{factionName});
95 0 $char->cachedUntil($xml->{eveapi}->{cachedUntil});
96  
97 0 push(@result, $char);
98  
99 }
100  
101 0 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 0 ▶sub get_char_info_list {
Subroutine get_char_info_list: not called CC=20 SCAR=60.4
Pod documented
113 0 my $self = shift;
114 0 my $charlist = shift;
115  
116 0 my @charlist = @{$charlist};
117 0 my @charinfolist;
118 0 my $path = '/eve/CharacterInfo.xml.aspx';
119  
120 0 for my $char ( @charlist ) {
121  
122 0 my $text = &connect($self, $self->keyid, $self->vcode, $path, $char);
123 0 my $xml = XMLin($text, KeepRoot => 1);
124 0 my $charinfo = EveOnline::CharacterInfo->new();
125 0 my $data = $xml->{eveapi}->{result};
126  
127 0 ▶ while ( my ($key, $value) = each(%$data) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$data) 0 0 0
128  
129 0 ▶ $charinfo->characterID($value) if $key eq 'characterID';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "characterID" 0 0 0
130 0 ▶ $charinfo->characterName($value) if $key eq 'characterName';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "characterName" 0 0 0
131 0 ▶ $charinfo->race($value) if $key eq 'race';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "race" 0 0 0
132 0 ▶ $charinfo->bloodline($value) if $key eq 'bloodline';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "bloodline" 0 0 0
133 0 ▶ $charinfo->accountBalance($value) if $key eq 'accountBalance';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "accountBalance" 0 0 0
134 0 ▶ $charinfo->skillPoints($value) if $key eq 'skillPoints';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "skillPoints" 0 0 0
135 0 ▶ $charinfo->shipName($value) if $key eq 'shipName';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "shipName" 0 0 0
136 0 ▶ $charinfo->shipTypeID($value) if $key eq 'shipTypeID';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "shipTypeID" 0 0 0
137 0 ▶ $charinfo->shipTypeName($value) if $key eq 'shipTypeName';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "shipTypeName" 0 0 0
138 0 ▶ $charinfo->corporationID($value) if $key eq 'corporationID';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "corporationID" 0 0 0
139 0 ▶ $charinfo->corporation($value) if $key eq 'corporation';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "corporation" 0 0 0
140 0 ▶ $charinfo->corporationDate($value) if $key eq 'corporationDate';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "corporationDate" 0 0 0
141 0 ▶ $charinfo->allianceID($value) if $key eq 'allianceID';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "allianceID" 0 0 0
142 0 ▶ $charinfo->alliance($value) if $key eq 'alliance';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "alliance" 0 0 0
143 0 ▶ $charinfo->allianceDate($value) if $key eq 'allianceDate';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "allianceDate" 0 0 0
144 0 ▶ $charinfo->lastKnownLocation($value) if $key eq 'lastKnownLocation';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "lastKnownLocation" 0 0 0
145 0 ▶ $charinfo->securityStatus($value) if $key eq 'securityStatus';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "securityStatus" 0 0 0
146 0 $charinfo->cachedUntil($xml->{eveapi}->{cachedUntil});
147  
148 }
149
150 0 push(@charinfolist, $charinfo);
151 }
152  
153 0 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 0 ▶sub get_account_status {
Subroutine get_account_status: not called CC=6 SCAR=37.4
Pod documented
166 0 my $self = shift;
167  
168 0 my $path = '/account/AccountStatus.xml.aspx';
169 0 my $char = undef;
170  
171 0 my $text = &connect($self, $self->keyid, $self->vcode, $path, $char);
172 0 my $obj = EveOnline::AccountStatus->new();
173 0 my $xml = XMLin($text, KeepRoot => 1);
174 0 my $data = $xml->{eveapi}->{result};
175
176 0 ▶ while ( my ($key, $value ) = each (%$data) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$data) 0 0 0
177  
178 0 ▶ $obj->paidUntil($value) if $key eq 'paidUntil';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "paidUntil" 0 0 0
179 0 ▶ $obj->createDate($value) if $key eq 'createDate';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "createDate" 0 0 0
180 0 ▶ $obj->logonCount($value) if $key eq 'logonCount';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "logonCount" 0 0 0
181 0 ▶ $obj->logonMinutes($value) if $key eq 'logonMinutes';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "logonMinutes" 0 0 0
182  
183 }
184  
185 0 $obj->cachedUntil($xml->{eveapi}->{cachedUntil});
186  
187 0 return $obj;
188 }
189  
190  
191 0 ▶sub get_char_skill_queue {
Subroutine get_char_skill_queue: not called CC=3 SCAR=24.8
Pod undocumented
192 0 my $self = shift;
193 0 my $charlist = shift;
194  
195 # TODO #
196  
197 0 my @charlist = @{$charlist};
198 0 my @skillQueueList;
199 0 my $path = '/char/SkillQueue.xml.aspx';
200  
201 0 for my $char ( @charlist ) {
202
203 0 my $text = &connect($self, $self->keyid, $self->vcode, $path, $char);
204  
205 0 my $xml = XMLin($text, KeepRoot => 1);
206  
207 0 my $obj;
208  
209 0 for my $id ( keys %{ $xml->{eveapi}{result}{rowset}{row} } ) {
210
211 0 $obj = EveOnline::SkillQueue->new();
212  
213 0 $obj->characterID($char->characterID);
214 0 $obj->queuePosition($xml->{eveapi}{result}{rowset}{row}{queuePosition});
215 0 $obj->typeID($xml->{eveapi}{result}{rowset}{row}{typeID});
216 0 $obj->level($xml->{eveapi}{result}{rowset}{row}{level});
217 0 $obj->startSP($xml->{eveapi}{result}{rowset}{row}{startSP});
218 0 $obj->endSP($xml->{eveapi}{result}{rowset}{row}{endSP});
219 0 $obj->startTime($xml->{eveapi}{result}{rowset}{row}{startTime});
220 0 $obj->endTime($xml->{eveapi}{result}{rowset}{row}{endTime});
221 0 $obj->cachedUntil($xml->{eveapi}->{cachedUntil});
222 }
223  
224 0 push(@skillQueueList, $obj);
225
226 }
227
228 0 return \@skillQueueList;
229 }
230  
231 0 ▶sub get_contact_list {
Subroutine get_contact_list: not called CC=1 SCAR=6.9
Pod undocumented
232 0 my $self = shift;
233 0 my $charlist = shift;
234  
235 0 my @charlist = @{$charlist};
236 0 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 0 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 0 ▶sub connect {
Subroutine connect: not called CC=3 SCAR=24.8
Pod undocumented
255 0 my ($self, $keyID, $vCode, $path, $char) = @_;
256  
257 0 my $ua = LWP::UserAgent->new;
258 0 my $req;
259  
260 0 ▶ if ( $char ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char) { } 0 0 0
261  
262 0 $req = POST $self->apiroot.$path, [ keyID => $keyID, vCode => $vCode, characterID => $char->characterID ];
263  
264 } else {
265
266 0 $req = POST $self->apiroot.$path, [ keyID => $keyID, vCode => $vCode ];
267  
268 }
269  
270 0 my $res = $ua->request($req);
271  
272 0 ▶ unless ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->is_success) 0 0 0
273  
274 0 die "Error: " . $res->status_line . "\n";
275  
276 }
277  
278 0 my $text = $res->decoded_content;
279
280 0 return $text;
281 }
282  
283 1 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 1; # End of EveOnline::Api
↑ Summary AccountStatus.pm »