davorg-cpan / net-songkick

Perl library for using the Songkick API
5 stars 1 forks source link

Check All Routes #1

Open davorg opened 8 years ago

davorg commented 8 years ago

It's been a while since I looked at this and the Songkick API has moved on. There are probably many API calls that are missing.

http://api.songkick.com/api/3.0/artists/{artist_id}/calendar.json?apikey={your_api_key} http://api.songkick.com/api/3.0/artists/{artist_id}/gigography.json?apikey={your_api_key} http://api.songkick.com/api/3.0/artists/{artist_id}/similar_artists.json?apikey={your_api_key} http://api.songkick.com/api/3.0/artists/mbid:{music_brainz_id}/calendar.json?apikey={your_api_key} http://api.songkick.com/api/3.0/events/{event_id}.json?apikey={your_api_key} http://api.songkick.com/api/3.0/events.json?apikey={your_api_key} http://api.songkick.com/api/3.0/metro_areas/{metro_area_id}/calendar.json?apikey={your_api_key} http://api.songkick.com/api/3.0/search/artists.json?query={search_query}&apikey={your_api_key} http://api.songkick.com/api/3.0/search/locations.json?location=geo:{lat,lng}&apikey={your_api_key} http://api.songkick.com/api/3.0/search/locations.json?query={search_query}&apikey={your_api_key} http://api.songkick.com/api/3.0/search/venues.json?query={search_query}&apikey={your_api_key} http://api.songkick.com/api/3.0/users/{username}/calendar.json?reason=tracked_artist&apikey={your_api_key} http://api.songkick.com/api/3.0/users/{username}/gigography.json?apikey={your_api_key} http://api.songkick.com/api/3.0/venues/{venue_id}/calendar.json?apikey={your_api_key} http://api.songkick.com/api/3.0/venues/{venue_id}.json?apikey={your_api_key}

richardleach commented 5 years ago

Looks like there are a few missing calls. I'll have a crack at this for Hacktoberfest.

richardleach commented 5 years ago

Still chipping away over at this branch. Will add all routes in before doing some refactoring.

richardleach commented 5 years ago

About to wire up the Trackings requests.

The Songkick API returns a 404 if the artist_id|event_id|metro_id asked about is not tracked by the user. I'm not sure what the Net::Songkick method that I implement should return for this case - undef, some kind of error/message object, an empty object??

What do you suggest please?

davorg commented 5 years ago

Sorry, on holiday, so I only have infrequent access to email.

I'd say that returning undef is the right approach here. But I'm happy to be persuaded otherwise

Dave...

On Fri, 26 Oct 2018, 05:01 Richard Leach, notifications@github.com wrote:

About to wire up the Trackings https://www.songkick.com/developer/trackings requests.

The Songkick API returns a 404 if the artist_id|event_id|metro_id asked about is not tracked by the user. I'm not sure what the Net::Songkick method that I implement should return for this case - undef, some kind of error/message object, an empty object??

What do you suggest please?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/davorg/net-songkick/issues/1#issuecomment-433239052, or mute the thread https://github.com/notifications/unsubscribe-auth/AABgQj8eUvDtuampyFW-I-EQJ9pCQQnqks5uokncgaJpZM4I5q9h .

richardleach commented 5 years ago

Hi Dave,

Thanks, I went with return undef for 404 responses.

I've hit a hurdle on implementing the final missing API call, down to my Moose-foo not being strong enough. (In fact, this is my first time hacking on Moose.) I wonder if you could take a look?

Getting a user's calendar returns an array of CalendarEntry objects, each of which contains an Event. The test for this call uses the exact same Event object as at the top of the test file, and which is processed just fine in previous tests, but in the CalendarEntry test, there's the following failure: Attribute (event) does not pass the type constraint because: Validation failed for 'Net::Songkick::Event'

This is the only API call that returns a structure containing an Event, where the Event is not the outermost object.

PS Once that final call is working, I'll do some refactoring and split up the test file. Any suggestions on how to go about refactoring, without breaking lazy building and whatnot, would be gratefully appreciated. I should so do your Moose training course.

davorg commented 5 years ago

Hi Richard,

Thanks for this. It looks really awesome.

I think the problem here is that you actually need two classes here - a Calendar and a CalendarEntry. It looks to me like the Calendar's only attribute would be an array of CalendarEntries and a CalendarEntry would have an Event and a Reason (so, like your existing Calendar class). Something like this, perhaps:

package Net::Songkick::Calendar;

coerce 'Net::Songkick::Calendar'
  from 'HashRef',
  via { Net::Songkick::Calendar->new($_) };

has entries => (
  is => 'ro',
  isa => 'ArrayRef[Net::Songkick::CalendarEntry)',
  coerce => 1,
);

And the Net::Songkick::CalendarEntry class would just be your existing Net::Songkick::Calendar class, renamed.

The coercion of the Calendar class might be a little different. I'll have a poke at it over the next couple of days and see what I can come up with.

davorg commented 5 years ago

On further investigation, I see the coercion is a bit more complex than I thought. I haven't got it right yet, but I think I'm on the right lines...

davorg commented 5 years ago

See https://github.com/davorg/net-songkick/commit/374254585a0258f46b0dfaa131450434f7af5520 for my work in progress.

richardleach commented 5 years ago

Cool. I probably won't have tuits for a few days, but will check back later.