File Coverage

blib/lib/Games/WoW/Armory.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 Games::WoW::Armory;
2              
3 3     3   71284 use warnings;
  3         7  
  3         109  
4 3     3   18 use strict;
  3         5  
  3         94  
5 3     3   15 use Carp;
  3         8  
  3         288  
6 3     3   16 use base qw(Class::Accessor::Fast);
  3         4  
  3         2931  
7 3     3   15701 use LWP::UserAgent;
  3         168382  
  3         103  
8 3     3   12720 use XML::Simple;
  0            
  0            
9             use Data::Dumper;
10              
11             __PACKAGE__->mk_accessors(
12             qw(character url team guild)
13             );
14              
15             our $VERSION = '0.0.7_1';
16              
17             =head1 NAME
18              
19             Games::WoW::Armory - Access to the WoW Armory
20              
21              
22             =head1 SYNOPSIS
23              
24             use Games::WoW::Armory;
25              
26             my $armory = Games::WoW::Armory->new();
27             $armory->search_character( { realm => 'Elune',
28             character => 'Aarnn',
29             country => 'EU } );
30             print $armory->character->name;
31             print $armory->character->race;
32             print $armory->character->level;
33              
34             =head2 METHOD
35              
36             =head3 fetch_data
37              
38             Fetch the data, and store the result in $self->{data}
39              
40             =head3 search_character
41              
42             Search a character. Required params:
43              
44             realm | character | country
45             realm : name of the realm
46             character : name of a character
47             country : name of the country (EU|US)
48            
49             List of accessor for character:
50              
51             =over 4
52              
53             =item * name: character name
54              
55             =item * guildName: guild name
56              
57             =item * arenaTeams: list of teams the character is in. Each team in the array is a Games::WoW::Armory::Team object
58              
59              
60             foreach my $team (@{$armory->character->arenaTeams}){
61             print $team->name;
62             foreach my $char (@{$team}){
63             print $char->name . " " . $char->race;
64             }
65             }
66              
67              
68             =item * battleGroup: the battlegroup name
69              
70             =item * realm: realm name
71              
72             =item * race: race name
73              
74             =item * gender: gender of the character
75              
76             =item * faction: faction the character belongs to
77              
78             =item * level: level of the character
79              
80             =item * lastModified:
81              
82             =item * title: highest rank in the old PVP mode
83              
84             =item * class: class name
85              
86             =item * rank: rank
87              
88             =item * teamRank: rank in the team
89              
90             =item * seasonGamesPlayed: number of games played in the current season
91              
92             =item * seasonGamesWon: number of games win in the current season
93              
94             =item * heroic_access: list of heroic access for the character
95              
96              
97             foreach my $key ( @{ $armory->character->heroic_access } ) {
98             print "Have access to the $key.\n";
99             }
100              
101              
102             =item * characterinfo: a hash with lot of informations about the character
103              
104             =item * skill: a hash with all the skill reputation
105              
106             =item * reputation: a hash with all the character reputation
107              
108             =back
109              
110             =head3 get_arena_teams
111              
112             Get arena teams for a player
113              
114             =head3 get_reputation
115              
116             Get reputation for a player
117              
118             =head3 search_guild
119              
120             Search for a guild. required params :
121            
122             realm | guild | country
123             realm : name of the realm
124             guild : name of the guild
125             country : name of the country (EU|US)
126            
127             List of accessor for guild:
128              
129             =over 4
130              
131             =item * realm: name of the realm
132              
133             =item * name: name of the guild
134              
135             =item * battleGroup: name of the battleGroup
136              
137             =item * members: array with all the member. Each member is a Games::WoW::Armory::Character object.
138              
139             =back
140              
141             foreach my $member (@{$armory->guild->members}){
142             print $member->name;
143             }
144              
145             =head3 search_team
146              
147             Search for a team. required params :
148            
149             team | ts | battlegroup | country
150             battlegroup : name of the battlegroup
151             ts : type (2vs2 | 3vs3 | 5vs5) juste the number (eg: ts => 5)
152             team : name of the team
153             country : name of the country (EU|US)
154              
155             List of accessor for team:
156              
157             =over 4
158              
159             =item * seasonGamesPlayed: number of games played this season
160              
161             =item * rating:
162              
163             =item * size: number of members in the team
164              
165             =item * battleGroup: name of the battlegroup
166              
167             =item * realm: name of the realm
168              
169             =item * lastSeasonRanking: ranking in the last season
170              
171             =item * factionId: faction ID, 0 for alliance, 1 for Horde
172              
173             =item * ranking:
174              
175             =item * name: name of the team
176              
177             =item * relevance:
178              
179             =item * seasonGamesWon: number of games won
180              
181             =item * members: team members in an array, all the members are a Games::WoW::Armory::Character object
182              
183             =back
184              
185             foreach my $member (@{$armory->team->members}){
186             print $member->name;
187             }
188              
189             =head3 get_heroic_access
190              
191             Store in $self->character->heroic_access the list of keys the user can buy for the instances in heroic mode.
192              
193             =cut
194              
195             our $WOW_EUROPE = "http://eu.wowarmory.com/";
196             our $WOW_US = 'http://www.wowarmory.com/';
197              
198             our $HEROIC_REPUTATIONS = {
199             "Keepers of Time" => "Key of Time",
200             "Lower City" => "Auchenai Key",
201             "The Sha'tar" => "Warpforged Key",
202             "Honor Hold" => "Flamewrought Key",
203             "Thrallmar" => "Flamewrought Key",
204             "Cenarion Expedition" => "Reservoir Key",
205             };
206              
207             sub fetch_data {
208             my ( $self, $params ) = @_;
209             $self->{ ua } = LWP::UserAgent->new() || croak $!;
210             $self->{ ua }->agent(
211             "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"
212             );
213              
214             my $base_url;
215             if ( $$params{ country } =~ /eu/i ) {
216             $base_url = $WOW_EUROPE;
217             }
218             elsif ( $$params{ country } =~ /us/i ) {
219             $base_url = $WOW_US;
220             }
221             else {
222             croak "Unknow region code, please choose US or EU";
223             }
224              
225             if ( defined $$params{ team } ) {
226             $self->url( $base_url
227             . $$params{ xml } . "?r="
228             . $$params{ realm } . "&ts="
229             . $$params{ ts } . "&t="
230             . $$params{ team } );
231              
232             }
233             else {
234             $self->url( $base_url
235             . $$params{ xml } . "?r="
236             . $$params{ realm } . "&n="
237             . $$params{ name } );
238              
239             }
240              
241             $self->{ resultat } = $self->{ ua }->get( $self->url );
242              
243             $self->{ xp } = XML::Simple->new;
244             $self->{ data } = $self->{ xp }->XMLin( $self->{ resultat }->content );
245             }
246              
247             sub search_character {
248             my ( $self, $params ) = @_;
249              
250             my $xml = 'character-sheet.xml';
251              
252             croak "you need to specify a character name"
253             unless defined $$params{ character };
254             croak "you need to specify a realm" unless defined $$params{ realm };
255             croak "you need to specify a country name"
256             unless defined $$params{ country };
257              
258             $self->fetch_data(
259             { xml => $xml,
260             realm => $$params{ realm },
261             name => $$params{ character },
262             country => $$params{ country }
263             }
264             );
265            
266             my $character = $self->{ data }{ characterInfo }{ character };
267             my $skill = $self->{ data }{ characterInfo }{ skillTab };
268             my $characterinfo = $self->{ data }{ characterInfo }{ characterTab };
269            
270             $self->character( Games::WoW::Armory::Character->new );
271             $self->character->name( $$character{ name } );
272             $self->character->class( $$character{ class } );
273             $self->character->guildName( $$character{ guildName } );
274              
275             $self->character->battleGroup( $$character{ battleGroup } );
276             $self->character->realm( $$character{ realm } );
277             $self->character->race( $$character{ race } );
278             $self->character->gender( $$character{ gender } );
279             $self->character->faction( $$character{ faction } );
280             $self->character->level( $$character{ level } );
281             $self->character->lastModified( $$character{ lastModified } );
282             $self->character->title( $$character{ title } );
283              
284             $self->character->skill( $skill );
285             $self->character->characterinfo( $characterinfo );
286            
287             # Reputation information requires a separate XML file.
288             $self->get_reputation( $params );
289              
290             $self->get_arena_teams( $params );
291             }
292              
293             sub get_reputation {
294             my ( $self, $params ) = @_;
295              
296             my $xml = 'character-reputation.xml';
297              
298             croak "you need to specify a character name"
299             unless defined $$params{ character };
300             croak "you need to specify a realm" unless defined $$params{ realm };
301             croak "you need to specify a country name"
302             unless defined $$params{ country };
303              
304             $self->fetch_data(
305             { xml => $xml,
306             realm => $$params{ realm },
307             name => $$params{ character },
308             country => $$params{ country }
309             }
310             );
311              
312             my $reputation = $self->{ data }{ characterInfo }{ reputationTab };
313             $self->character->reputation( $reputation );
314             $self->get_heroic_access;
315             }
316              
317             sub get_arena_teams {
318             my ( $self, $params ) = @_;
319              
320             my $xml = 'character-arenateams.xml';
321              
322             croak "you need to specify a character name"
323             unless defined $$params{ character };
324             croak "you need to specify a realm" unless defined $$params{ realm };
325             croak "you need to specify a country name"
326             unless defined $$params{ country };
327              
328             $self->fetch_data(
329             { xml => $xml,
330             realm => $$params{ realm },
331             name => $$params{ character },
332             country => $$params{ country }
333             }
334             );
335              
336             my $arena_team
337             = $self->{data}{characterInfo}{character}{arenaTeams}{arenaTeam};
338              
339             # XML::Simple will not divide team information up into keys
340             # (based on team name) unless the character is a member of more
341             # than one team. The following logic tries to figure this out:
342             my @teams = ( exists $$arena_team{name} )
343             ? ( $arena_team )
344             : map +{ %{$arena_team->{$_}}, name=>$_ }, (keys %{$arena_team});
345              
346             my @team_objs;
347             foreach my $team ( @teams ){
348             my $t = Games::WoW::Armory::Team->new;
349             $t->name($$team{name});
350             $t->seasonGamesPlayed($$team{seasonGamesPlayed});
351             $t->size($$team{size});
352             $t->rating($$team{rating});
353             $t->battleGroup($$team{battleGroup});
354             $t->realm($$team{realm});
355             $t->lastSeasonRanking($$team{lastSeasonRanking});
356             $t->factionId($$team{factionId});
357             $t->ranking($$team{ranking});
358             $t->seasonGamesWon($$team{seasonGamesWon});
359             my @members;
360              
361             my $members = $$team{members}{character};
362              
363             if (defined $members->{name} ) { my %hash = %$members ; delete $hash{name}; $members = { $members->{name} => \%hash } };
364              
365             foreach my $member (keys %{$members}){
366             my $m = Games::WoW::Armory::Character->new;
367             $m->name($member);
368             $m->race($$members{$member}{race});
369             $m->seasonGamesPlayed($$members{$member}{seasonGamesPlayed});
370             $m->teamRank($$members{$member}{teamRank});
371             $m->race($$members{$member}{race});
372             $m->gender($$members{$member}{gender});
373             $m->seasonGamesWon($$members{$member}{seasonGamesWon});
374             $m->guildName($$members{$member}{guild});
375             $m->class($$members{$member}{class});
376             push @members, $m;
377             }
378             $t->members(\@members);
379             push @team_objs, $t;
380             }
381             $self->character->arenaTeams( \@team_objs );
382             }
383              
384             sub search_guild {
385             my ( $self, $params ) = @_;
386              
387             my $xml = "guild-info.xml";
388              
389             croak "you need to specify a guild name" unless defined $$params{ guild };
390             croak "you need to specify a realm" unless defined $$params{ realm };
391             croak "you need to specify a country name"
392             unless defined $$params{ country };
393              
394             $self->fetch_data(
395             { xml => $xml,
396             realm => $$params{ realm },
397             name => $$params{ guild },
398             country => $$params{ country }
399             }
400             );
401              
402             $self->guild( Games::WoW::Armory::Guild->new );
403             my $guild = $self->{ data }{ guildInfo };
404             my $members
405             = $self->{ data }{ guildInfo }{ guild }{ members }{ character };
406              
407             $self->guild->name( $$guild{ guildHeader }{ name } );
408             $self->guild->battleGroup( $$guild{ guildHeader }{ battleGroup } );
409             $self->guild->realm( $$guild{ guildHeader }{ realm } );
410              
411             my @members;
412             foreach my $member ( keys %{ $members } ) {
413             my $m = Games::WoW::Armory::Character->new;
414             $m->name( $member );
415             $m->level( $$members{ $member }{ level } );
416             $m->race( $$members{ $member }{ race } );
417             $m->class( $$members{ $member }{ class } );
418             $m->rank( $$members{ $member }{ rank } );
419             $m->gender( $$members{ $member }{ gender } );
420             push @members, $m;
421             }
422             $self->guild->members( \@members );
423             }
424              
425             sub search_team {
426             my ( $self, $params ) = @_;
427              
428             my $xml = "team-info.xml";
429             croak "you need to specify a team name" unless defined $$params{ team };
430             croak "you need to specify a country name"
431             unless defined $$params{ country };
432             croak "you need to specify a team style" unless defined $$params{ ts };
433             croak "you need to specify a realm name"
434             unless defined $$params{ realm };
435              
436             $self->fetch_data(
437             { xml => $xml,
438             team => $$params{ team },
439             realm => $$params{ realm },
440             ts => $$params{ ts },
441             country => $$params{ country }
442             }
443             );
444              
445             my $arena_team = $self->{ data }{ teamInfo }{ arenaTeam };
446             my $members
447             = $self->{ data }{ teamInfo }{ arenaTeam }{ members }{ character };
448             if (defined $members->{name} ) { my %hash = %$members ; delete $hash{name}; $members = { $members->{name} => \%hash } };
449              
450             $self->team( Games::WoW::Armory::Team->new() );
451             $self->team->seasonGamesPlayed( $$arena_team{ seasonGamesPlayed } );
452             $self->team->rating( $$arena_team{ rating } );
453             $self->team->size( $$arena_team{ size } );
454             $self->team->battleGroup( $$arena_team{ battleGroup } );
455             $self->team->realm( $$arena_team{ realm } );
456             $self->team->lastSeasonRanking( $$arena_team{ lastSeasonRanking } );
457             $self->team->factionId( $$arena_team{ factionId } );
458             $self->team->ranking( $$arena_team{ ranking } );
459             $self->team->name( $$arena_team{ name } );
460             $self->team->relevance( $$arena_team{ relevance } );
461             $self->team->seasonGamesWon( $$arena_team{ seasonGamesWon } );
462              
463             my @members;
464             foreach my $member ( keys %{ $members } ) {
465             my $m = Games::WoW::Armory::Character->new;
466             $m->name( $member );
467             $m->class( $$members{ $member }{ class } );
468             $m->realm( $$members{ $member }{ realm } );
469             $m->battleGroup( $$members{ $member }{ battleGroup } );
470             $m->race( $$members{ $member }{ race } );
471             $m->gender( $$members{ $member }{ gender } );
472             $m->guildName( $$members{ $member }{ guild } );
473             push @members, $m;
474             }
475             $self->team->members( \@members );
476             }
477              
478             sub get_heroic_access {
479             my $self = shift;
480              
481             my @heroic_array;
482             foreach my $rep ( keys %{ $self->character->reputation } ) {
483             foreach my $fac ( keys %{ $self->character->reputation->{ $rep } } ) {
484             foreach my $city (
485             keys %{ $self->character->reputation->{ $rep }{ $fac }{ 'faction' } } )
486             {
487             foreach my $r ( keys %{ $HEROIC_REPUTATIONS } ) {
488             if ( $r eq $city
489             && $self->character->reputation->{ $rep }{ $fac }{ 'faction' }
490             { $city }{ 'reputation' } >= 21000 )
491             {
492             push @heroic_array, $$HEROIC_REPUTATIONS{ $r };
493             }
494             }
495             }
496             }
497             }
498             $self->character->heroic_access( \@heroic_array );
499             }
500              
501             =head1 BUGS AND LIMITATIONS
502              
503             Please report any bugs or feature requests to
504             C<bug-games-wow-armory@rt.cpan.org>, or through the web interface at
505             L<http://rt.cpan.org>.
506              
507             =head1 AUTHOR
508              
509             franck cuny C<< <franck.cuny@gmail.com> >>
510             Andrew Yochum C<< <andrewyochum@gmail.com> >>
511              
512             =head1 LICENCE AND COPYRIGHT
513              
514             Copyright (c) 2007, franck cuny C<< <franck.cuny@gmail.com> >>. All rights reserved.
515              
516             This module is free software; you can redistribute it and/or
517             modify it under the same terms as Perl itself. See L<perlartistic>.
518              
519             =cut
520              
521             1;
522              
523             package Games::WoW::Armory::Team;
524              
525             use base qw(Class::Accessor::Fast);
526              
527             __PACKAGE__->mk_accessors(
528             qw(seasonGamesPlayed rating size battleGroup realm lastSeasonRanking factionId ranking name relevance seasonGamesWon members)
529             );
530              
531             1;
532              
533             package Games::WoW::Armory::Guild;
534              
535             use base qw(Class::Accessor::Fast);
536              
537             __PACKAGE__->mk_accessors( qw(realm name battleGroup members) );
538              
539             1;
540              
541             package Games::WoW::Armory::Character;
542              
543             use base qw(Class::Accessor::Fast);
544              
545             __PACKAGE__->mk_accessors(
546             qw(name guildName arenaTeams battleGroup realm race gender faction level lastModified title class rank teamRank seasonGamesPlayed seasonGamesWon heroic_access characterinfo skill reputation)
547             );
548              
549             1;
550              
551             __END__