Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.8.1 GetTvShowChangesAsync returns a JToken in TMDbLib.Objects.Changes.ChangesContainer #380

Closed
mpfc75 opened this issue Jul 2, 2021 · 8 comments

Comments

@mpfc75
Copy link
Contributor

mpfc75 commented Jul 2, 2021

I'm trying to work with GetTvShowChangesAsync which returns a TMDbLib.Objects.Changes.ChangesContainer. Drilling down to the Item list there is a Value field of type JToken. I am having difficulty accessing the data in it. Should this be a JToken or something else?

@mpfc75
Copy link
Contributor Author

mpfc75 commented Jul 2, 2021

It seems that GetTvSeasonChangesAsync and GetTvEpisodeChangesAsync responses also contain JTokens.

@mpfc75
Copy link
Contributor Author

mpfc75 commented Jul 2, 2021

Looking at it further, is there a way to pass the optional start and end dates, or the page?

@LordMike
Copy link
Collaborator

LordMike commented Jul 3, 2021

As I recall, I made those values JTokens as I can't say anything about their contents. Iirc, the contents correspond to the actual change that was made, f.ex. when adding it could be the values that were added etc.

The value is a Newtonsoft JToken, so you could make your own object if you know what to expect, and convert to it like .Value.ToObject<MyObject>(). You can also inspect the Json document programmatically or convert it to a string representation like .Value.ToString().

As for pagination - there are both start, end and page parameters.

@mpfc75
Copy link
Contributor Author

mpfc75 commented Jul 3, 2021

Part of my struggle is that I'm not seeing .Value available to me. Here is a sample snippet. As you can see, I can have Action, Id, Iso_639_1, and Time. But the JToken fields OriginalValue and Value appear inaccessible.
image

Regarding start, end, and page... I see them on the Season and Episode change methods, but they aren't on the Show method.
https://developers.themoviedb.org/3/tv/get-tv-changes

Thanks!

@LordMike
Copy link
Collaborator

LordMike commented Jul 7, 2021

I've created this example that shows how it can be used. I still can't say anything about the value, hence it being an object, which depends on what the serializer (by default Newtonsoft.Json) decides to use. This is the JToken you see.

I can also see where your confusion comes from. The ChangeItemBase is an abstract type. In your screenshot, you're inspecting a ChangeItemUpdated. The example below uses type matching to show all types.

var changes = await client.GetMovieChangesAsync(848533);

// Example serialization back to json
var json = TMDbJsonSerializer.Instance.SerializeToString(changes);

foreach (var change in changes)
{
    Console.WriteLine("Key: " + change.Key);
    foreach (ChangeItemBase item in change.Items)
    {
        Console.WriteLine(" - Id: " + item.Id);
        switch (item)
        {
            case ChangeItemAdded changeItemAdded:
                Console.WriteLine("   Added: " + changeItemAdded.Value);
                break;
            case ChangeItemCreated changeItemCreated:
                Console.WriteLine("   Created");
                break;
            case ChangeItemDeleted changeItemDeleted:
                Console.WriteLine("   Deleted: " + changeItemDeleted.OriginalValue);
                break;
            case ChangeItemDestroyed changeItemDestroyed:
                Console.WriteLine("   Destroyed: " + changeItemDestroyed.Value);
                break;
            case ChangeItemUpdated changeItemUpdated:
                Console.WriteLine("   Updated: " + changeItemUpdated.OriginalValue + " => " + changeItemUpdated.Value);
                break;
            default:
                throw new ArgumentOutOfRangeException(nameof(item));
        }
    }

    Console.WriteLine();
}

image

@LordMike LordMike closed this as completed Jul 7, 2021
@mpfc75
Copy link
Contributor Author

mpfc75 commented Jul 7, 2021

Thanks for your reply.
GetMovieChangesAsync returns Task<IList<Change>>
GetTvEpisodeChangesAsync returns Task<IList<Change>>
GetTvSeasonChangesAsync returns Task<IList<Change>>

GetTvShowChangesAsync returns Task<ChangesContainer> (not IList).

Your sample (thank you for it) works for Movies, but not for TVShows.

And, I'm afraid I still don't see start, end, or page on
public Task<ChangesContainer> GetTvShowChangesAsync(int id, CancellationToken cancellationToken = default);

@LordMike
Copy link
Collaborator

LordMike commented Jul 8, 2021

I see that. The four methods could all have been of one or the other type, this is just inconcistency. I've created #381.

The sample should be the same, albeit with minor modifications. The ChangesContainer wraps a List<Change>, which in turn has the ChangeItemBase which the sample works on.

I can also see the mismatch of parameters in those methods, it could be that a lot of methods are like this. So if you're up for it, you can try adding some of these parameters - f.ex. just for the TV Shows Client. I've created #382 for this.

Mike.

@mpfc75
Copy link
Contributor Author

mpfc75 commented Jul 9, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants