C# examples
API calls examples
Receive all the available releases
//Receive all the releases available in the panel for a game
//gameId: Game id in IDCGames admin panel, provided by IDCGames
//gameSecret: Game keyword in IDCGames admin panel, provided by IDCGames
private void listExistingReleases(string gameId, string gameSecret)
{
WebClient wc = new WebClient();
wc.Headers.Add("GameID", gameId);
wc.Headers.Add("GameSecret", gameSecret);
try
{
string releasesJsonString = wc.DownloadString("https://admin.idcgames.com/api/release");
parseReleasesJson(releasesJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
{
response = r.ReadToEnd();
}
}
if (response != "")
{
MessageBox.Show("Error downloading game releases from IDC Games panel" + Environment.NewLine + response);
}
else
{
MessageBox.Show("Error downloading game releases from IDC Games panel" + Environment.NewLine + wex.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error downloading game releases from IDC Games panel");
}
}
Receive current release data
//Receive current active release data for a game
//gameId: Game id in IDCGames admin panel, provided by IDCGames
//gameSecret: Game keyword in IDCGames admin panel, provided by IDCGames
private void getActiveRelease(string gameId, string gameSecret)
{
WebClient wc = new WebClient();
wc.Headers.Add("GameID", gameId);
wc.Headers.Add("GameSecret", gameSecret);
try
{
string releasesJsonString = wc.DownloadString("https://admin.idcgames.com/api/release/active");
parseReleasesJson(releasesJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
{
response = r.ReadToEnd();
}
}
if (response != "")
{
MessageBox.Show("Error downloading active release from IDC Games panel" + Environment.NewLine + response);
}
else
{
MessageBox.Show("Error downloading active release from IDC Games panel" + Environment.NewLine + wex.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error downloading active release from IDC Games panel");
}
}
Create a copy of a release
//Create a new release (a copy of the last release)
//gameId: Game id in IDCGames admin panel, provided by IDCGames
//gameSecret: Game keyword in IDCGames admin panel, provided by IDCGames
//releaseName: Release Name or version
private void createRelease(string gameId, string gameSecret, string releaseName)
{
WebClient wc = new WebClient();
wc.Headers.Add("GameID", gameId);
wc.Headers.Add("GameSecret", gameSecret);
//Required in order to post parameters
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
releaseName = System.Web.HttpUtility.UrlPathEncode(releaseName);
string parameters = $"rel_name={releaseName}";
try
{
string releasesJsonString = wc.UploadString("https://admin.idcgames.com/api/release", parameters);
parseCreateOrModifyReleaseJson(releasesJsonString);
}
catch (WebException wex) {
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
{
response = r.ReadToEnd();
}
}
if (response != "")
{
MessageBox.Show("Error creating game release in IDC Games panel" + Environment.NewLine + response);
}
else
{
MessageBox.Show("Error creating game releases¡ in IDC Games panel" + Environment.NewLine + wex.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error creating game releases¡ in IDC Games panel" + Environment.NewLine + ex.ToString());
}
}
Modify an existing release
//Modify an existing release
//gameId: Game id in IDCGames admin panel, provided by IDCGames
//gameSecret: Game keyword in IDCGames admin panel, provided by IDCGames
//releaseID: Release id (received in createRelease, getActiveRelease or listExistingReleases)
//releaseName: Release Name or version
private void modifyRelease(string gameId, string gameSecret, int releaseId, string releaseName)
{
WebClient wc = new WebClient();
wc.Headers.Add("GameID", gameId);
wc.Headers.Add("GameSecret", gameSecret);
//Required in order to post parameters
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
releaseName = System.Web.HttpUtility.UrlPathEncode(releaseName);
string parameters = $"rel_name={releaseName}";
try
{
string modifyReleaseApiUrl = $"https://admin.idcgames.com/api/release/update/{releaseId}";
string releasesJsonString = wc.UploadString(modifyReleaseApiUrl, parameters);
parseCreateOrModifyReleaseJson(releasesJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
{
response = r.ReadToEnd();
}
}
if (response != "")
{
MessageBox.Show("Error creating game release in IDC Games panel" + Environment.NewLine + response);
}
else
{
MessageBox.Show("Error creating game releases¡ in IDC Games panel" + Environment.NewLine + wex.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error creating game releases¡ in IDC Games panel" + Environment.NewLine + ex.ToString());
}
}
Upload release files into an fp account
//Create a ftp account to upload release files. Once the accounts are created, ftp data can be received calling getReleaseFtpAccounts
//gameId: Game id in IDCGames admin panel, provided by IDCGames
//gameSecret: Game keyword in IDCGames admin panel, provided by IDCGames
//releaseID: Release id (received in createRelease, getActiveRelease or listExistingReleases)
//ftpType: 0 for release
// 1 for DLC
//ftpFolderType: redist for redistribuible files
// common for files with the same format in x86 and x6 systems
// uncommon for files for x86 systems, wich should be included in x86 folder and files for x64 systems, wich should be included in x64 folder
//sourcePublicIp: public source ip for uploading files with ftp. Leave blank if api is called from the same ip as ftp upload
//hours: ftp account lifetime in hours
void createReleaseFtpAccount(string gameId, string gameSecret, int releaseID, int ftpType, string ftpFolderType, string sourcePublicIp, int hours)
{
WebClient wc = new WebClient();
wc.Headers.Add("GameID", gameId);
wc.Headers.Add("GameSecret", gameSecret);
//Required in order to post parameters
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string ipParam = "";
if (sourcePublicIp != "")
{
ipParam = $"&ip={sourcePublicIp}";
}
string parameters = $"rel_dlc={ftpType}&rel_dir={ftpFolderType}&hours={hours}{ipParam}";
try
{
string ftpApiUrl = $"https://admin.idcgames.com/api/release/ftp/{releaseID}";
string createFtpAccountJsonString = wc.UploadString(ftpApiUrl, parameters);
parseCreateFtpAccountJson(createFtpAccountJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
{
response = r.ReadToEnd();
}
}
if (response != "")
{
MessageBox.Show("Error creating ftp account in IDC Games panel" + Environment.NewLine + response);
}
else
{
MessageBox.Show("Error creating ftp account in IDC Games panel" + Environment.NewLine + wex.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error creating ftp account in IDC Games panel" + Environment.NewLine + ex.ToString());
}
}
Publish a relesease
//Pusblish a release and start synchronizing files
//gameId: Game id in IDCGames admin panel, provided by IDCGames
//gameSecret: Game keyword in IDCGames admin panel, provided by IDCGames
//releaseID: Release id (received in createRelease, getActiveRelease or listExistingReleases)
void publishRelease(string gameId, string gameSecret, int releaseID)
{
WebClient wc = new WebClient();
wc.Headers.Add("GameID", gameId);
wc.Headers.Add("GameSecret", gameSecret);
//Required in order to post parameters
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string ipParam = "";
try
{
string publishReleaseApiUrl = $"https://admin.idcgames.com/api/release/publish/{releaseID}";
string publishReleaseJsonString = wc.UploadString(publishReleaseApiUrl, ipParam);
parsePublishReleaseJson(publishReleaseJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
{
response = r.ReadToEnd();
}
}
if (response != "")
{
MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + response);
}
else
{
MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + wex.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + ex.ToString());
}
}
Check synchronization status for a published release
//Check synchronization status for a published release
//gameId: Game id in IDCGames admin panel, provided by IDCGames
//gameSecret: Game keyword in IDCGames admin panel, provided by IDCGames
//releaseID: Release id (received in createRelease, getActiveRelease or listExistingReleases)
void checkSynchronization(string gameId, string gameSecret, int releaseID)
{
WebClient wc = new WebClient();
wc.Headers.Add("GameID", gameId);
wc.Headers.Add("GameSecret", gameSecret);
//Required in order to post parameters
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string ipParam = "";
try
{
string checSynchronizationApiUrl = $"https://admin.idcgames.com/api/release/check_sync/{releaseID}";
string checSynchronizationJsonString = wc.DownloadString(checSynchronizationApiUrl);
parseCheckSynchronizationJson(checSynchronizationJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
{
response = r.ReadToEnd();
}
}
if (response != "")
{
MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + response);
}
else
{
MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + wex.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + ex.ToString());
}
}
Activate a release
//Activate a release
//gameId: Game id in IDCGames admin panel, provided by IDCGames
//gameSecret: Game keyword in IDCGames admin panel, provided by IDCGames
//releaseID: Release id (received in createRelease, getActiveRelease or listExistingReleases)
void activateRelease(string gameId, string gameSecret, int releaseID)
{
WebClient wc = new WebClient();
wc.Headers.Add("GameID", gameId);
wc.Headers.Add("GameSecret", gameSecret);
//Required in order to post parameters
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string ipParam = "";
try
{
string activateReleaseApiUrl = $"https://admin.idcgames.com/api/release/activate/{releaseID}";
string activateReleaseJsonString = wc.UploadString(activateReleaseApiUrl, ipParam);
parseReleaseActivationJson(activateReleaseJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
{
response = r.ReadToEnd();
}
}
if (response != "")
{
MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + response);
}
else
{
MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + wex.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + ex.ToString());
}
}
Deactivate a release
//Deactivate a release
//gameId: Game id in IDCGames admin panel, provided by IDCGames
//gameSecret: Game keyword in IDCGames admin panel, provided by IDCGames
//releaseID: Release id (received in createRelease, getActiveRelease or listExistingReleases)
void deactivateRelease(string gameId, string gameSecret)
{
WebClient wc = new WebClient();
wc.Headers.Add("GameID", gameId);
wc.Headers.Add("GameSecret", gameSecret);
//Required in order to post parameters
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string ipParam = "";
try
{
string deactivateReleaseApiUrl = "https://admin.idcgames.com/api/release/remove_active/";
string deactivateReleaseJsonString = wc.UploadString(deactivateReleaseApiUrl, ipParam);
parseReleaseActivationJson(deactivateReleaseJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
{
response = r.ReadToEnd();
}
}
if (response != "")
{
MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + response);
}
else
{
MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + wex.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + ex.ToString());
}
}
Classes used in parsing code
public class CommonResponseClass {
public string success { get; set; }
public string message { get; set; }
}
public class ReleaseClass
{
public int id { get; set; }
public string name { get; set; }
public string exe { get; set; }
public string size { get; set; }
public string published { get; set; }
public bool active { get; set; }
public string splash { get; set; }
public string ico { get; set; }
public int sync_status { get; set; }
}
public class ReleasesClass {
public List<ReleaseClass> data { get; set; }
}
public class CreateOrModifyReleaseClass {
public ReleaseClass data { get; set; }
}
public class FtpAccountClass
{
public int id { get; set; }
public int user { get; set; }
public int rel { get; set; }
public string rel_dir { get; set; }
public int hours { get; set; }
public string ip { get; set; }
public string requested_at { get; set; }
public string accepted_at { get; set; }
public bool notified { get; set; }
public string ftp_username { get; set; }
public string ftp_password { get; set; }
public string expire_at { get; set; }
public int status { get; set; }
public string rel_dlc { get; set; }
public string created_at { get; set; }
public string updated_at { get; set; }
public class PublishReleaseResponseClass {
public string success { get; set; }
public List<string> errors { get; set; }
public string sync_url { get; set; }
public string json_url { get; set; }
}
public class CheckSynchronizationResponseClass{
public int status { get; set; }
public List<SyncrhonizationProgressClass> progress { get; set; }
}
public class SyncrhonizationProgressClass {
public string file_name { get; set; }
public int file_progress { get; set; }
public string file_speed { get; set; }
public string ip { get; set; }
}
public class ReleaseActivationResponseClass
{
public string success { get; set; }
}
Parse JSON Examples (Using newtonsoft)
private void parseReleasesJson(string releasesJsonString)
{
ReleasesClass releases;
try
{
releases = JsonConvert.DeserializeObject<ReleasesClass>(releasesJsonString);
showReleases(releases);
}
catch (Exception ex)
{
MessageBox.Show($"Invalid releases json data received from IDC Games panel:{Environment.NewLine}{releasesJsonString}");
}
}
private void parseCreateOrModifyReleaseJson(string releasesJsonString)
{
CreateOrModifyReleaseClass release;
try
{
release = JsonConvert.DeserializeObject<CreateOrModifyReleaseClass>(releasesJsonString);
showCreatedOrModifiedRelease(release);
}
catch (Exception ex)
{
MessageBox.Show($"Invalid create release json data received from IDC Games panel:{Environment.NewLine}{releasesJsonString}");
}
}
private void parseGetReleaseFTPAccountsJson(string ftpAccountsJsonString)
{
List<FtpAccountClass> ftpAccountsList;
try
{
ftpAccountsList = JsonConvert.DeserializeObject<List<FtpAccountClass>>(ftpAccountsJsonString);
showFtpAccounts(ftpAccountsList);
}
catch (Exception ex)
{
MessageBox.Show($"Invalid get release ftp accounts json data received from IDC Games panel:{Environment.NewLine}{ftpAccountsJsonString}");
private void parseCreateFtpAccountJson(string createFtpAccountJson)
{
CommonResponseClass createFtpAccountsResponse;
try
{
createFtpAccountsResponse = JsonConvert.DeserializeObject<CommonResponseClass>(createFtpAccountJson);
if (createFtpAccountsResponse.success != "false")
{
MessageBox.Show("FTP account created");
}
else
{
MessageBox.Show("Error creating FTP Account: " + createFtpAccountsResponse.message);
}
}
catch (Exception ex)
{
MessageBox.Show($"Invalid create ftp account json data received from IDC Games panel:{Environment.NewLine}{createFtpAccountJson}");
}
}
private void parsePublishReleaseJson(string publishReleaseJson)
{
PublishReleaseResponseClass publishReleaseResponse;
try
{
publishReleaseResponse = JsonConvert.DeserializeObject<PublishReleaseResponseClass>(publishReleaseJson);
if (publishReleaseResponse.success != "false")
{
//Synchronization status true, add your code here
synchronizationStarted(publishReleaseResponse);
}
else
{
//Convert errors list to comma separated string to show the message with the errors
IList<string> errors = publishReleaseResponse.errors;
MessageBox.Show("Error publishing Release: " + string.Join(",", errors));
}
}
catch (Exception ex)
{
MessageBox.Show($"Invalid publish release json data received from IDC Games panel:{Environment.NewLine}{publishReleaseJson}");
}
}
private void parseCheckSynchronizationJson(string checkSynchronizationJson)
{
CheckSynchronizationResponseClass checkSynchronizationResponse;
try
{
checkSynchronizationResponse = JsonConvert.DeserializeObject<CheckSynchronizationResponseClass>(checkSynchronizationJson);
if (checkSynchronizationResponse.status == 1)
{
synchronizationFinished();
}
else
{
showSynchronizationStatus(checkSynchronizationResponse);
}
}
catch (Exception ex)
{
MessageBox.Show($"Invalid check synchronization json data received from IDC Games panel:{Environment.NewLine}{checkSynchronizationJson}");
}
}
private void parseReleaseActivationJson(string releaseActivationJson)
{
ReleaseActivationResponseClass releaseActivationResponse;
try
{
releaseActivationResponse = JsonConvert.DeserializeObject<ReleaseActivationResponseClass>(releaseActivationJson);
if (releaseActivationResponse.success != "false")
{
//activation/deactivation success true, add your code here
showReleaseActivationResponse(releaseActivationResponse);
}
else
{
MessageBox.Show("Error activating release.");
}
}
catch (Exception ex)
{
MessageBox.Show($"Invalid release activation json data received from IDC Games panel:{Environment.NewLine}{releaseActivationJson}");
}
}
Last updated