API.pm

filter: Statementstmt 68.4% 39 / 57 Branchbran 66.6% 12 / 18 Conditioncond 14.2% 1 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.9% 10 / 11 Podpod 80.0% 4 / 5 totaltotal 64.7% 66 / 102 CC 14 SCAR 29.0
CC
14
Cov
63%
get_data
56.0
new
5.0
base_uri
2.0
CRAP 18.1
↑ Summary API/Discovery.pm »
1 package Ticketmaster::API;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Ticketmaster::API - start interacting with Ticketmaster's APIs
14  
15 =head1 VERSION
16  
17 Version 0.02
18  
19 =cut
20  
21 1 our $VERSION = '0.02';
22  
23  
24 =head1 SYNOPSIS
25  
26 Core module to facilitate interacting with Ticketmaster's APIs.
27  
28 Unless you are creating unique way to connect to Ticketmaster's API you probably
29 don't want this module. Please see one of the following:
30  
31 Ticketmaster::API::Discover
32  
33 To be able to interact with Ticketmaster's APIs you'll need to get an API key.
34  
35 General documentation can be found here: http://ticketmaster-api.github.io
36  
37  
38 =head1 NOTES
39  
40 =over 2
41  
42 =item Mozilla::CA
43  
44 Since connections are made via https Mozilla::CA will most likely need to be installed.
45  
46 =back
47  
48  
49 =head1 SUBROUTINES/METHODS
50  
51 =head2 new
52  
53 Create a new instance of Ticketmaster::API.
54  
55 # use the default base_uri and version infromation
56 my $tm_api = Ticketmaster::API->new(api_key => $api_key);
57  
58 my $tm_api = Ticketmaster::API->new(
59 api_key => $api_key,
60 base_uri => 'https://new_api_endpoint.ticketmaster.com',
61 version => 'v2'
62 );
63  
64 =cut
65  
66 5 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod documented
67 5 my $self;
68 5 my $package = shift;
69 5 ▶ my $class = ref($package) || $package;
Condition33%1/3
ref $package || $package
l!l&&r!l&&!r
050
MC/DC0%0/2
ref $package || $package
ref $package $package
Truth table33%1/3
A || B
A= ref $packageB= $package
ABresult
1X1
011
000
70  
71 5 $self = {@_};
72 5 bless($self, $class);
73  
74 5 ▶ $self->base_uri('https://app.ticketmaster.com') unless $self->base_uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->base_uri 3 2 5
75 5 ▶ $self->version('v1') unless $self->version;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->version 4 1 5
76
77 5 ▶ Carp::croak("No api_key provided") unless $self->api_key();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->api_key 1 4 5
78  
79 4 return $self;
80 }
81  
82 =head2 base_uri
83  
84 Set/Get the base endpoint for the Ticketmaster API.
85  
86 Default: https://app.ticketmaster.com
87  
88 =cut
89 10 ▶sub base_uri {
Subroutine base_uri: called CC=2 SCAR=6.9
Pod documented
90 10 my $self = shift;
91  
92 10 ▶ $self->{base_uri} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 7 10
93  
94 10 return $self->{base_uri};
95 }
96  
97 =head2 base_uri
98  
99 Set/Get the version of the Ticketmaster API that is currently being hit.
100  
101 Default: v1
102  
103 =cut
104 13 ▶sub version {
Subroutine version: called CC=2 SCAR=6.9
Pod undocumented
105 13 my $self = shift;
106  
107 13 ▶ $self->{version} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 4 9 13
108  
109 13 return $self->{version};
110 }
111  
112 =head2 api_key
113  
114 Set/Get the user's API key to the Ticketmaster API.
115  
116 =cut
117 10 ▶sub api_key {
Subroutine api_key: called CC=2 SCAR=6.9
Pod documented
118 10 my $self = shift;
119  
120 10 ▶ $self->{api_key} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 9 10
121  
122 10 return $self->{api_key};
123 }
124  
125 =head2 get_data
126  
127 Connect to the TM API to receive the information being requested.
128  
129 my $res = $tm_api->get_data(method => 'GET', path_template => '/discovery/%s/events');
130  
131 =over 2
132  
133 =item method
134  
135 The REST method to execute on the endpoint. IE: GET
136  
137 =item path_template
138  
139 A sprintf template that will be combined with the base_uri value to generate the final endpoint.
140  
141 Example: /discovery/%s/events
142  
143 The '%s' is the location of the version number of the API being hit.
144  
145 =item parameters
146  
147 A hash reference of any parameters that are to be added to the endpoint
148  
149 =back
150  
151 =cut
152 # Requires: method, path_template (sprintf string), parameters (hash ref)
153 0 ▶sub get_data {
Subroutine get_data: not called CC=7 SCAR=40.3
Pod documented
154 0 my $self = shift;
155 0 my %args = @_;
156  
157 0 ▶ my $method = $args{method} || Carp::croak("No method provided (GET)");
Condition0%0/2
$args{'method'} || Carp::croak('No method provided (GET)')
l!l
00
MC/DC0%0/1
$args{'method'} || Carp::croak('No method provided (GET)')
$args{'method'}
Truth table0%0/2
A
A= $args{'method'}
Aresult
11
00
158 0 ▶ my $path_template = $args{path_template} || Carp::croak("No URI template provided");
Condition0%0/2
$args{'path_template'} || Carp::croak('No URI template provided')
l!l
00
MC/DC0%0/1
$args{'path_template'} || Carp::croak('No URI template provided')
$args{'path_template'}
Truth table0%0/2
A
A= $args{'path_template'}
Aresult
11
00
159 0 ▶ my %parameters = exists $args{parameters} ? %{$args{parameters}} : ();
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'parameters'} ? : 0 0 0
160  
161 0 my $uri = $self->base_uri;
162 0 ▶ $uri .= '/' unless $uri =~ /\/$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri =~ m[/$] 0 0 0
163 0 $uri .= sprintf($path_template, $self->version());
164  
165 0 $uri .= '?apikey=' . $self->api_key();
166  
167 0 foreach my $key (keys %parameters) {
168 0 $uri .= '&' . $key . '=' . $parameters{$key};
169 }
170  
171 0 my $ua = LWP::UserAgent->new;
172  
173 0 my $req = HTTP::Request->new($method => $uri);
174  
175 0 my $res = $ua->request($req);
176  
177 0 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
178 0 return decode_json($res->content);
179 }
180 else {
181 0 Carp::croak("Error: " . $res->status_line);
182 }
183 }
184  
185 =head1 AUTHOR
186  
187 Erik Tank, C<< <tank at jundy.com> >>
188  
189 =head1 BUGS
190  
191 Please report any bugs or feature requests to C<bug-ticketmaster-api at rt.cpan.org>, or through
192 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Ticketmaster-API>. I will be notified, and then you'll
193 automatically be notified of progress on your bug as I make changes.
194  
195  
196 =head1 SUPPORT
197  
198 You can find documentation for this module with the perldoc command.
199  
200 perldoc Ticketmaster::API
201  
202  
203 You can also look for information at:
204  
205 =over 4
206  
207 =item * RT: CPAN's request tracker (report bugs here)
208  
209 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Ticketmaster-API>
210  
211 =item * AnnoCPAN: Annotated CPAN documentation
212  
213 L<http://annocpan.org/dist/Ticketmaster-API>
214  
215 =item * CPAN Ratings
216  
217 L<http://cpanratings.perl.org/d/Ticketmaster-API>
218  
219 =item * Search CPAN
220  
221 L<http://search.cpan.org/dist/Ticketmaster-API/>
222  
223 =back
224  
225  
226 =head1 ACKNOWLEDGEMENTS
227  
228  
229 =head1 LICENSE AND COPYRIGHT
230  
231 Copyright 2016 Erik Tank.
232  
233 This program is free software; you can redistribute it and/or modify it
234 under the terms of the the Artistic License (2.0). You may obtain a
235 copy of the full license at:
236  
237 L<http://www.perlfoundation.org/artistic_license_2_0>
238  
239 Any use, modification, and distribution of the Standard or Modified
240 Versions is governed by this Artistic License. By using, modifying or
241 distributing the Package, you accept this license. Do not use, modify,
242 or distribute the Package, if you do not accept this license.
243  
244 If your Modified Version has been derived from a Modified Version made
245 by someone other than you, you are nevertheless required to ensure that
246 your Modified Version complies with the requirements of this license.
247  
248 This license does not grant you the right to use any trademark, service
249 mark, tradename, or logo of the Copyright Holder.
250  
251 This license includes the non-exclusive, worldwide, free-of-charge
252 patent license to make, have made, use, offer to sell, sell, import and
253 otherwise transfer the Package with respect to any patent claims
254 licensable by the Copyright Holder that are necessarily infringed by the
255 Package. If you institute patent litigation (including a cross-claim or
256 counterclaim) against any party alleging that the Package constitutes
257 direct or contributory patent infringement, then this Artistic License
258 to you shall terminate on the date that such litigation is filed.
259  
260 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
261 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
262 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
263 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
264 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
265 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
266 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
267 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
268  
269  
270 =cut
271  
272 1 1; # End of Ticketmaster::API
↑ Summary API/Discovery.pm »