DiggApiNet Documentation
Quick Start

Fetching data from Digg's API begins by creating an instance of the Digg class. You pass your application key to the Digg class constructor, which needs to be a valid URI.

Copy C#
Digg digg = new Digg("http://headzoo.com/DiggApiNet");
					

Alternativly you can pass an instance of System.Uri.

Copy C#
Digg digg = new Digg(new Uri("http://headzoo.com/DiggApiNet"));
					

Once you have an instance of Digg, you use one of the Fetch* classes to get data from the Digg API. The classes are:

  1. FetchComments - For getting comment data
  2. FetchContainers - For getting container (Categories) data
  3. FetchDiggEvents - For getting digg event data
  4. FetchGalleryPhotos - For getting gallery photo data
  5. FetchStories - For fetching story data
  6. FetchUsers - For fetching user data

All of the Digg API end points are separated into those 6 classes to keep things organized, and each one takes a Digg instance in it's constructor.

Copy C#
Digg digg = new Digg("http://headzoo.com/DiggApiNet");
FetchComments comments = new FetchComments(digg);
FetchContainers containers = new FetchContainers(digg);
FetchDiggEvents diggevents = new FetchDiggEvents(digg);
FetchGalleryPhotos galleryphotos = new FetchGalleryPhotos(digg);
FetchStories stories = new FetchStories(digg);
FetchUsers users = new FetchUsers(digg);
					

For the first example, lets request some story data. We'll get the last 10 stories submitted.

Copy C#
Digg digg = new Digg("http://headzoo.com/DiggApiNet");
FetchStories stories = new FetchStories(digg);
DiggList<Story> list = stories.fetchAll();
					

The method stories.FetchAll() returns an instance of DiggList<Story>, which is a collection of Story objects. Each Story object represents a story on Digg, and contains information about the story title, description, who submitted the story, when it was submitted, number of diggs, and more.
The DiggList class is a List, so you can access the Story objects contained within using indexes, or iterating over the object.
Printing the titles and descriptions of the stories by using indexes.

Copy C#
Digg digg = new Digg("http://headzoo.com/DiggApiNet");
FetchStories stories = new FetchStories(digg);
DiggList<Story> list = stories.fetchAll();
Console.WriteLine(list[0].Title);
Console.WriteLine(list[0].Description);

for(int i = 1; i < list.Count; i++) {
	Console.WriteLine(list[i].Title);
	Console.WriteLine(list[i].Description);
}
					

Or you can iterate over the list.

Copy C#
Digg digg = new Digg("http://headzoo.com/DiggApiNet");
FetchStories stories = new FetchStories(digg);
DiggList<Story> list = stories.fetchAll();
foreach(Story story in list) {
	Console.WriteLine(story.Title);
	Console.WriteLine(story.Description);
}
					

It's just as easy to get popular stories.

Copy C#
Digg digg = new Digg("http://headzoo.com/DiggApiNet");
FetchStories stories = new FetchStories(digg);
DiggList<Story> list = stories.fetchPopular();
foreach(Story story in list) {
	Console.WriteLine(story.Title);
	Console.WriteLine(story.Description);
}
					

By default Digg will only return 10 items per request, but you can request up to 100 using the StoriesParameters class.

Copy C#
Digg digg = new Digg("http://headzoo.com/DiggApiNet");
FetchStories stories = new FetchStories(digg);
StoriesParameters parms = new StoriesParameters();
parms.Count = 100;
DiggList<Story> list = stories.fetchAll(parms);
foreach(Story story in list) {
	Console.WriteLine(story.Title);
	Console.WriteLine(story.Description);
}
					

You can use the StoriesParameters class in a lot of ways. For instance to get 100 stories that are only from Flickr.com, you can do this:

Copy C#
Digg digg = new Digg("http://headzoo.com/DiggApiNet");
FetchStories stories = new FetchStories(digg);
StoriesParameters parms = new StoriesParameters();
parms.Count = 100;
parms.Domain = "flickr.com";
DiggList<Story> list = stories.fetchAll(parms);
foreach(Story story in list) {
	Console.WriteLine(story.Title);
	Console.WriteLine(story.Description);
}
					

The Container class is similar to the other classes that represent Digg objects, like Story, User, Comment, etc. The difference is Containers derives from DiggList<Topic>. The Container class not only contains information about the container, but also a list of the topics in that container.

Copy C#
Digg digg = new Digg("http://headzoo.com/DiggApiNet");
FetchContainers containers = new FetchContainers(digg);
DiggList<Container> list = containers.fetchAll();
foreach(Container container in list) {
	Console.WriteLine(container.Name);
	foreach(Topic topic in container) {
		Console.WriteLine(topic.Name);
	}
}
					

The FetchStories class contains dozens of methods. As a final example, you can fetch stories submitted by a specific user by using the User class. You pass a Digg user name to it's constructor.

Copy C#
Digg digg = new Digg("http://headzoo.com/DiggApiNet");
FetchStories stories = new FetchStories(digg);
DiggList<Story> list = stories.FetchUserSubmitted(new User("headzoo"));
foreach(Story story in list) {
	Console.WriteLine(story.Title);
	Console.WriteLine(story.Description);
}
					

There are examples for using each of the Fetch* classes on the document pages for each of the classes (bottom of the pages).