Professional Documents
Culture Documents
Assessment Phreesia
Assessment Phreesia
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
class Program
{
static async Task Main()
{
// Part 3.1: Search for books having "Goodnight Moon" in its title
string searchQuery = "Goodnight Moon";
string apiUrl =
$"https://openlibrary.org/search.json?title={Uri.EscapeDataString(searchQuery)}";
using (HttpClient client = new())
{
HttpResponseMessage response = await client.GetAsync(apiUrl);
if (response.IsSuccessStatusCode)
{
string json = await response.Content.ReadAsStringAsync();
dynamic? data = JsonConvert.DeserializeObject(json);
// Part 3.1.1: Print the total number of books with the exact title
"Goodnight Moon"
int count = 0;
if (data != null)
{
foreach (var doc in data["docs"])
{
string title = doc["title"].ToString();
if (title == searchQuery)
{
count++;
}
}
}
// Part 3.1.2: Print the list of keys of books published since 2000
Console.WriteLine("\n\n");
Console.WriteLine("Part3.1.2");
Console.WriteLine("\n\n");
}
else
{
Console.WriteLine("API request failed. Status code: " +
response.StatusCode);
}
}
Console.WriteLine("\n");
Console.WriteLine("Part3.2");
Console.WriteLine("\n");
// Part 3.2: Search for books with the title "Goodnight Moon Base"
searchQuery = "Goodnight Moon Base";
apiUrl =
$"https://openlibrary.org/search.json?title={Uri.EscapeDataString(searchQuery)}";
if (isResponseValid)
{
Console.WriteLine("Response matches the expected response.");
}
else
{
Console.WriteLine("Response does not match the expected
response.");
Console.WriteLine("Differences:");
End of program
Output Printed: Number of books with the exact title 'Goodnight Moon': 13
Part3.1.2
/works/OL151866W
/works/OL26831311W
/works/OL20081449W
/works/OL25589868W
/works/OL22177520W
/works/OL6219194W
/works/OL30825221W
/works/OL32378068W
/works/OL28095568W
/works/OL22016309W
/works/OL9192921W
/works/OL32412280W
/works/OL30848135W
/works/OL33865575W
/works/OL25057476W
/works/OL27429506W
/works/OL28801632W
/works/OL20411370W
/works/OL21154393W
/works/OL21673796W
/works/OL15047327W
/works/OL9856986W
/works/OL9856987W
/works/OL9856988W
/works/OL9958608W
/works/OL12191021M
/works/OL31229072W
/works/OL27152305W
/works/OL25941945W
/works/OL26595129W
/works/OL26528482W
/works/OL8060810W
/works/OL20763230W
/works/OL7983348M
/works/OL10821269M
/works/OL26559704W
/works/OL7456211W
/works/OL21110117W
/works/OL22138214W
/works/OL17538279W
/works/OL17528078W
/works/OL17569984W
/works/OL17472557W
/works/OL21888381W
/works/OL17416845W
/works/OL21121843W
/works/OL26780641W
/works/OL22162718W
/works/OL31445950W
/works/OL31852531W
/works/OL33915683W
/works/OL25053339W
/works/OL24730072W
/works/OL25117529W
/works/OL25238548W
/works/OL26176586W
/works/OL26145082W
/works/OL27016571W
/works/OL27016621W
/works/OL25687194W
/works/OL26131954W
/works/OL26141510W
/works/OL26135071W
/works/OL24633003W
/works/OL24678602W
/works/OL24554159W
/works/OL24687102W
/works/OL24584777W
/works/OL24623348W
/works/OL24516252W
/works/OL24636752W
/works/OL24710357W
/works/OL24648630W
/works/OL24792500W
/works/OL24701141W
/works/OL24727417W
/works/OL24723615W
Part3.2
Differences:
Property: docs
Expected Value: [
"key": "/works/OL15047325W",
"text": [
"/works/OL15047325W",
"OL9953293M",
"234235364",
"9780061667558",
"HarperFestival",
"OL22122A",
"Juniper Sage",
"Golden MacDonald",
"Timothy Hay"
],
"type": "work",
"seed": [
"/books/OL0000000M",
"/works/OL15047325W",
"/authors/OL22122A"
],
"has_fulltext": false,
"edition_count": 1,
"edition_key": [
"OL9953293M",
"OL11111111"
],
"publish_date": [
"July 1, 2008"
],
"publish_year": [
2008
],
"first_publish_year": 2008,
"oclc": [
"234235364"
],
"contributor": [
],
"isbn": [
"0061667552",
"9780061667558"
],
"last_modified_i": 1582912881,
"ebook_count_i": 0,
"publisher": [
"HarperFestival"
],
"language": [
"eng"
],
"author_key": [
"OL22122A"
],
"author_name": [
],
"author_alternative_name": [
"Juniper Sage",
"Golden MacDonald",
"Timothy Hay"
],
"id_goodreads": [
"2508736"
],
"id_librarything": [
"3377897"
],
"publisher_facet": [
"HarperFestival"
],
"_version_": 1700699423277842432,
"author_facet": [
Actual Value: [
"key": "/works/OL26831311W",
"type": "work",
"seed": [
"/books/OL36885090M",
"/books/OL36421085M",
"/books/OL36410993M",
"/books/OL36381057M",
"/works/OL26831311W",
"/subjects/children's_fiction",
"/subjects/technology",
"/authors/OL9653893A",
"/authors/OL10086113A"
],
"edition_count": 4,
"edition_key": [
"OL36885090M",
"OL36421085M",
"OL36410993M",
"OL36381057M"
],
"publish_date": [
"2021"
],
"publish_year": [
2021
],
"first_publish_year": 2021,
"number_of_pages_median": 32,
"isbn": [
"1956622047",
"9781956622041",
"1956622055",
"1956622063",
"1956622071",
"9781956622072",
"9781956622058",
"9781956622065"
],
"last_modified_i": 1679409950,
"ebook_count_i": 0,
"ebook_access": "no_ebook",
"has_fulltext": false,
"public_scan_b": false,
"readinglog_count": 0,
"want_to_read_count": 0,
"currently_reading_count": 0,
"already_read_count": 0,
"cover_edition_key": "OL36885090M",
"cover_i": 13753793,
"publisher": [
"Aero Maestro"
],
"language": [
"eng"
],
"author_key": [
"OL9653893A",
"OL10086113A"
],
"author_name": [
"Brett Hoffstadt",
"Steve Tanaka"
],
"subject": [
"Children's fiction",
"Technology"
],
"publisher_facet": [
"Aero Maestro"
],
"subject_facet": [
"Children's fiction",
"Technology"
],
"_version_": 1760988970421846016,
"author_facet": [
],
"subject_key": [
"children's_fiction",
"technology"