Working with Pinnacle API – Get Leagues

This is a follow up article of  Working with Pinnacle API.

Next operation is to get a list of leagues under a specific sports.  Let’s try to continue from the previous view and get list of leagues.

Let’s go to PinnacleAPIHandler and make another class function to call the API operation v2/leagues?sportid={sportid}, and also get new Model ready for request and response of this API.

My model; (I have added comment above declared object to better understand what these objects ll be used for)

Then, go to Handlers/PinnacleAPIHandler.cs and add new function called GetLeagues with integer parameter named id, like below;

I have made a little modification, and created separate function called GetReponse(string url), where Get call to the specific Pinnacl API URL can be handled, and back with string of result.

If in case, there is an error, it will return empty string.   The caller of this function has to make sure that string is not empty.

Now back at my controller.  Let’s create new Action called Leagues with integer parameter called id like below;

At last, my view, View/Pinnacle/Leagues.cshtml

This page always required ID of sports. The best place to navigate from, would be a list sports.  Let’s go back to the view of list of sports and create new link to the league like below.

OK, all done.  Let’s look at new Sports page below;

And after clicking on Soccer, which is ID 29;

Good.  Let’s continue on with next operation.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.