Initial
This commit is contained in:
50
Bokhantarare/BareBookInfo.cs
Normal file
50
Bokhantarare/BareBookInfo.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Windows;
|
||||
|
||||
namespace Bokhantarare;
|
||||
|
||||
public class BareBookInfo(string editionId, string title, string? workId = null)
|
||||
{
|
||||
string WorkID { get; set; } = workId??"";
|
||||
string EditionID { get; set; } = editionId;
|
||||
string Title { get; set; } = title;
|
||||
|
||||
public Book getBook()
|
||||
{
|
||||
Dictionary<String, Object>? responce = JsonSerializer.Deserialize<Dictionary<String, Object>>(
|
||||
Helper.Request($"https://openlibrary.org/books/{EditionID}.json"));
|
||||
|
||||
if (responce == null)
|
||||
{
|
||||
throw new Exception("Failed to get book info");
|
||||
}
|
||||
|
||||
object? isbn_13_raw_array = 0;
|
||||
if (responce.ContainsKey("isbn_13"))
|
||||
{
|
||||
isbn_13_raw_array = responce["isbn_13"];
|
||||
}
|
||||
else if(responce.ContainsKey("isbn_10"))
|
||||
{
|
||||
isbn_13_raw_array = responce["isbn_10"];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Failed to get ISBN");
|
||||
}
|
||||
if (isbn_13_raw_array == null)
|
||||
{
|
||||
throw new Exception("Failed to get book info");
|
||||
}
|
||||
|
||||
List<string> isbn_13_array = JsonSerializer.Deserialize<List<string>>(isbn_13_raw_array.ToString());
|
||||
|
||||
return Book.GetBookFromISBN(isbn_13_array[0])??throw new Exception("Failed to get book info");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Title;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user