API Series: Facts

 

On this series, we would like to talk about some endpoints that are already available to developers on Codealike.

Let’s start with Facts. You can access any user highlights through codealike.com/facts/soke or you can have access to some of that data through our API.

How to request a user’s Facts profile via Codealike API?

1) You should create a GET request to https://codealike.com/api/v2/facts/[USERNAME]

2) Include 2 header fields:

  • X-Api-Identity
  • X-Api-Token

Each API Token has this structure and you can get yours here:

[IDENTITY]/[TOKEN]

Sample of a real API Token:

 soke/c12060a3-1ace-450a-b4ae-1eaec2effd5b 

It’s expected that the field X-Api-Identity is filled with the [IDENTITY] component and the field X-Api-Token is filled with the [TOKEN] component.

IMPORTANT: You can only get a valid response from this endpoint if:

  • The X-Api-Token is valid.
  • The X-Api-Token belongs to the user filled in the Identity field.
  • [USERNAME] at the URL and X-Api-Identity field are the same.

That means you cannot get the Facts from another user.

If the request is properly built, you’ll get something like this:

{
 "SinceUtc":"2012-02-28T15:38:47.533",
 "ToUtc":"2015-04-06T19:42:54.7004098",
 "DaysOnFire":[
 "2015-02-15T00:00:00",
 "2014-08-02T00:00:00",
 "2014-02-04T00:00:00",
 "2014-02-02T00:00:00",
 "2014-01-07T00:00:00",
 "2013-09-06T00:00:00",
 "2012-09-03T00:00:00",
 "2012-07-28T00:00:00",
 "2012-04-24T00:00:00"
 ],
 "ActivityTimeInMs":16027773286,
 "ActivityPercentage":{
 "Building":4.46,
 "Coding":51.34,
 "Debugging":44.20
 },
 "ByTechnologies":[
 {
 "Name":"C#",
 "Percentage":53.13,
 "Extension":".cs",
 "Categories":[
 "Web",
 "Desktop"
 ]
 },
 {
 "Name":"MVC with Razor (C#)",
 "Percentage":33.62,
 "Extension":".cshtml",
 "Categories":[
 "Web",
 "C#",
 "Html"
 ]
 }
 ]
}

This is what each field represent:

  • SinceUtc: A timestamp representing when the user tracked for the first time their activity at Codealike.
  • ToUtc: A timestamp representing the last time the user tracked their activity at Codealike.
  • DaysOnFire: A timestamps array representing all the days for what the user had outstanding performance.
  • ActivityTimeInMs: A long field representing the sum of all the activity of the user in Milliseconds.
  • ActivityPercentage: An object representing the proportion of time spent among the main three activities (Building, Coding and Debugging).
  • ByTechnologies: An array of objects including the stats for each language used:
    • Each object in this array, contains the following structure:
      • Name: Friendly name of the technology.
      • Percentage: Proportion of time spent over ActivityTimeInMs for each technology.
      • Extension: File extension of the technology.
      • Categories: An array of strings containing categories for each technology. For instance: Web, Html, Desktop, etc.

Well, if you’ve received this beautiful JSON, you can start doing whatever you want, for instance:

  • Your own visualization for Codealike’s Facts.
  • A mobile client just like the one that Bogdan Bujdea did a few months ago for WindowsPhone devices.
  • An alerts and messaging mechanism to warn the users when certain levels of activity are reached.
  • A Widget for embedding stats on you online portfolio or CV.

In further posts, we’ll reveal how to extract other data from the API and play around with some serious stuff.

Enjoy and happy coding!

 

BONUS TRACK: If you want to get the DisplayName and AvatarUri of the user, you can get any users’ profile basic details by using the GET endpoint https://codealike.com/api/v2/account/[USERNAME]/profile. Remember to set the X-Api-Identity and X-Api-Token fields. 😉

Leave a Reply