Retrieves a RedCritter team leaderboard.
This version of the GetTeamLeaderboard retrieves the team leaderboard based on the name of the leaderboard.
https://redcritterconnecter.com/services/gamificationv1/GetTeamLeaderboard?SecretKey={SecretKey}&LeaderboardName={LeaderboardName}
SecretKey | string | yes | This SecretKey is an App or App Domain Secret Key. If an App Secret Key is specified, your default App Domain will be assumed. If an App Domain Secret Key is specified, that App Domain will be used. |
LeaderboardName | string | yes | The LeaderboardName parameter represents the RedCritter leaderboard that you want to retrieve. The following characters cannot be used : | = [ ] , ; |
Code Samples Javascript, C#
GetTeamLeaderboard with JavaScript
This is a minimal example of calling the GetTeamLeaderboard API via HTML and Javascript. Remember to never use your Secret Keys on the client side.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script>
<style type='text/css'>
body {
font-family: "Arial";
}
.rctable{
padding-top:20px;
padding-bottom:10px;
border-bottom:solid 1px #ccc;
width:600px;
}
.rclabel {
font-size:14px;
font-weight:bold;
}
.rcval{
font-size:14px;
padding-left:10px;
}
</style>
<script type="text/javascript">
var connecterURL = "https://www.redcritterconnecter.com/";
function getTeamLeaderboard(secretKey, leaderboardName, cbSuccess, cbFail) {
$.getJSON(connecterURL + "services/gamificationv1/getTeamLeaderboard?jsoncallback=?", { secretKey: secretKey, leaderboardName: leaderboardName },
function (data) {
if (data.Result) {
cbSuccess(data);
} else {
cbFail(data);
}
});
}
//My Success Callback
function onMygetTeamLeaderboardSuccessHandler(data) {
//data is JSON response
renderItems(data)
}
//My Failure Callback
function onMygetTeamLeaderboardFailHandler(data) {
//Something went wrong
alert("Something went wrong");
}
//Sample function to generate the list output in html
function renderItems(data) {
var h = "";
if (data.Teams.length == 0) {
// no rewards
h = "Sorry, there are no Teams on the Leaderboard..";
} else {
//render each Team
for (var i = 0; i < data.Teams.length; i++) {
h = h+ generateItemHTML(data.Teams[i]);
}
}
//display the results
$("#results").html(h);
}
function generateItemHTML(item) {
var h = "<table class='rctable'>";
h += "<tr><td class='rclabel'>TeamID : </td><td class='rcval'>" + HTMLEncode(item.TeamID) + "</td></tr>"
h += "<tr><td class='rclabel'>Team Name : </td><td class='rcval'>" + HTMLEncode(item.TeamName) + "</td></tr>"
h += "<tr><td class='rclabel'>Points : </td><td class='rcval'>" + HTMLEncode(item.Points) + "</td></tr>"
h += "<tr><td class='rclabel'>Rank : </td><td class='rcval'>" + HTMLEncode(item.Rank) + "</td></tr>"
h += "</table>";
return h
}
function HTMLEncode(str) {
var div = document.createElement('div');
var text = document.createTextNode(str);
div.appendChild(text);
return div.innerHTML;
}
</script>
</head>
<body>
<table>
<tr>
<td>Secret Key</td>
<td>
<input type="text" id="tSecretKey" style="width: 500px" />
</td>
</tr>
<tr>
<td>LeaderboardName</td>
<td>
<input type="text" id="tLeaderboardName" style="width: 500px" />
</td>
</tr>
<tr>
<td></td>
<td>
<input type="button" onclick="getTeamLeaderboard($('#tSecretKey').val(), $('#tLeaderboardName').val(), onMygetTeamLeaderboardSuccessHandler, onMygetTeamLeaderboardFailHandler)" value="Get Team Leaderboard" /></td>
</tr>
</table>
<br />
<div id="results"></div>
</body>
</html>
GetTeamLeaderboard with C#
This is a minmal example of calling the GetTeamLeaderboard API and parsing the JSON result into a populated C# object. This example uses asynchronous techniques to raise a callback when the response is received.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Web; //Add reference to System.Web
using System.Runtime.Serialization.Json; //Add reference to System.Runtime.Serialization
namespace RedCritterConnecter.Samples
{
//Create a class to contain the response
public class GetTeamLeaderboardResponse
{
public Int64 UserID { get; set; }
public String TeamID { get; set; }
public String ProfileEntity { get; set; }
public Int64 AppID { get; set; }
public Int64 AppDomainID { get; set; }
public Boolean Result { get; set; }
private Int32 ErrorCode { get; set; }
public Int32 RewardPoints { get; set; }
public String APIVersion { get; set; }
public String ErrorMessage { get; set; }
public Int32 AuthErrorCode { get; set; }
public List<LeaderboardTeam> Teams { get; set; }
}
public class LeaderboardTeam
{
public String TeamID { get; set; }
public String TeamName { get; set; }
public Int32 Rank { get; set; }
public Double Points { get; set; }
public Boolean OnBoard { get; set; }
}
public class GetTeamLeaderboard
{
public delegate void OnGetTeamLeaderboardResponse(GetTeamLeaderboardResponse GetTeamLeaderboardResponse);
public event OnGetTeamLeaderboardResponse onGetTeamLeaderboardResponse;
public delegate void OnGetTeamLeaderboardResponseError(GetTeamLeaderboardResponse GetTeamLeaderboardResponse);
public event OnGetTeamLeaderboardResponseError onGetTeamLeaderboardResponseError;
const string CONST_ConnecterBaseURL = "https://www.redcritterconnecter.com/";
public void Execute(String SecretKey, String Leaderboard)
{
try
{
//Create url encoded parameters in query string
String queryString = "secretkey=" + System.Web.HttpUtility.UrlEncode(SecretKey) + "&leaderboardname="+ System.Web.HttpUtility.UrlEncode(Leaderboard);
//Create a new instance of a WebClient
WebClient wc = new System.Net.WebClient();
//Prevent this request from caching in order to ensure that it is sent to server
wc.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
//Attach an event handler to receive the response
wc.DownloadStringCompleted += onGetTeamLeaderboardResponseReceived;
//Make the call
wc.DownloadStringAsync(new Uri(CONST_ConnecterBaseURL + "services/gamificationv1/GetTeamLeaderboard?" + queryString, UriKind.Absolute));
}
catch
{
//Something went wrong communicating with the server
if (onGetTeamLeaderboardResponseError != null)
{
onGetTeamLeaderboardResponseError(null);
}
}
}
private void onGetTeamLeaderboardResponseReceived(object sender, DownloadStringCompletedEventArgs e)
{
try
{
//Create a JSON serializer
System.Runtime.Serialization.Json.DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(GetTeamLeaderboardResponse));
//Copy the string into a memory stream
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(e.Result));
//Read the stream into an object matching the response's type
GetTeamLeaderboardResponse GetTeamLeaderboardResponse = (GetTeamLeaderboardResponse)s.ReadObject(ms);
//Work with the populated response object
if (GetTeamLeaderboardResponse.Result == true)
{
//Request was accepted, raise the success event
onGetTeamLeaderboardResponse(GetTeamLeaderboardResponse);
}
else
{
//Something went wrong
if (onGetTeamLeaderboardResponseError != null)
{
//Request failed, raise the error event
onGetTeamLeaderboardResponseError(GetTeamLeaderboardResponse);
}
}
}
catch
{
//Something went wrong
onGetTeamLeaderboardResponseError(null);
}
}
}
}
Responses JSON, XML
JSON Response
{
"LeaderboardName": "Test",
"LeaderboardID": 17,
"AppID": 40,
"AppName": "Office Heroes",
"AppIconURL": "http://connecterstoredev.blob.core.windows.net/apps/appicon_40_{s|m|l}.png",
"AppDomainID": 59,
"ExternalAccountID": "(Default)",
"LeaderboardReadKey": "LBT-40-59-17-635115082809900000-635126881090270000",
"LeaderboardDescription": "Test Leaderboard",
"Users": [],
"Teams": [
{
"TeamID": "8/21/2013 6:15:38 PM",
"TeamName": "TestTeam",
"Rank": 1,
"Points": 1.0,
"OnBoard": true
}
],
"Result": true,
"ErrorMessage": "",
"ErrorCode": 0,
"APIVersion": "1.0.0",
"AuthErrorCode": 0
}
XML Response
<Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="Connecter">
<APIVersion>1.0.0</APIVersion>
<AuthErrorCode>0</AuthErrorCode>
<ErrorMessage />
<AppDomainID>59</AppDomainID>
<AppID>40</AppID>
<AppIconURL>
http://connecterstoredev.blob.core.windows.net/apps/appicon_40_{s|m|l}.png
</AppIconURL>
<AppName>Office Heroes</AppName>
<ErrorCode>0</ErrorCode>
<ExternalAccountID>(Default)</ExternalAccountID>
<LeaderboardDescription>Test Leaderboard</LeaderboardDescription>
<LeaderboardID>17</LeaderboardID>
<LeaderboardName>Test</LeaderboardName>
<LeaderboardReadKey>LBT-40-59-17-635115082809900000-635126881090270000</LeaderboardReadKey>
<Result>true</Result>
<Teams>
<Team>
<OnBoard>true</OnBoard>
<Points>1</Points>
<Rank>1</Rank>
<TeamID>8/21/2013 6:15:38 PM</TeamID>
<TeamName>TestTeam</TeamName>
</Team>
</Teams>
<Users />
</Response>
This version of the GetTeamLeaderboard retrieves the team leaderboard based on the App Domain and name of the leaderboard. The Secret Key must be the App Secret Key.
https://redcritterconnecter.com/services/gamificationv1/GetTeamLeaderboard?SecretKey={SecretKey}&ExternalAccountID={ExternalAccountID}&LeaderboardName={LeaderboardName}
SecretKey | string | yes | This SecretKey is an App Secret Key.The App Domain is determined by the External Account ID you provide. |
ExternalAccountID | string | yes | A unique ID for an App Domain that you create and manage. For example an App could have 2 App Domains managed separately by specifying an ExternalAccountID of 'Sales Dept' or 'IT Dept'. When passed as a parameter if the External Account ID does not exist. RedCritter Connecter will create a new App Domain on the fly with the ID that you specify. |
LeaderboardName | string | yes | The LeaderboardName parameter represents the RedCritter leaderboard that you want to retrieve. The following characters cannot be used : | = [ ] , ; |
Code Samples Javascript, C#
GetTeamLeaderboard with JavaScript
This is a minimal example of calling the GetTeamLeaderboard API via HTML and Javascript. Remember to never use your Secret Keys on the client side.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script>
<style type='text/css'>
body {
font-family: "Arial";
}
.rctable{
padding-top:20px;
padding-bottom:10px;
border-bottom:solid 1px #ccc;
width:600px;
}
.rclabel {
font-size:14px;
font-weight:bold;
}
.rcval{
font-size:14px;
padding-left:10px;
}
</style>
<script type="text/javascript">
var connecterURL = "https://www.redcritterconnecter.com/";
function getTeamLeaderboard(secretKey, externalAccountID, leaderboardName, cbSuccess, cbFail) {
$.getJSON(connecterURL + "services/gamificationv1/getTeamLeaderboard?jsoncallback=?", { secretKey: secretKey, externalAccountID: externalAccountID, leaderboardName: leaderboardName },
function (data) {
if (data.Result) {
cbSuccess(data);
} else {
cbFail(data);
}
});
}
//My Success Callback
function onMygetTeamLeaderboardSuccessHandler(data) {
//data is JSON response
renderItems(data)
}
//My Failure Callback
function onMygetTeamLeaderboardFailHandler(data) {
//Something went wrong
alert("Something went wrong");
}
//Sample function to generate the list output in html
function renderItems(data) {
var h = "";
if (data.Teams.length == 0) {
// no rewards
h = "Sorry, there are no Teams on the Leaderboard..";
} else {
//render each Team
for (var i = 0; i < data.Teams.length; i++) {
h = h+ generateItemHTML(data.Teams[i]);
}
}
//display the results
$("#results").html(h);
}
function generateItemHTML(item) {
var h = "<table class='rctable'>";
h += "<tr><td class='rclabel'>TeamID : </td><td class='rcval'>" + HTMLEncode(item.TeamID) + "</td></tr>"
h += "<tr><td class='rclabel'>Team Name : </td><td class='rcval'>" + HTMLEncode(item.TeamName) + "</td></tr>"
h += "<tr><td class='rclabel'>Points : </td><td class='rcval'>" + HTMLEncode(item.Points) + "</td></tr>"
h += "<tr><td class='rclabel'>Rank : </td><td class='rcval'>" + HTMLEncode(item.Rank) + "</td></tr>"
h += "</table>";
return h
}
function HTMLEncode(str) {
var div = document.createElement('div');
var text = document.createTextNode(str);
div.appendChild(text);
return div.innerHTML;
}
</script>
</head>
<body>
<table>
<tr>
<td>Secret Key</td>
<td>
<input type="text" id="tSecretKey" style="width: 500px" />
</td>
</tr>
<tr>
<td>Leaderboard Name</td>
<td>
<input type="text" id="tLeaderboardName" style="width: 500px" />
</td>
</tr>
<tr>
<td>External Account ID</td>
<td>
<input type="text" id="tExternalAccountID" style="width: 500px" />
</td>
</tr>
<tr>
<td></td>
<td>
<input type="button" onclick="getTeamLeaderboard($('#tSecretKey').val(),$('#tExternalAccountID').val(), $('#tLeaderboardName').val(), onMygetTeamLeaderboardSuccessHandler, onMygetTeamLeaderboardFailHandler)" value="Get Team Leaderboard" /></td>
</tr>
</table>
<br />
<div id="results"></div>
</body>
</html>
GetTeamLeaderboard with C#
This is a minmal example of calling the GetTeamLeaderboard API and parsing the JSON result into a populated C# object. This example uses asynchronous techniques to raise a callback when the response is received.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Web; //Add reference to System.Web
using System.Runtime.Serialization.Json; //Add reference to System.Runtime.Serialization
namespace RedCritterConnecter.Samples
{
//Create a class to contain the response
public class GetTeamLeaderboardResponse
{
public Int64 UserID { get; set; }
public String TeamID { get; set; }
public String ProfileEntity { get; set; }
public Int64 AppID { get; set; }
public Int64 AppDomainID { get; set; }
public Boolean Result { get; set; }
private Int32 ErrorCode { get; set; }
public Int32 RewardPoints { get; set; }
public String APIVersion { get; set; }
public String ErrorMessage { get; set; }
public Int32 AuthErrorCode { get; set; }
public List<LeaderboardTeam> Teams { get; set; }
}
public class LeaderboardTeam
{
public String TeamID { get; set; }
public String TeamName { get; set; }
public Int32 Rank { get; set; }
public Double Points { get; set; }
public Boolean OnBoard { get; set; }
}
public class GetTeamLeaderboard
{
public delegate void OnGetTeamLeaderboardResponse(GetTeamLeaderboardResponse GetTeamLeaderboardResponse);
public event OnGetTeamLeaderboardResponse onGetTeamLeaderboardResponse;
public delegate void OnGetTeamLeaderboardResponseError(GetTeamLeaderboardResponse GetTeamLeaderboardResponse);
public event OnGetTeamLeaderboardResponseError onGetTeamLeaderboardResponseError;
const string CONST_ConnecterBaseURL = "https://www.redcritterconnecter.com/";
public void Execute(String SecretKey, String ExternalAccountID, String Leaderboard)
{
try
{
//Create url encoded parameters in query string
String queryString = "secretkey=" + System.Web.HttpUtility.UrlEncode(SecretKey) + "&externalaccountID=" + System.Web.HttpUtility.UrlEncode(ExternalAccountID) + "&leaderboardname=" + System.Web.HttpUtility.UrlEncode(Leaderboard);
//Create a new instance of a WebClient
WebClient wc = new System.Net.WebClient();
//Prevent this request from caching in order to ensure that it is sent to server
wc.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
//Attach an event handler to receive the response
wc.DownloadStringCompleted += onGetTeamLeaderboardResponseReceived;
//Make the call
wc.DownloadStringAsync(new Uri(CONST_ConnecterBaseURL + "services/gamificationv1/GetTeamLeaderboard?" + queryString, UriKind.Absolute));
}
catch
{
//Something went wrong communicating with the server
if (onGetTeamLeaderboardResponseError != null)
{
onGetTeamLeaderboardResponseError(null);
}
}
}
private void onGetTeamLeaderboardResponseReceived(object sender, DownloadStringCompletedEventArgs e)
{
try
{
//Create a JSON serializer
System.Runtime.Serialization.Json.DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(GetTeamLeaderboardResponse));
//Copy the string into a memory stream
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(e.Result));
//Read the stream into an object matching the response's type
GetTeamLeaderboardResponse GetTeamLeaderboardResponse = (GetTeamLeaderboardResponse)s.ReadObject(ms);
//Work with the populated response object
if (GetTeamLeaderboardResponse.Result == true)
{
//Request was accepted, raise the success event
onGetTeamLeaderboardResponse(GetTeamLeaderboardResponse);
}
else
{
//Something went wrong
if (onGetTeamLeaderboardResponseError != null)
{
//Request failed, raise the error event
onGetTeamLeaderboardResponseError(GetTeamLeaderboardResponse);
}
}
}
catch
{
//Something went wrong
onGetTeamLeaderboardResponseError(null);
}
}
}
}
Responses JSON, XML
JSON Result
{
"LeaderboardName": "Test",
"LeaderboardID": 17,
"AppID": 40,
"AppName": "Office Heroes",
"AppIconURL": "http://connecterstoredev.blob.core.windows.net/apps/appicon_40_{s|m|l}.png",
"AppDomainID": 59,
"ExternalAccountID": "(Default)",
"LeaderboardReadKey": "LBT-40-59-17-635115082809900000-635126881090270000",
"LeaderboardDescription": "Test Leaderboard",
"Users": [],
"Teams": [
{
"TeamID": "8/21/2013 6:15:38 PM",
"TeamName": "TestTeam",
"Rank": 1,
"Points": 1.0,
"OnBoard": true
}
],
"Result": true,
"ErrorMessage": "",
"ErrorCode": 0,
"APIVersion": "1.0.0",
"AuthErrorCode": 0
}
XML Response
<Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="Connecter">
<APIVersion>1.0.0</APIVersion>
<AuthErrorCode>0</AuthErrorCode>
<ErrorMessage />
<AppDomainID>59</AppDomainID>
<AppID>40</AppID>
<AppIconURL>
http://connecterstoredev.blob.core.windows.net/apps/appicon_40_{s|m|l}.png
</AppIconURL>
<AppName>Office Heroes</AppName>
<ErrorCode>0</ErrorCode>
<ExternalAccountID>(Default)</ExternalAccountID>
<LeaderboardDescription>Test Leaderboard</LeaderboardDescription>
<LeaderboardID>17</LeaderboardID>
<LeaderboardName>Test</LeaderboardName>
<LeaderboardReadKey>LBT-40-59-17-635115082809900000-635126881090270000</LeaderboardReadKey>
<Result>true</Result>
<Teams>
<Team>
<OnBoard>true</OnBoard>
<Points>1</Points>
<Rank>1</Rank>
<TeamID>8/21/2013 6:15:38 PM</TeamID>
<TeamName>TestTeam</TeamName>
</Team>
</Teams>
<Users />
</Response>
|
Use |
Runtime |
Method |
HTTP GET |
Invites User |
No |
Billable |
No |
Response |
JSON,XML |
API Version |
1 |
|