14 Replies - 4532 Views - Last Post: 28 April 2011 - 01:41 PM

#1 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

CherryTomato - .NET C# RottenTomatoes Library

Post icon  Posted 18 April 2011 - 12:17 PM

CherryTomato

CherryTomato makes using information provided by RottenTomatoes.com very simple. It's aim is to allow developers to quickly and safely create powerful applications with the JSON api provided for free by RottenTomatoes.

Full C# POCO objects allow you to concentrate on creating a great application and not parsing random JSON from a source.

Standing on the Shoulders of Giants

CherryTomato is proudly powered by the phenomenal library JSON.Net provided for free by James Newton.

http://james.newtonk...s/json-net.aspx


Introduction to CherryTomato


    string apiKey = ConfigurationManager.AppSettings["ApiKey"];
    var tomatoe = new Tomatoe(apiKey);
 
    //Numerical ID in this case is 9818.
    var movie = tomatoe.FindMovieById(9818);
   
    Console.WriteLine(movie.Name);
    Console.WriteLine(movie.Year);
    foreach (var rating in movie.Ratings)
    {
        Console.WriteLine("{0} Rating: {1}", rating.Type, rating.Score);
    }

    Console.ReadKey();



Please report any bugs you may find. If you report it, I'll fix it and we can all benefit from a better library.
:)

This post has been edited by Sergio Tapia: 18 April 2011 - 12:56 PM


Is This A Good Question/Topic? 4
  • +

Replies To: CherryTomato - .NET C# RottenTomatoes Library

#2 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,903
  • Joined: 08-June 10

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 18 April 2011 - 01:09 PM

Our libraries look strikingly similar, even to the point of using the same name for MovieSearchResult. Wow. I'll be posting mine tonight.

I used a little more LINQ, and more static methods, but that's about all the difference.

This post has been edited by Curtis Rutland: 18 April 2011 - 01:09 PM

Was This Post Helpful? 0
  • +
  • -

#3 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 445
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 18 April 2011 - 03:00 PM

My library is similar in some regards, obviously since we're dealing with the same api, but has some distinct differences. For one I am not using any 3rd party libraries. I'll post some of my code when I get home
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,903
  • Joined: 08-June 10

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 18 April 2011 - 03:05 PM

So you're manually parsing the JSON? Nice. More effort than I was willing to expend.
Was This Post Helpful? 0
  • +
  • -

#5 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 18 April 2011 - 03:13 PM

Just pointing this out, but there is a built-in JSON parser in .NET Framework.

http://msdn.microsof...son(VS.95).aspx

It's a Silverlight assembly, by the way.
Was This Post Helpful? 1
  • +
  • -

#6 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 18 April 2011 - 05:05 PM

Wow, it's great that so many people are working on the same thing. Let's all contribute to the same lib then, I know Curtis is familiar with Github, how about you Nakor?

Let's collaborate on CherryTomato and make it the best RT lib out there for .NET. :)
Was This Post Helpful? 0
  • +
  • -

#7 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 445
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 18 April 2011 - 05:09 PM

There is also the JavascriptSerializer class in System.Web.Extensions, which is what I used to convert the JSON into objects.

First, the Movie class and the smaller classes it uses

Spoiler


The MovieList class
Spoiler


And here's the class that provides access to the data

Spoiler


The JavascriptSerializer.Deserialize() method does all the work of converting the JSON string into the object, no parsing needed on my part.
Was This Post Helpful? 0
  • +
  • -

#8 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 18 April 2011 - 05:11 PM

The main downside I see when using that method, is that you no longer have a way to manually shape your POCO objects to make them seem natural.

Unless I'm mistaken.
Was This Post Helpful? 0
  • +
  • -

#9 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 445
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 18 April 2011 - 05:17 PM

To manually shape it in what way?
Was This Post Helpful? 0
  • +
  • -

#10 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,903
  • Joined: 08-June 10

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 18 April 2011 - 05:17 PM

Check my sig for the link to my github repo, the project is called RottenTomatoes.NET (yes, I know I'm unimaginative). What I've done differently than you, Sergio, is include Review and Full Cast support, as well as providing easy access to getting the next search results. Also, you can take a movie created from the Search, and have it fill itself in.

I've also added asynchronous versions of most of the methods, with events to be called when they're completed.

Also, I've marked the classes as DataContracts, and the members as DataMembers for easy WCF Serialization.

Take a look at my project and see what you think.
Was This Post Helpful? 0
  • +
  • -

#11 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 18 April 2011 - 05:25 PM

Yeah you seem to be doing some of the things I had planned except for the WCF bit, I didn't plan on providing that for now.

Most of the things that I have missing I'm going to add tonight though. :D

Edit: I also think I'm going to completely rewrite the search area of my lib. If it takes more than a 10 seconds to understand what's going on, that's a glaring sign that the code needs to be refactored and made beautiful. And I love beautiful code. :D

If anyone reading actually likes the act of coding, you need to read this at least once every couple of years. It always gives something more. :)

Clean Code.

This post has been edited by Sergio Tapia: 18 April 2011 - 05:58 PM

Was This Post Helpful? 0
  • +
  • -

#12 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 18 April 2011 - 05:35 PM

Curtis, I already told this to Sergio and just to point out - it would be great when methods that have the same idea behind them have similar naming. So, for example, you have this:

public static Movie GetById
public static MovieSearchResult Search

Why not name these with something like GetMovieById and GetMovieByQuery?
Was This Post Helpful? 1
  • +
  • -

#13 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,903
  • Joined: 08-June 10

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 18 April 2011 - 05:55 PM

Took me a sec to realize you were talking to me, lol.

Couldn't hurt. I'd have to be GetMoviesByQuery or BySearch, since it returns a collection, but it's a good idea.
Was This Post Helpful? 0
  • +
  • -

#14 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 20 April 2011 - 05:57 PM

I significantly modified the Parser.cs class and it's now a lot easier to read and understand what it's doing. I'm proud of this! :D

/// <summary>
/// Parse a JSON string representing a Movie item
/// </summary>
/// <param name="json">The JSON string to be parsed</param>
/// <returns>Movie object</returns>
public static Movie ParseMovie(string json)
{
    JObject jObject = JObject.Parse(json);
    Movie movie = new Movie();

    movie.RottenTomatoesId = ParseRottenTomatoesId(jObject["id"]);
    movie.Title = ParseTitle(jObject["title"]);
    movie.Year = ParseYear(jObject["year"]);
    movie.MpaaRating = ParseMpaaRating(jObject["mpaa_rating"]);
    movie.Runtime = ParseRunTime(jObject["runtime"]);
    movie.Synopsis = ParseSynopsis(jObject["synopsis"]);
    movie.Directors = ParseDirectors(jObject["abridged_directors"]);
    movie.Genres = ParseGenres(jObject["genres"]);
    movie.Cast = ParseCastMembers(jObject["abridged_cast"]);
    movie.Links = ParseLinks(jObject["links"]);
    movie.Posters = ParsePosters(jObject["posters"]);
    movie.Ratings = ParseRatings(jObject["ratings"]);
    movie.ReleaseDates = ParseReleaseDates(jObject["release_dates"]);

    return movie;
}



I have to some testing to do tonight and by tomorrow it should be 'production' ready.

I had a lot of help from Nakor and I really enjoy collaborating with him. :D

Use it, break it, fork it and let's make this one kick ass lib. Check my signature for a link to the Github.

This post has been edited by Sergio Tapia: 20 April 2011 - 05:59 PM

Was This Post Helpful? 0
  • +
  • -

#15 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: CherryTomato - .NET C# RottenTomatoes Library

Posted 28 April 2011 - 01:41 PM

View PostSergio Tapia, on 20 April 2011 - 08:57 PM, said:

Use it, break it, fork it and let's make this one kick ass lib. Check my signature for a link to the Github.

If you replace your movie class with this:
namespace CherryTomato.Entities
{
    public class Movie : IComparable
    {
        public int id { get; set; }
        public string title { get; set; }
        public int year { get; set; }
        public string mpaa_rating { get; set; }
        public int? runtime { get; set; }
        public string synopsis { get; set; }
        public Dictionary<string,DateTime> release_dates { get; set; }
        public Dictionary<string,int> ratings { get; set; }
        public List<string> genres { get; set; }
        public List<Director> abridged_directors { get; set; }
        public List<CastMember> abridged_cast { get; set; }
        public Dictionary<string, string> links { get; set; }
        public Dictionary<string, string> posters { get; set; }

        public int CompareTo(object obj)
        {
            throw new NotImplementedException();
        }
        public class CastMember
        {
            public string name { get; set; }
            public List<string> characters { get; set; }

            public CastMember()
            {
                characters = new List<string>();
            }
        }
        public class Director
        {
            public string name { get; set; }

        }
    }
}



All of your parsing code can be replaced with:
Movie m = Newtonsoft.Json.JsonConvert.DeserializeObject<Movie>(json);


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1