From 1083a802ac767aac4903c1531f85a3d8f737d52f Mon Sep 17 00:00:00 2001 From: zuxriddinCsharp <137428899+zuxriddinCsharp@users.noreply.github.com> Date: Mon, 16 Oct 2023 21:35:57 +0500 Subject: [PATCH] Zuxriddin Lesson-01 --- .../Lesson01/Models/RandomUser/RandomUser.cs | 112 +++++++++++++++++ Lesson01/Lesson01/Program.cs | 116 +++++++++++++++++- .../Universities List/Universities List.cs | 20 +++ Lesson01/Lesson01/Zippopotam/Zippopotam.cs | 33 +++++ 4 files changed, 276 insertions(+), 5 deletions(-) create mode 100644 Lesson01/Lesson01/Models/RandomUser/RandomUser.cs create mode 100644 Lesson01/Lesson01/Universities List/Universities List.cs create mode 100644 Lesson01/Lesson01/Zippopotam/Zippopotam.cs diff --git a/Lesson01/Lesson01/Models/RandomUser/RandomUser.cs b/Lesson01/Lesson01/Models/RandomUser/RandomUser.cs new file mode 100644 index 0000000..578b02b --- /dev/null +++ b/Lesson01/Lesson01/Models/RandomUser/RandomUser.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lesson01.Models.RandomUser +{ + // Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse); + + class RandomUser + { + public List results { get; set; } + public Info info { get; set; } + } + + public class Coordinates + { + public string latitude { get; set; } + public string longitude { get; set; } + } + + public class Dob + { + public DateTime date { get; set; } + public int age { get; set; } + } + + public class Id + { + public string name { get; set; } + public string value { get; set; } + } + + public class Info + { + public string seed { get; set; } + public int results { get; set; } + public int page { get; set; } + public string version { get; set; } + } + + public class Location + { + public Street street { get; set; } + public string city { get; set; } + public string state { get; set; } + public string country { get; set; } + public string postcode { get; set; } + public Coordinates coordinates { get; set; } + public Timezone timezone { get; set; } + } + + public class Login + { + public string uuid { get; set; } + public string username { get; set; } + public string password { get; set; } + public string salt { get; set; } + public string md5 { get; set; } + public string sha1 { get; set; } + public string sha256 { get; set; } + } + + public class Name + { + public string title { get; set; } + public string first { get; set; } + public string last { get; set; } + } + + public class Picture + { + public string large { get; set; } + public string medium { get; set; } + public string thumbnail { get; set; } + } + + public class Registered + { + public DateTime date { get; set; } + public int age { get; set; } + } + + public class Result + { + public string gender { get; set; } + public Name name { get; set; } + public Location location { get; set; } + public string email { get; set; } + public Login login { get; set; } + public Dob dob { get; set; } + public Registered registered { get; set; } + public string phone { get; set; } + public string cell { get; set; } + public Id id { get; set; } + public Picture picture { get; set; } + public string nat { get; set; } + } + + public class Street + { + public int number { get; set; } + public string name { get; set; } + } + + public class Timezone + { + public string offset { get; set; } + public string description { get; set; } + } +} diff --git a/Lesson01/Lesson01/Program.cs b/Lesson01/Lesson01/Program.cs index 5559afb..24d6e00 100644 --- a/Lesson01/Lesson01/Program.cs +++ b/Lesson01/Lesson01/Program.cs @@ -1,5 +1,9 @@ using Lesson01.Models.CoinDesk; +using Lesson01.Models.RandomUser; +using Lesson01.Universities_List; +using Lesson01.Zippopotam; using Newtonsoft.Json; +using System.Runtime.InteropServices; using System.Text; namespace Lesson01 @@ -30,23 +34,125 @@ static void Main(string[] args) #region CoinDesk + //var client = new HttpClient(); + + //var webRequest = new HttpRequestMessage(HttpMethod.Get, "https://randomuser.me/api/") + //{ + // Content = new StringContent("", Encoding.UTF8, "application/json") + //}; + + //var response = client.Send(webRequest); + + //using var reader = new StreamReader(response.Content.ReadAsStream()); + //string json = reader.ReadToEnd(); + + //CoinDesk result = JsonConvert.DeserializeObject(json); + + + //Console.WriteLine($"Last time Bitcoin was updated: {result}"); + + #endregion + + #region RandomUser + + //var client = new HttpClient(); + //try + //{ + // var webRequest = new HttpRequestMessage(HttpMethod.Get, "https://randomuser.me/api/") + // { + // Content = new StringContent("", Encoding.UTF8, "application/json") + // }; + + // var response = client.Send(webRequest); + + // using var reader = new StreamReader(response.Content.ReadAsStream()); + // string json = reader.ReadToEnd(); + + // RandomUser result = JsonConvert.DeserializeObject(json); + + // foreach (var item in result.results) + // { + // Console.WriteLine($"Title: {item.name.title}"); + // Console.WriteLine($"First: {item.name.first}"); + // Console.WriteLine($"Last: {item.name.last}"); + // Console.WriteLine($"Street: Number - {item.location.street.number}, Name - {item.location.street.name}"); + // Console.WriteLine($"City: {item.location.city}"); + // Console.WriteLine($"State: {item.location.state}"); + // Console.WriteLine($"Country: {item.location.country}"); + // Console.WriteLine($"Pastcode: {item.location.postcode}"); + // } + //} + //catch (Exception ex) + //{ + // Console.WriteLine(ex.Message); + //} + #endregion + + #region Zippopotam + //var client = new HttpClient(); + //try + //{ + // var wepRequest = new HttpRequestMessage(HttpMethod.Get, "https://api.zippopotam.us/us/33162") + // { + // Content = new StringContent("", Encoding.UTF8, "application/json") + // }; + // var response = client.Send(wepRequest); + // using var reader = new StreamReader(response.Content.ReadAsStream()); + // string json = reader.ReadToEnd(); + + // zippopotame result = JsonConvert.DeserializeObject(json); + + // Console.WriteLine($"Post code: {result.postcode}"); + // Console.WriteLine($"Country: {result.country}"); + // Console.WriteLine($"Country abbreviation: {result.countryabbreviation}"); + + // foreach (var item in result.places) + // { + // Console.WriteLine($"Place name: {item.placename}"); + // Console.WriteLine($"Longitude: {item.longitude}"); + // Console.WriteLine($"State: {item.state}"); + // Console.WriteLine($"State abbreviation: {item.stateabbreviation}"); + // Console.WriteLine($"Latitude: {item.latitude}"); + + // } + //} + //catch ( Exception ex ) + //{ + // Console.WriteLine(ex.Message ); + //} + #endregion + + #region Universities List + Console.Write("Enter counrty name: "); + string country = Console.ReadLine(); + var client = new HttpClient(); - var webRequest = new HttpRequestMessage(HttpMethod.Get, "https://api.coindesk.com/v1/bpi/currentprice.json") + var wepRequest = new HttpRequestMessage(HttpMethod.Get, $" http://universities.hipolabs.com/search?country={country}") { Content = new StringContent("", Encoding.UTF8, "application/json") }; - var response = client.Send(webRequest); + var respons = client.Send(wepRequest); - using var reader = new StreamReader(response.Content.ReadAsStream()); + using var reader = new StreamReader(respons.Content.ReadAsStream()); string json = reader.ReadToEnd(); - CoinDesk result = JsonConvert.DeserializeObject(json); + List universities=JsonConvert.DeserializeObject>(json); + + Console.WriteLine($"Universities in the country: {country}"); + foreach (var university in universities) + { - Console.WriteLine($"Last time Bitcoin was updated: {result.time.updatedISO}"); + Console.WriteLine(); + Console.WriteLine($"Name: {university.name}"); + Console.WriteLine($"Country: {university.country}"); + Console.WriteLine($"Web Pages: {string.Join(", ", university.web_pages)}"); + Console.WriteLine(); + Console.WriteLine("________________________________________________________"); + } #endregion } } diff --git a/Lesson01/Lesson01/Universities List/Universities List.cs b/Lesson01/Lesson01/Universities List/Universities List.cs new file mode 100644 index 0000000..0924915 --- /dev/null +++ b/Lesson01/Lesson01/Universities List/Universities List.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lesson01.Universities_List +{ + public class Root + { + [JsonProperty("state-province")] + public string stateprovince { get; set; } + public string country { get; set; } + public List domains { get; set; } + public List web_pages { get; set; } + public string alpha_two_code { get; set; } + public string name { get; set; } + } +} diff --git a/Lesson01/Lesson01/Zippopotam/Zippopotam.cs b/Lesson01/Lesson01/Zippopotam/Zippopotam.cs new file mode 100644 index 0000000..8b22d39 --- /dev/null +++ b/Lesson01/Lesson01/Zippopotam/Zippopotam.cs @@ -0,0 +1,33 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lesson01.Zippopotam +{ + internal class zippopotame + { + [JsonProperty("post code")] + public string postcode { get; set; } + public string country { get; set; } + + [JsonProperty("country abbreviation")] + public string countryabbreviation { get; set; } + public List places { get; set; } + } + public class Place + { + [JsonProperty("place name")] + public string placename { get; set; } + public string longitude { get; set; } + public string state { get; set; } + + [JsonProperty("state abbreviation")] + public string stateabbreviation { get; set; } + public string latitude { get; set; } + } + + +}