Advertisement
Guest User

Untitled

a guest
Jan 1st, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Newtonsoft.Json;
  7. using Newtonsoft.Json.Linq;
  8. using System.Net;
  9. using System.IO;
  10. namespace ReadRusselAPI
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             try
  17.             {
  18.                 HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://ee-api.lrussell.net/player/lrussell");
  19.                 req.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0";
  20.                 req.Method = "GET";
  21.                 req.ContentType = "application/json";
  22.                 try
  23.                 {
  24.                     using (HttpWebResponse response = req.GetResponse() as HttpWebResponse)
  25.                     {
  26.                         if (response.StatusCode != HttpStatusCode.OK)
  27.                         {
  28.                             throw new Exception("Error: " + response.StatusCode + " " + response.StatusDescription);
  29.                         }
  30.                         else
  31.                         {
  32.                             using (StreamReader reader = new StreamReader(response.GetResponseStream()))
  33.                             {
  34.                                 String text = reader.ReadToEnd();
  35.                                 var datta = JsonConvert.DeserializeObject<player>(text);
  36.                                 foreach (KeyValuePair<string,string> kvp in datta.Worlds)
  37.                                 {
  38.                                     Console.WriteLine("ID: " + kvp.Key + " Title: " + kvp.Value);
  39.                                 }
  40.                             }
  41.  
  42.                         }
  43.                     }
  44.                 }
  45.                 catch (Exception ex)
  46.                 {
  47.                     Console.WriteLine(ex.Message);
  48.                 }
  49.             }
  50.             catch (Exception ex)
  51.             {
  52.                 Console.WriteLine(ex.Message);
  53.             }
  54.             Console.ReadKey();
  55.         }
  56.     }
  57.     public class player
  58.     {
  59.         public string Name { get; set; }
  60.         public string Id { get; set; }
  61.         public int MaximumEnergy { get; set; }
  62.         public int CurrentEnergy { get; set; }
  63.         public int Gems { get; set; }
  64.         public string LastLogin { get; set; }
  65.         public string LastMagicCoin { get; set; }
  66.         public int LoginStreak { get; set; }
  67.         public int TotalItems { get; set; }
  68.         public int Smiley { get; set; }
  69.         public int TimeZone { get; set; }
  70.         public bool Visible { get; set; }
  71.         public string Banned { get; set; }
  72.         public string TempBanned { get; set; }
  73.         public string HasBeta { get; set; }
  74.         public string IsGold { get; set; }
  75.         public string IsModerator { get; set; }
  76.         public string IsAdministrator { get; set; }
  77.         public Dictionary<string,string> Worlds { get; set; }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement