mardi 27 octobre 2015

New Imgur .NET SDK on Github, can be used Universal App, WinRT app, Windows Phone, any .net project


Github Repo: https://github.com/Delaire/Imgur-.NET-SDK

How to use this sdk:

You first need to get your API key and secret id which you can find on the imgur website https://api.imgur.com/oauth2/addclient and/or here if you already have a done this: https://imgur.com/account/settings/apps
To start you need to initialize the api:
    ApiRoot.Instance.Init("XXXXXXXX", "XXXXXX");
All of the methods are async, so just remember that you need to wait for the response.
I have mapped all of the imgur api endpoint which can be found here: https://api.imgur.com/endpoints to classes.

Here is example of how the API works with the GetEndPointEntityAsync method:
You will tell the method the type of data you plan on receiving and then tell it where to get this data:
    ApiRoot.Instance.GetEndPointEntityAsync<RootElement<Data_Format_we_will_recieve>>(
                      new Data_to_get()
                          {
                                    //Data parameters
                          });
Here is a real example for how you can make a call:
    var result = await ApiRoot.Instance.GetEndPointEntityAsync<RootElement<GalleryImage>>(
            new GetGalleryImage ()
            {
                page = 0,
                section = Section.hot.ToString(), <- cloud be improved
                showViral = true,
                sort = Sort.top.ToString(),
                window = WindowsSort.day.ToString(),
            });
Here is another example of how to do a Get Random Gallery Image
    ApiRoot.Instance.GetEndPointEntityAsync<RootElement<GalleryAlbum>>(
                 new GetRandomGalleryImages()
                    {
                            page = 1
                    });

This API sdk is used in my personal windows phone imgur app 8gur which can be found here: http://windowsphone.com/s?appid=15913087-9ea1-4f42-92b0-8b2c1c764837
if you wish to help be my guest!
Here is the Github Repo: https://github.com/Delaire/Imgur-.NET-SDK