Permalink
Browse files

added support for leaderboard count and get assets

  • Loading branch information...
1 parent 0301dc0 commit d6e511989b10f0fa57084b32b3f6d618630ece2f Karl Seguin committed Aug 28, 2011
View
@@ -57,6 +57,17 @@ public void GetLeaderboard(string leaderboardId, LeaderboardScope scope, string
});
}
+ public void GetLeaderboardCount(string leaderboardId, LeaderboardScope scope, Action<Response<int>> callback)
+ {
+ var payload = new Dictionary<string, object> { { "lid", leaderboardId }, { "scope", (int)scope } };
+ var communicator = new Communicator(this);
+ communicator.SendPayload<int>(Communicator.Get, "scores/count", payload, r =>
+ {
+ if (r.Success) { r.Data = JsonConvert.DeserializeObject<int>(r.Raw); }
+ callback(r);
+ });
+ }
+
private void GetLeaderboard(IDictionary<string, object> payload, Action<Response<LeaderboardScores>> callback)
{
var communicator = new Communicator(this);
@@ -182,5 +193,16 @@ public void LogError(string subject, string details, Action<Response> callback)
if (callback != null) { callback(r); }
});
}
+
+ public void GetAssets(Action<Response<IList<Asset>>> callback)
+ {
+ var payload = new Dictionary<string, object>() {{"key", Key}};
+ var communicator = new Communicator(this);
+ communicator.SendPayload<IList<Asset>>(Communicator.Get, "assets", payload, r =>
+ {
+ if (r.Success) { r.Data = JsonConvert.DeserializeObject<IList<Asset>> (r.Raw); }
+ if (callback != null) { callback(r); }
+ });
+ }
}
}
View
@@ -60,6 +60,14 @@ public interface IDriver
void GetLeaderboard(string leaderboardId, LeaderboardScope scope, string userName, string uniqueIdentifier, Action<Response<Score>> callback);
/// <summary>
+ /// Gets the number of scores in a leaderboard (up to 25 000)
+ /// </summary>
+ /// <param name="leaderboardId">The id of the leaderboard to get the scores from</param>
+ /// <param name="scope">The scope to get the scores from (daily, weekly or overall)</param>
+ /// <returns>The number of scores</returns>
+ void GetLeaderboardCount(string leaderboardId, LeaderboardScope scope, Action<Response<int>> callback);
+
+ /// <summary>
/// Gets a user's rank across all scopes
/// </summary>
/// <param name="leaderboardId">The id of the leaderboard to get the scores from</param>
@@ -145,5 +153,11 @@ public interface IDriver
/// <param name="details">the error's details</param>
/// <param name="callback">the callback (null can safely be passed in)</param>
void LogError(string subject, string details, Action<Response> callback);
+
+ /// <summary>
+ /// Gets the game's assets
+ /// </summary>
+ /// <param name="callback">A list of assets</param>
+ void GetAssets(Action<Response<IList<Asset>>> callback);
}
}
@@ -0,0 +1,13 @@
+using System;
+
+namespace Mogade
+{
+ public class Asset
+ {
+ public string Name { get; set; }
+ public int Type { get; set; }
+ public DateTime Dated { get; set; }
+ public string File { get; set; }
+ public string Meta { get; set; }
+ }
+}
@@ -46,6 +46,7 @@
<Compile Include="Components\Communicator.cs" />
<Compile Include="Components\IRequestContext.cs" />
<Compile Include="Models\Achievement.cs" />
+ <Compile Include="Models\Asset.cs" />
<Compile Include="Models\Highs.cs" />
<Compile Include="Models\LeaderboardScores.cs" />
<Compile Include="Models\LeaderboardScope.cs" />
@@ -61,6 +61,7 @@
<Compile Include="Driver.cs" />
<Compile Include="IDriver.cs" />
<Compile Include="Models\Achievement.cs" />
+ <Compile Include="Models\Asset.cs" />
<Compile Include="Models\Highs.cs" />
<Compile Include="Models\LeaderboardScope.cs" />
<Compile Include="Models\LeaderboardScores.cs" />
@@ -0,0 +1,33 @@
+using System;
+using NUnit.Framework;
+
+namespace Mogade.Tests.AssetTests
+{
+ public class GetAssetsTests : BaseFixture
+ {
+ [Test]
+ public void SendsRequestForTheAssetsToTheServer()
+ {
+ Server.Stub(new ApiExpectation { Method = "GET", Url = "/gamma/assets", Request = "key=akey", Response = "[]" });
+ new Driver("akey", "sssshh2").GetAssets(SetIfSuccess);
+ WaitOne();
+ }
+
+ [Test]
+ public void RetrievesTheAssets()
+ {
+ Server.Stub(new ApiExpectation { Response = "[{name: 'a-name', type: 33, dated: '2009-02-16T04:06:06Z', file: 'a.zip', meta: 'har'}]" });
+ new Driver("akey", "sssshh2").GetAssets(response =>
+ {
+ Assert.AreEqual(1, response.Data.Count);
+ Assert.AreEqual("a-name", response.Data[0].Name);
+ Assert.AreEqual("a.zip", response.Data[0].File);
+ Assert.AreEqual(33, response.Data[0].Type);
+ Assert.AreEqual(new DateTime(2009, 2, 16, 4, 6, 6), response.Data[0].Dated.ToUniversalTime());
+ Assert.AreEqual("har", response.Data[0].Meta);
+ Set();
+ });
+ WaitOne();
+ }
+ }
+}
@@ -0,0 +1,27 @@
+using NUnit.Framework;
+
+namespace Mogade.Tests.LeaderboardsTest
+{
+ public class GetLeaderboardCountTests : BaseFixture
+ {
+ [Test]
+ public void SendsRequestForLeaderboardCountToTheServer()
+ {
+ Server.Stub(new ApiExpectation { Method = "GET", Url = "/gamma/scores/count", Request = "lid=theid&scope=2", Response = "0" });
+ new Driver("akey", "sssshh2").GetLeaderboardCount("theid", LeaderboardScope.Weekly, SetIfSuccess);
+ WaitOne();
+ }
+
+ [Test]
+ public void RetrievesACount()
+ {
+ Server.Stub(new ApiExpectation { Response = "55" });
+ new Driver("akey", "sssshh2").GetLeaderboardCount("theid", LeaderboardScope.Weekly, response =>
+ {
+ Assert.AreEqual(55, response.Data);
+ Set();
+ });
+ WaitOne();
+ }
+ }
+}
@@ -45,6 +45,7 @@
<ItemGroup>
<Compile Include="Achievements\AchievementEarnedTests.cs" />
<Compile Include="Achievements\GetEarnedAchievementsTests.cs" />
+ <Compile Include="AssetTests\GetAssetsTests.cs" />
<Compile Include="ErrorsTests\LogErrorTests.cs" />
<Compile Include="InstructureTests\CoreCommunicationTests.cs" />
<Compile Include="FakeContext.cs" />
@@ -58,6 +59,7 @@
<Compile Include="InstructureTests\SignatureTests.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="LeaderboardsTest\GetLeaderboardCountTests.cs" />
<Compile Include="LeaderboardsTest\GetLeaderboardTests.cs">
<SubType>Code</SubType>
</Compile>
Binary file not shown.
Binary file not shown.

0 comments on commit d6e5119

Please sign in to comment.