Skip to content

OLEditionData WorkKeys not populated with Edition.GetDataSync #17

Description

@bradyguyc

OLEditionData edition = await OLClient.Edition.GetDataAsync(_isbn, OpenLibraryNET.Utility.BookIdType.ISBN);

When I make the above call WorkKeys are not populated tho I have confirmed there are works in openlibrary.

I have used the following method to update OLEditionData after the GetDataAsync call. I suspect there may be a better way.

    public async Task<List<string>> OLGetWorksFromEdition(string editionID)
    {
        // Construct the URL for the API call
        string url = $"https://openlibrary.org/books/{editionID}.json";

        // Make the HTTP GET request
        HttpResponseMessage response = await OLClient.BackingClient.GetAsync(url);

        // Ensure the request was successful
        response.EnsureSuccessStatusCode();

        // Read the response content as a string
        string jsonResponse = await response.Content.ReadAsStringAsync();

        // Parse the JSON response
        JObject json = JObject.Parse(jsonResponse);

        // Extract the works node and return the list of work keys
        List<string> works = json["works"]
            .Select(work => work["key"].ToString().Replace("/works/", ""))
            .ToList();

        return works;
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions