File Coverage

blib/lib/Games/EveOnline/EveCentral/Request/MarketStat.pm
Criterion Covered Total %
statement 45 45 100.0
branch 10 12 83.3
condition 4 6 66.6
subroutine 8 8 100.0
pod 1 1 100.0
total 68 72 94.4


line stmt bran cond sub pod time code
1             package Games::EveOnline::EveCentral::Request::MarketStat;
2             {
3             $Games::EveOnline::EveCentral::Request::MarketStat::VERSION = '0.001';
4             }
5              
6              
7             # ABSTRACT: Create a request for the marketstat endpoint.
8              
9              
10 1     1   36224 use Moo 1.003001;
  1         15893  
  1         6  
11 1     1   2421 use MooX::Types::MooseLike 0.25;
  1         1305  
  1         41  
12 1     1   740 use MooX::StrictConstructor 0.006;
  1         10923  
  1         8  
13 1     1   23560 use MooX::Types::MooseLike::Base qw(AnyOf ArrayRef Int Str);
  1         5264  
  1         131  
14              
15 1     1   20 use 5.012;
  1         3  
  1         38  
16              
17             extends 'Games::EveOnline::EveCentral::Request';
18              
19 1     1   844 use Readonly 1.03;
  1         2884  
  1         486  
20              
21              
22             Readonly::Scalar my $ENDPOINT => 'marketstat';
23              
24              
25             has 'hours' => (
26             is => 'ro',
27             isa => Int,
28             default => 24
29             );
30              
31             has 'type_id' => (
32             is => 'ro',
33             isa => AnyOf[Int, ArrayRef[Int]],
34             required => 1
35             );
36              
37             has 'min_q' => (
38             is => 'ro',
39             isa => Int,
40             default => 1
41             );
42              
43             has 'regions' => (
44             is => 'ro',
45             isa => AnyOf[Int, ArrayRef[Int]],
46             default => -1
47             );
48              
49             has 'system' => (
50             is => 'ro',
51             isa => Int,
52             default => -1
53             );
54              
55             has '_path' => (
56             is => 'lazy',
57             isa => Str,
58             );
59              
60              
61              
62             sub request {
63 1     1 1 473 my $self = shift;
64 1         22 my $path = $self->_path;
65              
66 1         15 return $self->http_request($path);
67             }
68              
69              
70              
71             sub _build__path {
72 4     4   14353 my $self = shift;
73              
74 4         12 my $path = $ENDPOINT . '?';
75              
76 4         11 my $type_ids = $self->type_id;
77 4 100       15 if (ref $type_ids eq 'ARRAY') {
78 1         2 for my $type_id (@$type_ids) {
79 2         5 $path .= "typeid=$type_id&";
80             }
81 1         5 $path =~ s/&$//;
82             }
83             else {
84 3         9 $path .= "typeid=$type_ids";
85             }
86              
87 4 50       16 if (defined $self->hours) {
88 4         10 my $hours = $self->hours;
89 4         8 $path .= "&hours=$hours";
90             }
91              
92 4 50       27 if (defined $self->min_q) {
93 4         8 my $min_q = $self->min_q;
94 4         7 $path .= "&minQ=$min_q";
95             }
96              
97 4         9 my $system = $self->system;
98 4 100 66     60 if (defined $system && $system > 0) {
99 1         3 $path .= "&usesystem=$system";
100             }
101              
102 4         13 my $regions = $self->regions;
103 4 100 66     18 if (defined $regions && $regions > 0) {
104 2 100       8 if (ref $regions eq 'ARRAY') {
105 1         4 for my $region (@$regions) {
106 2         5 $path .= "&regionlimit=$region";
107             }
108             }
109             else {
110 1         4 $path .= "&regionlimit=$regions";
111             }
112             }
113              
114 4         84 return $path;
115             }
116              
117              
118             1; # End of Games::EveOnline::EveCentral::Request::MarketStat
119              
120             __END__
121              
122             =pod
123              
124             =head1 NAME
125              
126             Games::EveOnline::EveCentral::Request::MarketStat - Create a request for the marketstat endpoint.
127              
128             =head1 VERSION
129              
130             version 0.001
131              
132             =head1 SYNOPSIS
133              
134             my $req = Games::EveOnline::EveCentral::Request::MarketStat->new(
135             type_id => 34, # or [34, 35]. Mandatory.
136             hours => 1, # defaults to 24
137             min_q => 10000, # defaults to 1
138             system => 30000142,
139             regions => 10000002, # or [10000002, 10000003],
140             )->request;
141              
142             =head1 DESCRIPTION
143              
144             This class is used to create HTTP::Request objects suitable to call the
145             `marketstat` method on EVE Central.
146              
147             Please take care to only use valid type ids.
148              
149             Examples:
150              
151             =over 4
152              
153             =item * L<http://api.eve-central.com/api/marketstat?typeid=34&typeid=35&regionlimit=10000002>
154              
155             =item * L<http://api.eve-central.com/api/marketstat?typeid=34&usesystem=30000142>
156              
157             =back
158              
159             =for test_synopsis no strict 'vars'
160              
161             =head1 METHODS
162              
163             =head2 request
164              
165             Returns an HTTP::Request object which can be used to call the 'markestat'
166             endpoint.
167              
168             =begin private
169              
170             =end private
171              
172             =head1 AUTHOR
173              
174             Pedro Figueiredo, C<< <me at pedrofigueiredo.org> >>
175              
176             =head1 BUGS
177              
178             Please report any bugs or feature requests through the web interface at
179             L<https://github.com/pfig/games-eveonline-evecentral/issues>. I will be
180             notified, and then you'll automatically be notified of progress on your bug as
181             I make changes.
182              
183             =head1 SUPPORT
184              
185             You can find documentation for this module with the perldoc command.
186              
187             perldoc Games::EveOnline::EveCentral
188              
189             You can also look for information at:
190              
191             =over 4
192              
193             =item * GitHub Issues (report bugs here)
194              
195             L<https://github.com/pfig/games-eveonline-evecentral/issues>
196              
197             =item * AnnoCPAN: Annotated CPAN documentation
198              
199             L<http://annocpan.org/dist/Games-EveOnline-EveCentral>
200              
201             =item * CPAN Ratings
202              
203             L<http://cpanratings.perl.org/d/Games-EveOnline-EveCentral>
204              
205             =item * CPAN
206              
207             L<http://metacpan.org/module/Games::EveOnline::EveCentral>
208              
209             =back
210              
211             =head1 ACKNOWLEDGEMENTS
212              
213             =over 4
214              
215             =item * The people behind EVE Central.
216              
217             L<http://eve-central.com/>
218              
219             =back
220              
221             =head1 LICENSE AND COPYRIGHT
222              
223             Copyright 2013 Pedro Figueiredo.
224              
225             This program is free software; you can redistribute it and/or modify it
226             under the terms of the Artistic License.
227              
228             See http://dev.perl.org/licenses/ for more information.
229              
230             =head1 AUTHOR
231              
232             Pedro Figueiredo <me@pedrofigueiredo.org>
233              
234             =head1 COPYRIGHT AND LICENSE
235              
236             This software is copyright (c) 2013 by Pedro Figueiredo.
237              
238             This is free software; you can redistribute it and/or modify it under
239             the same terms as the Perl 5 programming language system itself.
240              
241             =cut