Advertisement
ElfenSky

tinyProject_TVDBManager

Aug 19th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. //custom
  5. using Newtonsoft.Json; //used for json
  6. using System.Threading.Tasks; //used for async
  7. using System.Net.Http; //used to make http requests
  8. using System.Diagnostics; //used for Debug.WriteLine("xamarin:::   " + "string");
  9. using Newtonsoft.Json.Linq; //used to directly access JObject
  10. using tinyapp.Model; //used to access nearby classes, such as Series.
  11. using System.Net.Http.Headers; //used for AuthenticationHeaderValue which is required for bearer token authorization
  12.  
  13. namespace tinyapp.Model
  14. {
  15.     class TVDBManager
  16.     {
  17.         const string apikey = "_";
  18.         const string userkey = "_";
  19.         const string username = "_";
  20.         const string url = "https://api.thetvdb.com";
  21.         const string sContentType = "application/json";
  22.         //test
  23.         const string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NjYzMjkwMTAsImlkIjoiZGV2aWNlcHJvZ3JhbW1pbmcyIiwib3JpZ19pYXQiOjE1NjYyNDI2MTAsInVzZXJpZCI6NDE0MTI4LCJ1c2VybmFtZSI6IkVsZmVuU2t5In0.NXWrThBo85vHctscCR_Ze40gJPbH3hx6yuBlEiES3KredFXWigs9IYmeXrkvCD2uJDfgeEvN0YdOyqAHSX2yluobMUnv_SOENPtAasQjpkJOq_JKKNpEVSMxHGFbHYkB9NvTgtLYX-itII3nBSURMs0gPC-DtK8w4J_w2oDD2MWJMHqsQKjSP50Zedj7O57ppx-doOzmW657JvPyLIjighAiEDcigP829UwHhxr4691KZdaQg2vcTu_E-Ldz3KrV6EOW0otusKZwOvb5llvdNXt9taZE9_7gP0IkVTe5VkWnkCDNaQctskAPxPQRKeiCG5qarqXQKFAJPqHHGmHnQw";
  24.  
  25.         public static async Task<List<Serie>> GetSearchResultsV2()
  26.         {
  27.             string url = "https://api.thetvdb.com/search/series?name=stranger";
  28.  
  29.             try
  30.             {
  31.                 HttpClient client = new HttpClient();
  32.                 client.DefaultRequestHeaders.Add("Accept", "application/json");
  33.                 client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
  34.  
  35.                 string json = await client.GetStringAsync(url);
  36.                 Debug.WriteLine("xamarin:::   " + json);
  37.  
  38.                 if (json != null)
  39.                 {
  40.                     List<Serie> listSeries = JsonConvert.DeserializeObject<List<Serie>>(json);
  41.                     return listSeries;
  42.                 }
  43.                 else
  44.                 {
  45.                     Debug.WriteLine("xamarin:::   " + "GetSearchResultsV2:::   " + "json did not load");
  46.                     Debug.WriteLine("xamarin:::   " + json);
  47.                     return null;
  48.                 }
  49.             }
  50.  
  51.             catch (Exception ex)
  52.             {
  53.                 Debug.WriteLine("xamarin:::   " + "error: " + ex.Message);
  54.                 throw ex;
  55.             }
  56.         }
  57.  
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement