Simple Movie Finder App with Windows Phone 7

I haven’t done much mobile developement since my senior design project at Drexel, which is why I chose to play once again with Windows Phone 7. The exercise or Code Kata I decided upon is a simple movie information finder. Nothing fancy. Pass in the movie title, get back the plot, the picture, the duration, and other bits of information about the movie. Just enough to be completed in a single sitting of less than 2h.

The hardest part of this exercise was finding a movie database. For reasons I fail to understand, IMDB does not provide an REST API for their movie database. Lucky for me, Brian Fritz did that for them.

The only thing left for me to do was to write the app, query the movie database, and display the data. Trivial. To make things even simpler (I love Open Source), I used RestSharp to handle retrieving the data for me and deserializing it…though the deserialization did not work.


public class Finder
{
RestClient client = new RestClient("http://www.imdbapi.com/");
public delegate void FindingMovie(string content);
public event FindingMovie OnMovieFound;
public void FindMovie(string title)
{
var request = new RestRequest(string.Format("?i=&t={0}&plot=full", title),Method.GET);
request.RequestFormat = DataFormat.Json;
client.ExecuteAsync<Movie>(request, Callback());
}
private Action<RestResponse<Movie>> Callback()
{
return (e) => OnMovieFound(e.Content);
}
}

view raw

gistfile1.cs

hosted with ❤ by GitHub

Because the Movie object contained in the response was always null, I ended up using Json.Net to deserialize the returned Json data.


void OnMovieFound(string content)
{
var movie = JsonConvert.DeserializeObject<Movie>(content);
if (movie != null && movie.Response == "True")
{
this.movieTitleTextBlock.Text = movie.Title;
this.plotTextBlock.Text = movie.Plot;
this.ratingTextBlock.Text = movie.Rating;
this.releasedDattetextBlock.Text = movie.Released;
this.runtimetextBlock.Text = movie.Runtime;
this.posterImage.Source = new BitmapImage(new Uri(movie.Poster));
}
else
{
MessageBox.Show(string.Format("No movie could be found for Movie titled {0}", searchTextBox.Text));
}
}

view raw

gistfile1.cs

hosted with ❤ by GitHub

Voila!

Movie find

All in less than 2 hours, just the way code katas ought to be.

Simple Movie Finder App with Windows Phone 7

Leave a comment