Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added get_artist_events and get_metro_events methods.

  • Loading branch information...
commit 1b606048e9ed999fa0080155560372dfade194dd 1 parent b22ce40
Dave Cross authored March 14, 2011

Showing 1 changed file with 80 additions and 0 deletions. Show diff stats Hide diff stats

  1. 80  lib/Net/Songkick.pm
80  lib/Net/Songkick.pm
@@ -59,6 +59,9 @@ my $EVT_URL = "$API_URL/events";
59 59
 my $UPC_URL = "$API_URL/users/USERNAME/events";
60 60
 my $GIG_URL = "$API_URL/users/USERNAME/gigography";
61 61
 my $SET_URL = "$API_URL/events/EVENT_ID/setlists";
  62
+my $ART_URL = "$API_URL/artists/ARTIST_ID/calendar";
  63
+my $AMB_URL = "$API_URL/artists/mbid:MB_ID/calendar";
  64
+my $MET_URL = "$API_URL/metro/METRO_ID/calendar";
62 65
 
63 66
 my @EVT_PRM = qw(type artists artist_name artist_id venue_id setlist_item_name
64 67
 		 min_date max_date location);
@@ -257,6 +260,83 @@ sub get_past_events {
257 260
   }
258 261
 }
259 262
 
  263
+=head2 $sk->get_artist_events({ ... options ... });
  264
+
  265
+=cut
  266
+
  267
+sub get_artist_events {
  268
+  my $self = shift;
  269
+
  270
+  my ($params) = @_;
  271
+
  272
+  my ($ret_format, $api_format) = $self->_formats($params->{format});
  273
+
  274
+  my $url;
  275
+  
  276
+  if (exists $params->{artist_id}) {
  277
+    $url = "$ART_URL.$api_format";
  278
+    $url =~ s/ARTIST_ID/$params->{artist_id}/;
  279
+  } elsif (exists $params->{mb_id}) {
  280
+    $url = "$AMB_URL.$api_format";
  281
+    $url =~ s/MB_ID/$params->{mb_id}/;
  282
+  } else {
  283
+    die "No artist id or MusicBrainz id passed to get_artist_events\n";
  284
+  }
  285
+  
  286
+  $url .= '?api_key=' . $self->api_key;
  287
+  
  288
+  my $resp = $self->_request($url);
  289
+
  290
+  if ($ret_format eq 'perl') {
  291
+    my $evnts;
  292
+
  293
+    my $xp = XML::LibXML->new->parse_string($resp);
  294
+    foreach ($xp->findnodes('//event')) {
  295
+      push @$evnts, Net::Songkick::Event->new_from_xml($_);
  296
+    }
  297
+    return wantarray ? @$evnts : $evnts;
  298
+  } else {
  299
+    return $resp;
  300
+  }  
  301
+}
  302
+
  303
+=head2 $sk->get_metro_events({ ... options ... });
  304
+
  305
+=cut
  306
+
  307
+sub get_metro_events {
  308
+  my $self = shift;
  309
+
  310
+  my ($params) = @_;
  311
+
  312
+  my ($ret_format, $api_format) = $self->_formats($params->{format});
  313
+
  314
+  my $url;
  315
+  
  316
+  if (exists $params->{metro_id}) {
  317
+    $url = "$MET_URL.$api_format";
  318
+    $url =~ s/METRO_ID/$params->{metro_id}/;
  319
+  } else {
  320
+    die "No metro area id passed to get_metro_events\n";
  321
+  }
  322
+  
  323
+  $url .= '?api_key=' . $self->api_key;
  324
+  
  325
+  my $resp = $self->_request($url);
  326
+
  327
+  if ($ret_format eq 'perl') {
  328
+    my $evnts;
  329
+
  330
+    my $xp = XML::LibXML->new->parse_string($resp);
  331
+    foreach ($xp->findnodes('//event')) {
  332
+      push @$evnts, Net::Songkick::Event->new_from_xml($_);
  333
+    }
  334
+    return wantarray ? @$evnts : $evnts;
  335
+  } else {
  336
+    return $resp;
  337
+  }  
  338
+}
  339
+
260 340
 =head2 $sk->get_setlist({ ... options ... });
261 341
 
262 342
 Returns information about a set list from a gig. It supports the B<format>

0 notes on commit 1b60604

Please sign in to comment.
Something went wrong with that request. Please try again.