private void getCategories(Action<List<LevelCategory>> callback)
        {
            List<LevelCategory> categories = new List<LevelCategory>();

            var client = new RestClient("http://webmat.cs.aau.dk/api/");

            var request = new RestRequest(Method.POST);

            request.AddParameter("action", "get_levels");
            request.AddParameter("token", token);

            string data;

            try
            {
                data = client.Execute(request).Content;
            }
            catch (TimeoutException)
            {
                getCategories(callback);
                return;
            }

            JSONObject json = new JSONObject(data);
            JSONArray jsonArray = json.GetJSONArray("data");
            for (int index = 0; index < jsonArray.Length(); index++)
            {
                LevelCategory levelCategory = new LevelCategory(jsonArray.GetJSONObject(index).GetString("name"));
                var levelsData = jsonArray.GetJSONObject(index).GetJSONArray("levels");
                for (int i = 0; i < levelsData.Length(); i++)
                {
                    List<string> starExpressions = new List<string>();
                    var starArray = levelsData.GetJSONObject(i).GetJSONArray("star_expressions");
                    for (int y = 0; y < starArray.Length(); y++)
                    {
                        starExpressions.Add(starArray.GetString(y));
                    }
                    Level level = new Level(
                        levelsData.GetJSONObject(i).GetInt("id"),
                        levelsData.GetJSONObject(i).GetString("initial_expression"),
                        levelsData.GetJSONObject(i).GetInt("stars"),
                        levelsData.GetJSONObject(i).GetString("current_expression"),
                        starExpressions.ToArray());
                    levelCategory.Add(level);
                }
                categories.Add(levelCategory);
            }
            callback(categories);

        }
		private void GetCategories(Action<List<LevelCategory>> callback)
		{
			JObject response = MakeRequest ("http://webmat.cs.aau.dk/api/?action=get_levels", true);

			List<LevelCategory> categories = new List<LevelCategory>();

			JArray data = response.SelectToken ("data") as JArray;
			for (int index = 0; index < data.Count; index++)
			{
				LevelCategory levelCategory = new LevelCategory(data[index].Value<string>("name"));
				JArray levelsData = data [index].SelectToken ("levels") as JArray;
				for (int i = 0; i < levelsData.Count; i++)
				{
					List<string> starExpressions = new List<string>();
					JArray starArray = levelsData[i].SelectToken ("star_expressions") as JArray;
					for (int j = 0; j < starArray.Count; j++)
					{
						starExpressions.Add(starArray[j].ToString());
					}
					Level level = new Level(
						int.Parse(levelsData[i].SelectToken("id").Value<string>()),
						levelsData[i].SelectToken("initial_expression").Value<string>(),
						int.Parse(levelsData[i].SelectToken("stars").Value<string>()),
						levelsData[i].SelectToken("initial_expression").Value<string>(),
						starExpressions.ToArray());
					levelCategory.Add(level);
				}
				categories.Add(levelCategory);
			}
			callback(categories);
		}
        private void getCategories(Action<List<LevelCategory>> callback)
        {
            jQuery.Post(
                "/api/",
                new
                {
                    action = "get_levels",
                    token = token
                },
                (data, textStatus, request) =>
                {
                    var jdata = JSON.Parse((string)data);
                    List<LevelCategory> categories = new List<LevelCategory>();
                    var categoriesData = jdata["data"] as object[];
                    foreach (var categoryData in categoriesData)
                    {

                        LevelCategory levelCategory = new LevelCategory((string)categoryData["name"]);
                        var levelsData = categoryData["levels"] as object[];

                        foreach (var levelData in levelsData)
                        {
                            Level level = new Level(
                                int.Parse((string)levelData["id"]),
                                (string)levelData["initial_expression"],
                                int.Parse((string)levelData["stars"] ?? "0"),
                                (string)levelData["current_expression"],
                                (levelData["star_expressions"] as object[]).Select((o) => (string)o).ToArray());
                            levelCategory.Add(level);
                        }
                        categories.Add(levelCategory);
                    }

                    callback(categories);
                }
            );
        }