Retrieves a RedCritter user leaderboard.
This version of the GetUserLeaderboard retrieves the user leaderboard based on the name of the leaderboard.
https://redcritterconnecter.com/services/gamificationv1/GetUserLeaderboard?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 name of the RedCritter user leaderboard that you want to retrieve. The following characters cannot be used : | = [ ] , ; |
Code Samples Javascript, C#
GetUserLeaderboard with JavaScript
This is a minimal example of calling the GetUserLeaderboard 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 getUserLeaderboard(secretKey, leaderboardName, cbSuccess, cbFail) {
$.getJSON(connecterURL + "services/gamificationv1/getUserLeaderboard?jsoncallback=?", { secretKey: secretKey, leaderboardName: leaderboardName },
function (data) {
if (data.Result) {
cbSuccess(data);
} else {
cbFail(data);
}
});
}
//My Success Callback
function onMygetUserLeaderboardSuccessHandler(data) {
//data is JSON response
renderItems(data)
}
//My Failure Callback
function onMygetUserLeaderboardFailHandler(data) {
//Something went wrong
alert("Something went wrong");
}
//Sample function to generate the rewardslist output in html
function renderItems(data) {
var h = "";
if (data.Users.length == 0) {
// no rewards
h = "Sorry, there are no users on the Leaderboard..";
} else {
//render each user
for (var i = 0; i < data.Users.length; i++) {
h = h+ generateItemHTML(data.Users[i]);
}
}
//display the results
$("#results").html(h);
}
function generateItemHTML(item) {
var h = "<table class='rctable'>";
h += "<tr><td class='rclabel'>First Name : </td><td class='rcval'>" + HTMLEncode(item.FirstName) + "</td></tr>"
h += "<tr><td class='rclabel'>Last Name : </td><td class='rcval'>" + HTMLEncode(item.LastName) + "</td></tr>"
h += "<tr><td class='rclabel'>Email : </td><td class='rcval'>" + HTMLEncode(item.Email) + "</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="getUserLeaderboard($('#tSecretKey').val(), $('#tLeaderboardName').val(), onMygetUserLeaderboardSuccessHandler, onMygetUserLeaderboardFailHandler)" value="Get User Leaderboard" /></td>
</tr>
</table>
<br />
<div id="results"></div>
</body>
</html>
GetUserLeaderboard with C#
This is a minmal example of calling the GetUserLEaderboard 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 GetUserLeaderboardResponse
{
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<LeaderboardUser> Users { get; set; }
}
public class LeaderboardUser
{
public String Email { get; set; }
public String Username { get; set; }
public Int64 UserID { get; set; }
public String FirstName { get; set; }
public String LastName { get; set; }
public String IconURL { get; set; }
public Int32 Rank { get; set; }
public Double Points { get; set; }
public Boolean OnBoard { get; set; }
}
public class GetUserLeaderboard
{
public delegate void OnGetUserLeaderboardResponse(GetUserLeaderboardResponse GetUserLeaderboardResponse);
public event OnGetUserLeaderboardResponse onGetUserLeaderboardResponse;
public delegate void OnGetUserLeaderboardResponseError(GetUserLeaderboardResponse GetUserLeaderboardResponse);
public event OnGetUserLeaderboardResponseError onGetUserLeaderboardResponseError;
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 += onGetUserLeaderboardResponseReceived;
//Make the call
wc.DownloadStringAsync(new Uri(CONST_ConnecterBaseURL + "services/gamificationv1/GetUserLeaderboard?" + queryString, UriKind.Absolute));
}
catch
{
//Something went wrong communicating with the server
if (onGetUserLeaderboardResponseError != null)
{
onGetUserLeaderboardResponseError(null);
}
}
}
private void onGetUserLeaderboardResponseReceived(object sender, DownloadStringCompletedEventArgs e)
{
try
{
//Create a JSON serializer
System.Runtime.Serialization.Json.DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(GetUserLeaderboardResponse));
//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
GetUserLeaderboardResponse GetUserLeaderboardResponse = (GetUserLeaderboardResponse)s.ReadObject(ms);
//Work with the populated response object
if (GetUserLeaderboardResponse.Result == true)
{
//Request was accepted, raise the success event
onGetUserLeaderboardResponse(GetUserLeaderboardResponse);
}
else
{
//Something went wrong
if (onGetUserLeaderboardResponseError != null)
{
//Request failed, raise the error event
onGetUserLeaderboardResponseError(GetUserLeaderboardResponse);
}
}
}
catch
{
//Something went wrong
onGetUserLeaderboardResponseError(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": "LBU-40-59-17-635115082809900000-635126881090270000",
"LeaderboardDescription": "Test Leaderboard",
"Users": [
{
"Email": "Dave@redcritter.com",
"Username": "Dave",
"UserID": 135,
"FirstName": "Dave",
"LastName": "Jenness",
"IconURL": "http://connecterstoredev.blob.core.windows.net/users/usericon_135_{s|m|l}.png",
"Rank": 1,
"Points": 7.0,
"OnBoard": true
},
{
"Email": "Mike@redcritter.com",
"Username": "Mike",
"UserID": 107,
"FirstName": "Mike",
"LastName": "Beaty",
"IconURL": "http://connecterstoredev.blob.core.windows.net/users/usericon_107_{s|m|l}.png",
"Rank": 2,
"Points": 1.0,
"OnBoard": true
}
],
"Teams": [],
"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>LBU-40-59-17-635115082809900000-635126881090270000</LeaderboardReadKey>
<Result>true</Result>
<Teams />
<Users>
<User>
<Email>Dave@redcritter.com</Email>
<FirstName>Dave</FirstName>
<IconURL>
http://connecterstoredev.blob.core.windows.net/users/usericon_135_{s|m|l}.png
</IconURL>
<LastName>Jenness</LastName>
<OnBoard>true</OnBoard>
<Points>7</Points>
<Rank>1</Rank>
<UserID>135</UserID>
<Username>Dave</Username>
</User>
<User>
<Email>Mike@redcritter.com</Email>
<FirstName>Mike</FirstName>
<IconURL>
http://connecterstoredev.blob.core.windows.net/users/usericon_107_{s|m|l}.png
</IconURL>
<LastName>Beaty</LastName>
<OnBoard>true</OnBoard>
<Points>1</Points>
<Rank>2</Rank>
<UserID>107</UserID>
<Username>Mike</Username>
</User>
</Users>
</Response>
This version of the GetUserLeaderboard retrieves the user leaderboard based on the App Domain and name of the leaderboard.
https://redcritterconnecter.com/services/gamificationv1/GetUserLeaderboard?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 name of the RedCritter user leaderboard that you want to retrieve. The following characters cannot be used : | = [ ] , ; |
Code Samples Javascript, C#
GetUserLeaderboard with JavaScript
This is a minimal example of calling the GetUserLeaderboard 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 getUserLeaderboard(secretKey, externalAccountID, leaderboardName, cbSuccess, cbFail) {
$.getJSON(connecterURL + "services/gamificationv1/getUserLeaderboard?jsoncallback=?", { secretKey: secretKey, externalAccountID:externalAccountID, leaderboardName: leaderboardName },
function (data) {
if (data.Result) {
cbSuccess(data);
} else {
cbFail(data);
}
});
}
//My Success Callback
function onMygetUserLeaderboardSuccessHandler(data) {
//data is JSON response
renderItems(data)
}
//My Failure Callback
function onMygetUserLeaderboardFailHandler(data) {
//Something went wrong
alert("Something went wrong");
}
//Sample function to generate the rewardslist output in html
function renderItems(data) {
var h = "";
if (data.Users.length == 0) {
// no rewards
h = "Sorry, there are no users on the Leaderboard..";
} else {
//render each user
for (var i = 0; i < data.Users.length; i++) {
h = h+ generateItemHTML(data.Users[i]);
}
}
//display the results
$("#results").html(h);
}
function generateItemHTML(item) {
var h = "<table class='rctable'>";
h += "<tr><td class='rclabel'>First Name : </td><td class='rcval'>" + HTMLEncode(item.FirstName) + "</td></tr>"
h += "<tr><td class='rclabel'>Last Name : </td><td class='rcval'>" + HTMLEncode(item.LastName) + "</td></tr>"
h += "<tr><td class='rclabel'>Email : </td><td class='rcval'>" + HTMLEncode(item.Email) + "</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>External Account ID</td>
<td>
<input type="text" id="tExternalAccountID" 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="getUserLeaderboard($('#tSecretKey').val(), $('#tExternalAccountID').val(), $('#tLeaderboardName').val(), onMygetUserLeaderboardSuccessHandler, onMygetUserLeaderboardFailHandler)" value="Get User Leaderboard" /></td>
</tr>
</table>
<br />
<div id="results"></div>
</body>
</html>
GetUserLeaderboard with C#
This is a minmal example of calling the GetUserLeaderboard 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 GetUserLeaderboardResponse
{
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<LeaderboardUser> Users { get; set; }
}
public class LeaderboardUser
{
public String Email { get; set; }
public String Username { get; set; }
public Int64 UserID { get; set; }
public String FirstName { get; set; }
public String LastName { get; set; }
public String IconURL { get; set; }
public Int32 Rank { get; set; }
public Double Points { get; set; }
public Boolean OnBoard { get; set; }
}
public class GetUserLeaderboard
{
public delegate void OnGetUserLeaderboardResponse(GetUserLeaderboardResponse GetUserLeaderboardResponse);
public event OnGetUserLeaderboardResponse onGetUserLeaderboardResponse;
public delegate void OnGetUserLeaderboardResponseError(GetUserLeaderboardResponse GetUserLeaderboardResponse);
public event OnGetUserLeaderboardResponseError onGetUserLeaderboardResponseError;
const string CONST_ConnecterBaseURL = "https://www.redcritterconnecter.com/";
public void Execute(String SecretKey, String Leaderboard, String ExternalAccountID)
{
try
{
//Create url encoded parameters in query string
String queryString = "secretkey=" + System.Web.HttpUtility.UrlEncode(SecretKey) + "&leaderboardname=" + System.Web.HttpUtility.UrlEncode(Leaderboard) + "&externalaccountide=" + System.Web.HttpUtility.UrlEncode(ExternalAccountID);
//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 += onGetUserLeaderboardResponseReceived;
//Make the call
wc.DownloadStringAsync(new Uri(CONST_ConnecterBaseURL + "services/gamificationv1/GetUserLeaderboard?" + queryString, UriKind.Absolute));
}
catch
{
//Something went wrong communicating with the server
if (onGetUserLeaderboardResponseError != null)
{
onGetUserLeaderboardResponseError(null);
}
}
}
private void onGetUserLeaderboardResponseReceived(object sender, DownloadStringCompletedEventArgs e)
{
try
{
//Create a JSON serializer
System.Runtime.Serialization.Json.DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(GetUserLeaderboardResponse));
//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
GetUserLeaderboardResponse GetUserLeaderboardResponse = (GetUserLeaderboardResponse)s.ReadObject(ms);
//Work with the populated response object
if (GetUserLeaderboardResponse.Result == true)
{
//Request was accepted, raise the success event
onGetUserLeaderboardResponse(GetUserLeaderboardResponse);
}
else
{
//Something went wrong
if (onGetUserLeaderboardResponseError != null)
{
//Request failed, raise the error event
onGetUserLeaderboardResponseError(GetUserLeaderboardResponse);
}
}
}
catch
{
//Something went wrong
onGetUserLeaderboardResponseError(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": 63,
"ExternalAccountID": "TestGroup",
"LeaderboardReadKey": "LBU-40-63-17-635121771621130000-635126881090270000",
"LeaderboardDescription": "Test Leaderboard",
"Users": [
{
"Email": "Dave@redcritter.com",
"Username": "Dave",
"UserID": 135,
"FirstName": "Dave",
"LastName": "Jenness",
"IconURL": "http://connecterstoredev.blob.core.windows.net/users/usericon_135_{s|m|l}.png",
"Rank": 1,
"Points": 3.0,
"OnBoard": true
},
{
"Email": "mike@redcritter.com",
"Username": "Mike",
"UserID": 107,
"FirstName": "Mike",
"LastName": "Beaty",
"IconURL": "http://connecterstoredev.blob.core.windows.net/users/usericon_107_{s|m|l}.png",
"Rank": 2,
"Points": 1.0,
"OnBoard": true
}
],
"Teams": [],
"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>63</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>TestGroup</ExternalAccountID>
<LeaderboardDescription>Test Leaderboard</LeaderboardDescription>
<LeaderboardID>17</LeaderboardID>
<LeaderboardName>Test</LeaderboardName>
<LeaderboardReadKey>LBU-40-63-17-635121771621130000-635126881090270000</LeaderboardReadKey>
<Result>true</Result>
<Teams />
<Users>
<User>
<Email>Dave@redcritter.com</Email>
<FirstName>Dave</FirstName>
<IconURL>
http://connecterstoredev.blob.core.windows.net/users/usericon_135_{s|m|l}.png
</IconURL>
<LastName>Jenness</LastName>
<OnBoard>true</OnBoard>
<Points>3</Points>
<Rank>1</Rank>
<UserID>135</UserID>
<Username>Dave</Username>
</User>
<User>
<Email>mike@redcritter.com</Email>
<FirstName>Mike</FirstName>
<IconURL>
http://connecterstoredev.blob.core.windows.net/users/usericon_107_{s|m|l}.png
</IconURL>
<LastName>Beaty</LastName>
<OnBoard>true</OnBoard>
<Points>1</Points>
<Rank>2</Rank>
<UserID>107</UserID>
<Username>Mike</Username>
</User>
</Users>
</Response>
|
Use |
Runtime |
Method |
HTTP GET |
Invites User |
No |
Billable |
No |
Response |
JSON,XML |
API Version |
1 |
|