Пример #1
0
        /// <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 SendMessageRequest(SendMessageRequestDesc desc, string connectAccessToken, string serverUrl)
        {
            ReleaseAssert.IsNotNull(desc, "A description object cannot be null.");

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

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

            To    = desc.To;
            From  = desc.From;
            Title = desc.Title;
            Text  = desc.Text;
            Data  = desc.Data;
            if (desc.Tags != null)
            {
                Tags = Mutability.ToImmutable(desc.Tags);
            }
            Expiry             = desc.Expiry;
            Gifts              = desc.Gifts;
            Transfer           = desc.Transfer;
            ConnectAccessToken = connectAccessToken;

            Url = serverUrl + "/1.0/message/send";
            HttpRequestMethod = HttpRequestMethod.Post;
        }
Пример #2
0
        /// <summary>
        /// Sends a message to a player. This call allows the From parameter to be set -
        /// enabling sending from any Player, or not set - enabling sending a system message.
        /// To send a message from the currently logged-in Player see SendMessageFromPlayer.
        /// A message can generate, or transfer from the sender, Currency and Inventory
        /// items. Direct access to this method from the SDKs is disabled by default and must
        /// be enabled from the ChilliConnect dashboard. Note: At least one of; Title, Text,
        /// Data, or Rewards is required.
        /// </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 SendMessage(SendMessageRequestDesc desc, Action <SendMessageRequest, SendMessageResponse> successCallback, Action <SendMessageRequest, SendMessageError> errorCallback)
        {
            m_logging.LogVerboseMessage("Sending Send Message request.");

            var connectAccessToken = m_dataStore.GetString("UserAccessToken");
            var request            = new SendMessageRequest(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)
                {
                    NotifySendMessageSuccess(serverResponse, request, successCallback);
                }
                else
                {
                    NotifySendMessageError(serverResponse, request, errorCallback);
                }
            });
        }