/// <summary>
        /// Initialises a new instance of the request with the given description.
        /// </summary>
        ///
        /// <param name="desc">The description.</param>
        /// <param name="connectAccessToken">A valid session ConnectAccessToken obtained through one of the login endpoints.</param>
        /// <param name="serverUrl">The server url for this call.</param>
        public RegisterTokenRequest(RegisterTokenRequestDesc desc, string connectAccessToken, string serverUrl)
        {
            ReleaseAssert.IsNotNull(desc, "A description object cannot be null.");

            ReleaseAssert.IsNotNull(desc.Service, "Service cannot be null.");
            ReleaseAssert.IsNotNull(desc.DeviceToken, "DeviceToken cannot be null.");

            ReleaseAssert.IsNotNull(connectAccessToken, "Connect Access Token cannot be null.");

            Service            = desc.Service;
            DeviceToken        = desc.DeviceToken;
            Overwrite          = desc.Overwrite;
            ConnectAccessToken = connectAccessToken;

            Url = serverUrl + "/1.0/push/register";
            HttpRequestMethod = HttpRequestMethod.Post;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers a Device Push Token for the currently logged in ChilliConnect player
        /// for a particular Push Notification Service. On success, returns an empty JSON
        /// object.
        /// </summary>
        ///
        /// <param name="desc">The request description.</param>
        /// <param name="successCallback">The delegate which is called if the request was successful.</param>
        /// <param name="errorCallback">The delegate which is called if the request was unsuccessful. Provides
        /// a container with information on what went wrong.</param>
        public void RegisterToken(RegisterTokenRequestDesc desc, Action <RegisterTokenRequest> successCallback, Action <RegisterTokenRequest, RegisterTokenError> errorCallback)
        {
            m_logging.LogVerboseMessage("Sending Register Token request.");

            var connectAccessToken = m_dataStore.GetString("UserAccessToken");
            var request            = new RegisterTokenRequest(desc, connectAccessToken);

            m_serverRequestSystem.SendImmediateRequest(request, (IImmediateServerRequest sentRequest, ServerResponse serverResponse) =>
            {
                ReleaseAssert.IsTrue(request == sentRequest, "Received request is not the same as the one sent!");

                if (serverResponse.Result == HttpResult.Success && serverResponse.HttpResponseCode == SuccessHttpResponseCode)
                {
                    NotifyRegisterTokenSuccess(serverResponse, request, successCallback);
                }
                else
                {
                    NotifyRegisterTokenError(serverResponse, request, errorCallback);
                }
            });
        }