UNPKG

poker-server-api

Version:
503 lines 27.9 kB
"use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; /// <reference path="lib/poker.commanding.api.d.ts" /> /* tslint:disable:quotemark */ var authToken = null; var beforeSendHandler = function (xhr) { xhr.withCredentials = true; if (authToken != null) { xhr.setRequestHeader("X-Auth-Token", authToken); } }; (function (TournamentStatus) { TournamentStatus[TournamentStatus["Pending"] = 0] = "Pending"; TournamentStatus[TournamentStatus["RegistrationStarted"] = 1] = "RegistrationStarted"; TournamentStatus[TournamentStatus["RegistrationCancelled"] = 2] = "RegistrationCancelled"; TournamentStatus[TournamentStatus["SettingUp"] = 3] = "SettingUp"; TournamentStatus[TournamentStatus["WaitingTournamentStart"] = 4] = "WaitingTournamentStart"; TournamentStatus[TournamentStatus["Started"] = 5] = "Started"; TournamentStatus[TournamentStatus["Completed"] = 6] = "Completed"; TournamentStatus[TournamentStatus["Cancelled"] = 7] = "Cancelled"; TournamentStatus[TournamentStatus["LateRegistration"] = 8] = "LateRegistration"; })(exports.TournamentStatus || (exports.TournamentStatus = {})); var TournamentStatus = exports.TournamentStatus; /** * Represents player status in the tournament. */ (function (TournamentPlayerStatus) { /** * Player registered to play in the tournament */ TournamentPlayerStatus[TournamentPlayerStatus["Registered"] = 0] = "Registered"; /** * Player cancel his registration. */ TournamentPlayerStatus[TournamentPlayerStatus["RegistrationCancelled"] = 1] = "RegistrationCancelled"; /** * Player is currently playing in the tournament. */ TournamentPlayerStatus[TournamentPlayerStatus["Playing"] = 2] = "Playing"; /** * Player complete playing in the tournament. */ TournamentPlayerStatus[TournamentPlayerStatus["Completed"] = 3] = "Completed"; })(exports.TournamentPlayerStatus || (exports.TournamentPlayerStatus = {})); var TournamentPlayerStatus = exports.TournamentPlayerStatus; (function (TournamentOptionsEnum) { TournamentOptionsEnum[TournamentOptionsEnum["None"] = 0] = "None"; TournamentOptionsEnum[TournamentOptionsEnum["HasBuyIn"] = 1] = "HasBuyIn"; TournamentOptionsEnum[TournamentOptionsEnum["HasEntryFee"] = 2] = "HasEntryFee"; TournamentOptionsEnum[TournamentOptionsEnum["HasRebuy"] = 4] = "HasRebuy"; TournamentOptionsEnum[TournamentOptionsEnum["HasAddon"] = 8] = "HasAddon"; TournamentOptionsEnum[TournamentOptionsEnum["RebuyGoesToPrizePool"] = 16] = "RebuyGoesToPrizePool"; TournamentOptionsEnum[TournamentOptionsEnum["RebuyGoesToCasino"] = 32] = "RebuyGoesToCasino"; TournamentOptionsEnum[TournamentOptionsEnum["AddonGoesToPrizePool"] = 64] = "AddonGoesToPrizePool"; TournamentOptionsEnum[TournamentOptionsEnum["AddonGoesToCasino"] = 128] = "AddonGoesToCasino"; })(exports.TournamentOptionsEnum || (exports.TournamentOptionsEnum = {})); var TournamentOptionsEnum = exports.TournamentOptionsEnum; var OnlinePoker; (function (OnlinePoker) { var Commanding; (function (Commanding) { var API; (function (API) { (function (MoneyType) { MoneyType[MoneyType["Tenge"] = 1] = "Tenge"; MoneyType[MoneyType["GameChips"] = 2] = "GameChips"; })(API.MoneyType || (API.MoneyType = {})); var MoneyType = API.MoneyType; ; API.logging = false; API.version = 1; var WebApiProxy = (function () { function WebApiProxy(host, baseName) { this.host = host; this.baseName = baseName; this.timeout = 5000; this.baseUrl = host + '/' + baseName + '/'; } WebApiProxy.prototype.Call = function (methodName, parameters, successCallback) { var self = this; var parametersString = "null"; if (parameters != null) { parametersString = JSON.stringify(parameters); } this.Log(this.baseName, "Method " + methodName + " called. Parameters: " + parametersString); var url = this.baseUrl + methodName; return $.ajax({ type: 'POST', url: url, data: JSON.stringify(parameters), success: function (data, textStatus, jqXHR) { var dataString = data != null ? JSON.stringify(data) : "NULL"; textStatus = textStatus != null ? textStatus : "NULL"; var logMessage = "Method " + methodName + " finished. Status: " + textStatus + ". Results: " + dataString; self.Log(self.baseName, logMessage); if (successCallback != null) { successCallback(data, textStatus, jqXHR); } }, timeout: this.timeout, crossDomain: true, async: true, contentType: 'application/json', beforeSend: beforeSendHandler, dataType: 'json' }); }; WebApiProxy.prototype.SimpleCall = function (methodName, successCallback) { var data = {}; return this.Call(methodName, data, successCallback); }; WebApiProxy.prototype.Log = function (api, msg) { if (API.logging === false) { return; } if (typeof (window.console) === "undefined") { return; } var m = "[" + new Date().toTimeString() + "] OnlinePoker API(" + this.baseName + "): " + msg; if (window.console.debug) { window.console.debug(m); } else if (window.console.log) { window.console.log(m); } }; return WebApiProxy; }()); API.WebApiProxy = WebApiProxy; var Chat = (function (_super) { __extends(Chat, _super); function Chat(host) { _super.call(this, host, 'Chat'); } Chat.prototype.Send = function (tableId, message, callback) { var data = { tableId: tableId, message: message }; return _super.prototype.Call.call(this, 'Send', data, callback); }; return Chat; }(WebApiProxy)); API.Chat = Chat; var Message = (function (_super) { __extends(Message, _super); function Message(host) { _super.call(this, host, 'Message'); } Message.prototype.Send = function (recepient, subject, body, callback) { var data = { Recipient: recepient, Subject: subject, Body: body }; return _super.prototype.Call.call(this, 'Send', data, callback); }; Message.prototype.GetInboxMessages = function (page, pageSize, filter, sortOrder, callback) { var data = { Page: page, PageSize: pageSize, Filter: filter, SortOrder: sortOrder }; return _super.prototype.Call.call(this, 'GetInboxMessages', data, callback); }; Message.prototype.GetSentMessages = function (page, pageSize, filter, sortOrder, callback) { var data = { Page: page, PageSize: pageSize, Filter: filter, SortOrder: sortOrder }; return _super.prototype.Call.call(this, 'GetSentMessages', data, callback); }; Message.prototype.GetMessage = function (id, callback) { var data = { Id: id }; return _super.prototype.Call.call(this, 'GetMessage', data, callback); }; return Message; }(WebApiProxy)); API.Message = Message; var Game = (function (_super) { __extends(Game, _super); function Game(host) { /// <signature> /// <summary>Wrapper for the Game Commanding API</summary> /// <param name="host">Host with Metadata Commanding API installed</param> /// </signature> _super.call(this, host, 'Game'); } Game.prototype.GetTables = function (fullTables, privateTables, maxPlayers, betLevels, moneyType, limitType, callback) { var data = { FullTables: fullTables, Private: privateTables, MaxPlayers: maxPlayers, BetLevels: betLevels, MoneyType: moneyType, LimitType: limitType }; return _super.prototype.Call.call(this, 'GetTables', data, callback); }; Game.prototype.GetTable = function (tableId, callback) { var data = { TableId: tableId }; return _super.prototype.Call.call(this, 'GetTable', data, callback); }; Game.prototype.GetSitingTables = function (callback) { var data = {}; return _super.prototype.Call.call(this, 'GetSitingTables', data, callback); }; Game.prototype.Sit = function (tableId, seat, amount, callback) { var data = { TableId: tableId, Seat: seat, Amount: amount }; return _super.prototype.Call.call(this, 'Sit', data, callback); }; Game.prototype.SitAnywhere = function (tableId, amount, callback) { var data = { TableId: tableId, Amount: amount }; return _super.prototype.Call.call(this, 'SitAnywhere', data, callback); }; Game.prototype.Standup = function (tableId, callback) { var data = { TableId: tableId }; return _super.prototype.Call.call(this, 'Standup', data, callback); }; Game.prototype.Fold = function (tableId, callback) { var data = { TableId: tableId }; return _super.prototype.Call.call(this, 'Fold', data, callback); }; Game.prototype.CheckOrCall = function (tableId, callback) { var data = { TableId: tableId }; return _super.prototype.Call.call(this, 'CheckOrCall', data, callback); }; Game.prototype.BetOrRaise = function (tableId, amount, callback) { var data = { TableId: tableId, Amount: amount }; return _super.prototype.Call.call(this, 'BetOrRaise', data, callback); }; Game.prototype.ForceJoinGame = function (tableId, callback) { var data = { TableId: tableId }; return _super.prototype.Call.call(this, 'ForceJoin', data, callback); }; Game.prototype.WaitBigBlind = function (tableId, callback) { var data = { TableId: tableId }; return _super.prototype.Call.call(this, 'WaitBigBlind', data, callback); }; Game.prototype.AddBalance = function (tableId, amount, callback) { var data = { TableId: tableId, Amount: amount }; return _super.prototype.Call.call(this, 'AddBalance', data, callback); }; Game.prototype.SitOut = function (tableId, callback) { var data = { TableId: tableId }; return _super.prototype.Call.call(this, 'SitOut', data, callback); }; Game.prototype.ForceSitout = function (tableId, callback) { var data = { TableId: tableId }; return _super.prototype.Call.call(this, 'ForceSitout', data, callback); }; Game.prototype.ComeBack = function (tableId, callback) { var data = { TableId: tableId }; return _super.prototype.Call.call(this, 'ComeBack', data, callback); }; Game.prototype.SetOpenCardsParameters = function (tableId, openCardsAutomatically, callback) { var data = { TableId: tableId, OpenCardsAutomatically: openCardsAutomatically }; return _super.prototype.Call.call(this, 'SetOpenCardsParameters', data, callback); }; return Game; }(WebApiProxy)); API.Game = Game; var Tournament = (function (_super) { __extends(Tournament, _super); function Tournament(host) { /// <signature> /// <summary>Wrapper for the Tournament Commanding API</summary> /// <param name="host">Host with Metadata Commanding API installed</param> /// </signature> _super.call(this, host, 'Tournament'); } Tournament.prototype.GetTournaments = function (prizeCurrency, tournamentType, speed, buyin, maxPlayers, callback) { var data = { TournamentType: tournamentType, PrizeCurrency: prizeCurrency, Speed: speed, BuyIn: buyin, MaxPlayers: maxPlayers }; return _super.prototype.Call.call(this, 'GetTournaments', data, callback); }; Tournament.prototype.GetTournament = function (tournamentId, callback) { var data = { Id: tournamentId }; return _super.prototype.Call.call(this, 'GetTournament', data, callback); }; Tournament.prototype.Register = function (tournamentId, callback) { var data = { Id: tournamentId }; return _super.prototype.Call.call(this, 'Register', data, callback); }; Tournament.prototype.CancelRegistration = function (tournamentId, callback) { var data = { Id: tournamentId }; return _super.prototype.Call.call(this, 'CancelRegistration', data, callback); }; Tournament.prototype.Rebuy = function (tournamentId, double, callback) { var data = { Id: tournamentId, Double: double }; return _super.prototype.Call.call(this, 'Rebuy', data, callback); }; Tournament.prototype.Addon = function (tournamentId, callback) { var data = { Id: tournamentId }; return _super.prototype.Call.call(this, 'Addon', data, callback); }; Tournament.prototype.GetRegisteredTournamentsStatus = function (callback) { var data = {}; // return super.SimpleCall('GetRegisteredTournamentsStatus', callback); return _super.prototype.Call.call(this, 'GetRegisteredTournamentsStatus', data, callback); }; return Tournament; }(WebApiProxy)); API.Tournament = Tournament; var Account = (function (_super) { __extends(Account, _super); function Account(host) { /// <signature> /// <summary>Wrapper for the Metadata Commanding API</summary> /// <param name="host">Host with Metadata Commanding API installed</param> /// </signature> _super.call(this, host, 'Account'); } Account.prototype.ActivateAccount = function (login, token, callback) { var data = { Login: login, Token: token }; return _super.prototype.Call.call(this, 'ActivateAccount', data, callback); }; Account.prototype.Logout = function (callback) { var data = {}; authToken = null; return _super.prototype.Call.call(this, 'Logout', data, callback); }; Account.prototype.Authenticate = function (login, password, rememberMe, callback) { var data = { Login: login, Password: password, RememberMe: rememberMe }; var aquireTokenCallback = function (data, textStatus, xhr) { authToken = xhr.getResponseHeader('X-Auth-Token'); console.log("Aquired auth token", authToken); if (callback != null) { callback(data, textStatus, xhr); } }; return _super.prototype.Call.call(this, 'Authenticate', data, aquireTokenCallback); }; Account.prototype.CancelAccountActivation = function (login, token, callback) { var data = { Login: login, Token: token }; return _super.prototype.Call.call(this, 'CancelAccountActivation', data, callback); }; Account.prototype.ChangePassword = function (oldPassword, newPassword, callback) { var data = { OldPassword: oldPassword, NewPassword: newPassword }; return _super.prototype.Call.call(this, 'ChangePassword', data, callback); }; Account.prototype.GetPersonalAccount = function (callback) { var data = {}; return _super.prototype.Call.call(this, 'GetPersonalAccount', data, callback); }; Account.prototype.GetPlayerAccountHistory = function (fromDate, toDate, fromAmount, toAmount, operationType, callback) { var data = { FromDate: fromDate, ToDate: toDate, FromAmount: fromAmount, ToAmount: toAmount, OperationType: operationType }; return _super.prototype.Call.call(this, 'GetPlayerAccountHistory', data, callback); }; Account.prototype.GetPlayerDefinition = function (callback) { var data = {}; return _super.prototype.Call.call(this, 'GetPlayerDefinition', data, callback); }; Account.prototype.PutWithdrawalRequest = function (type, amount, parameters, callback) { var data = { Type: type, Amount: amount, Parameters: parameters }; return _super.prototype.Call.call(this, 'PutWithdrawalRequest', data, callback); }; Account.prototype.Register = function (login, email, password, firstName, lastName, patronymicName, country, city, additionalProperties, image, callback) { var url = this.baseUrl + 'Register'; var data = { Login: login, Email: email, Password: password, FirstName: firstName, LastName: lastName, PatronymicName: patronymicName, Country: country, City: city, Image: image, AdditionalProperties: additionalProperties }; return $.ajax({ type: 'POST', url: url, data: JSON.stringify(data), success: callback, crossDomain: true, contentType: 'application/json', beforeSend: beforeSendHandler, dataType: 'json' }); }; Account.prototype.RequestResetPassword = function (login, email, callback) { var data = { Login: login, Email: email }; return _super.prototype.Call.call(this, 'RequestResetPassword', data, callback); }; Account.prototype.ResetAvatar = function (callback) { var data = {}; return _super.prototype.Call.call(this, 'ResetAvatar', data, callback); }; Account.prototype.ResetPassword = function (token, newPassword, callback) { var data = { Token: token, Password: newPassword }; return _super.prototype.Call.call(this, 'ResetPassword', data, callback); }; Account.prototype.SetAvatarUrl = function (url, callback) { var data = { Url: url }; return _super.prototype.Call.call(this, 'SetAvatarUrl', data, callback); }; Account.prototype.UpdatePlayerProfile = function (firstName, lastName, patronymicName, email, country, city, image, callback) { throw new Error('Calls with multipart data not supported'); }; Account.prototype.UploadAvatar = function (image, callback) { throw new Error('Calls with multipart data not supported'); }; Account.prototype.GetBestPlayers = function (callback) { var data = {}; return _super.prototype.Call.call(this, 'GetBestPlayers', data, callback); }; Account.prototype.RegisterGuest = function (callback) { var data = {}; return _super.prototype.Call.call(this, 'RegisterGuest', data, callback); }; return Account; }(WebApiProxy)); API.Account = Account; var Metadata = (function (_super) { __extends(Metadata, _super); function Metadata(host) { /// <signature> /// <summary>Wrapper for the Metadata Commanding API</summary> /// <param name="host">Host with Metadata Commanding API installed</param> /// </signature> _super.call(this, host, 'Metadata'); this.timeout = 10000; } Metadata.prototype.GetServerLayout = function (callback) { if (callback === void 0) { callback = null; } var data = {}; return _super.prototype.Call.call(this, 'GetServerLayout', data, callback); }; Metadata.prototype.GetDefaultAvatars = function (callback) { if (callback === void 0) { callback = null; } var data = {}; return _super.prototype.Call.call(this, 'GetDefaultAvatars', data, callback); }; Metadata.prototype.GetWellKnownBetStructure = function (callback) { if (callback === void 0) { callback = null; } var data = {}; return _super.prototype.Call.call(this, 'GetWellKnownBetStructure', data, callback); }; Metadata.prototype.GetWellKnownPrizeStructure = function (callback) { if (callback === void 0) { callback = null; } var data = {}; return _super.prototype.Call.call(this, 'GetWellKnownPrizeStructure', data, callback); }; Metadata.prototype.GetNews = function (callback) { if (callback === void 0) { callback = null; } var data = {}; return _super.prototype.Call.call(this, 'GetNews', data, callback); }; Metadata.prototype.GetOnlinePlayers = function (callback) { if (callback === void 0) { callback = null; } var data = {}; return _super.prototype.Call.call(this, 'GetOnlinePlayers', data, callback); }; Metadata.prototype.GetBanners = function (format, callback) { if (callback === void 0) { callback = null; } var data = { Format: format }; return _super.prototype.Call.call(this, 'GetBanners', data, callback); }; /** * Request server date. * @param callback A callback function that is executed if the request succeeds. */ Metadata.prototype.GetDate = function (callback) { if (callback === void 0) { callback = null; } var data = {}; return _super.prototype.Call.call(this, 'GetDate', data, callback); }; /** * Perform version check. * @param callback A callback function that is executed if the request succeeds. */ Metadata.prototype.VersionCheck = function (callback) { if (callback === void 0) { callback = null; } var data = {}; return _super.prototype.Call.call(this, 'VersionCheck', data, callback); }; return Metadata; }(WebApiProxy)); API.Metadata = Metadata; var Support = (function (_super) { __extends(Support, _super); function Support(host) { _super.call(this, host, 'Support'); } Support.prototype.ContactUs = function (fullName, email, subject, message, callback) { var data = { FullName: fullName, Email: email, Subject: subject, Body: message }; return _super.prototype.Call.call(this, 'ContactUs', data, callback); }; return Support; }(WebApiProxy)); API.Support = Support; })(API = Commanding.API || (Commanding.API = {})); })(Commanding = OnlinePoker.Commanding || (OnlinePoker.Commanding = {})); })(OnlinePoker = exports.OnlinePoker || (exports.OnlinePoker = {})); //# sourceMappingURL=index.js.map