/// <summary> /// Gets the publisher from search. /// </summary> /// <param name="search">The search.</param> /// <returns></returns> public async Task <string[]> GetPublisherFromSearch(string search) { string request = ""; var version = GetISBNVersion(search); if (version == VERSION.INVALID) { request = "http://openlibrary.org/search.json?title=" + Uri.EscapeUriString(search); } else { request = "http://openlibrary.org/search.json?isbn=" + Uri.EscapeUriString(search); } using (HttpClient client = new HttpClient()) { var response = await client.GetAsync(request).ConfigureAwait(false); if (response.IsSuccessStatusCode) { OpenLibrary data = JsonConvert.DeserializeObject <OpenLibrary>(await response.Content.ReadAsStringAsync() .ConfigureAwait(false)); return(data.docs .Select(doc => doc.publisher != null && doc.publisher.Count > 0 ? string.Join(", ", doc.publisher) : "") .Where(s => !string.IsNullOrWhiteSpace(s)).ToArray()); } } return(Array.Empty <string>()); }
/// <summary> /// Gets the information from search. /// </summary> /// <param name="search">The search.</param> /// <returns></returns> public async Task <Doc> GetInfoFromSearch(string search) { string request = ""; var version = GetISBNVersion(search); if (version == VERSION.INVALID) { request = "http://openlibrary.org/search.json?title=" + Uri.EscapeUriString(search); } else { request = "http://openlibrary.org/search.json?isbn=" + Uri.EscapeUriString(search); } using (HttpClient client = new HttpClient()) { var response = await client.GetAsync(request).ConfigureAwait(false); if (response.IsSuccessStatusCode) { OpenLibrary data = JsonConvert.DeserializeObject <OpenLibrary>(await response.Content.ReadAsStringAsync() .ConfigureAwait(false)); var doc = data.docs.Count > 0 ? data.docs[0] : new Doc(); if (doc.isbn != null && doc.isbn.Count > 0) { if (doc.place == null) { doc.place = new List <string>(); } if (doc.place.Count == 0) { doc.place.Add(await GetCountry(doc.isbn[0]).ConfigureAwait(false)); } } return(doc); } } return(new Doc()); }
/// <summary> /// Gets the isbn from search query. /// </summary> /// <param name="search">The search.</param> /// <returns></returns> public async Task <string[]> GetISBNFromSearch(string search) { string request = "http://openlibrary.org/search.json?q=" + Uri.EscapeUriString(search); using (HttpClient client = new HttpClient()) { var response = await client.GetAsync(request).ConfigureAwait(false); if (response.IsSuccessStatusCode) { OpenLibrary data = JsonConvert.DeserializeObject <OpenLibrary>(await response.Content.ReadAsStringAsync() .ConfigureAwait(false)); return(data.docs.Select(doc => doc.isbn != null && doc.isbn.Count > 0 ? doc.isbn[0] : "") .Where(s => !string.IsNullOrWhiteSpace(s)).ToArray()); } } return(Array.Empty <string>()); }
/// <summary> /// /// </summary> /// <param name="e"></param> protected virtual void OpenRequestEvent(OpenLibraryEventArgs e) { OpenLibrary?.Invoke(this, e); }