示例#1
0
        public static async Task <IActionResult> RegisterPushNotifications(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "/api/player/{playerId}/push")] HttpRequest req,
            string playerId,
            ILogger log)
        {
            if (!Validation.TryValidateGuid(playerId, out Guid playerGuidId))
            {
                log.LogError($"Player ID ({playerId}) was not a valid GUID.");
                return(new BadRequestObjectResult("Invalid Player ID."));
            }

            PushRegistrationRequest pushRegistration = JsonConvert.DeserializeObject <PushRegistrationRequest>(await req.ReadAsStringAsync());

            bool success = await PushNotifications.Register(playerGuidId,
                                                            pushRegistration.PushPlatform,
                                                            pushRegistration.PnsToken,
                                                            pushRegistration.PlatformPushTemplate,
                                                            log);

            if (!success)
            {
                return(new BadRequestResult());
            }

            return(new CreatedResult("", ""));
        }
示例#2
0
 /// <summary>
 /// Begin a new PushRegistrationRequest
 /// </summary>
 /// <param name="requestData"></param>
 /// <returns></returns>
 public PushRegistrationResponse PushRegistrationRequest(PushRegistrationRequest requestData)
 {
     return(JsonConvert.DeserializeObject <PushRegistrationResponse>(Requestor.PostString(Urls.PushRegistrationRequest, JsonHelper.SerializeData(requestData)).ResponseJson));
 }
示例#3
0
        public async Task <MaybeResult <bool, GenericErrorResult> > RegisterPushNotifications(Guid id, PushRegistrationRequest pushRegistration)
        {
            var response = await PostAsJsonAsync($"player/{id.ToString("N")}/push?{GetFunctionCode()}", pushRegistration);

            if (!response.IsSuccessStatusCode)
            {
                Debug.WriteLine($"Failed to register push notifications.");
                return(NetworkMaybeResult.Failure <bool>(response.StatusCode.ToErrorCode()));
            }

            return(NetworkMaybeResult.Success(true));
        }
示例#4
0
        /// <summary>
        /// Begin a new asynchronous PushRegistrationRequest
        /// </summary>
        /// <param name="requestData"></param>
        /// <returns></returns>
        public async Task <PushRegistrationResponse> GPushRegistrationRequestAsync(PushRegistrationRequest requestData)
        {
            var res = await Requestor.PostStringAsync(Urls.PushRegistrationRequest, JsonHelper.SerializeData(requestData));

            return(JsonConvert.DeserializeObject <PushRegistrationResponse>(res.ResponseJson));
        }