November 12, 2012

HealthGraphNet - A .NET Library for RunKeeper / HealthGraph

This summer I started running to lose weight. To measure my efforts, I used the RunKeeper iOS app. It's a great product for recording pace, time, distance, location and a whole plethora of other interesting information relevant to your exercise routine.

All of RunKeeper's data gets saved into an API known as the HealthGraph. I was starting to think up some interesting ways to use this information but was dismayed to discover that no one had written a .NET wrapper to integrate with the HealthGraph.

I wanted an easy to use, strongly-typed library, capable of communicating with this REST-based service both synchronously and asynchronously. So I started writing one, called it HealthGraphNet and put it here on GitHub.

The library is comprised of endpoint and model classes. Each endpoint represents a subject within the HealthGraph API (eg. Fitness Activities, Strength Training Activities, Nutrition, Weight, etc) while the models represent the data transfer to and from the service.

Sample use (taken straight out my documentation) in a synchronous situation might look something like this:
//Retrieve the OAuth2 access token.
var tm = new AccessTokenManager(CLIENT_ID, CLIENT_SECRET, REQUEST_URI);

//Retrieve URIs for HealthGraph endpoints.
var userRequest = new UsersEndpoint(tm);
var user = userRequest.GetUser();

//Create a new 30 minute running activity
var newActivity = new FitnessActivitiesNewModel
    Type = "Running",
    StartTime = DateTime.Now,
    Duration = 1800,
    Notes = "Around the park."
var activitiesRequest = new FitnessActivitiesEndpoint(tm, user);
The folks at RunKeeper were kind enough to list HealthGraphNet on their third-party library page. However, the easiest way to get started is to download the library via Nuget.

I've started to add MonoTouch support but this is still a work in progress. Please feel free to fork HealthGraphNet on GitHub. Pull requests are always welcome!