Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions Lesson01/Lesson01/Models/RandomUser/RandomUser.cs
Original file line number Diff line number Diff line change
@@ -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<Root>(myJsonResponse);

class RandomUser
{
public List<Result> 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; }
}
}
116 changes: 111 additions & 5 deletions Lesson01/Lesson01/Program.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<RandomUser>(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<RandomUser>(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<zippopotame>(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<CoinDesk>(json);
List<Root> universities=JsonConvert.DeserializeObject<List<Root>>(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
}
}
Expand Down
20 changes: 20 additions & 0 deletions Lesson01/Lesson01/Universities List/Universities List.cs
Original file line number Diff line number Diff line change
@@ -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<string> domains { get; set; }
public List<string> web_pages { get; set; }
public string alpha_two_code { get; set; }
public string name { get; set; }
}
}
33 changes: 33 additions & 0 deletions Lesson01/Lesson01/Zippopotam/Zippopotam.cs
Original file line number Diff line number Diff line change
@@ -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<Place> 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; }
}


}