Search API Examples

Example of how to search using the API:

            TVersityManager target = new TVersityManager(this.BaseUrl);
            SearchOptions searchOptions = new SearchOptions("Search query");
            searchOptions.StartAt = 0;
            searchOptions.Count = 50;
            SearchResponse response = target.MedialibSearch(searchOptions);


All fields within the SearchOptions object are optional. If non are set, TVersity's default values will be used instead.

To iterate all responses, simply use the ResponseItems list within the SearchResponse object:

            foreach (SearchResponseItem sri in response.ResponseItems)
            {
                Console.WriteLine(sri.Title);
                Console.WriteLine(sri.Id);
                //etc
            }


If you want only the Videos, use the Videos list within the SearchResponse object:
            foreach (SearchVideo smi in response.Videos)
            {
                Console.WriteLine(smi.Title);
                Console.WriteLine(smi.Genre);
                // etc
            }


All objects other than SearchResponseItem are "lazy-loaded", meaning their data will only be parsed if needed. This improves performance a bit. Note that if an object's XML is improperly sent back from TVersity for whatever reason, you may only get an error when trying to load these other types.

Last edited Aug 1, 2010 at 8:04 PM by ericdunn, version 4

Comments

No comments yet.