Example #1
0
        public async Task <PushResponse> SendPushAsync(PushoverMessage message)
        {
            try
            {
                var limit     = 0;
                var remaining = 0;
                var reset     = "";
                message.AppKey = _appKey;

                var asyncResponse = await BASE_MESSAGE_API_URL.PostToUrlAsync(message.ToArgs(), responseFilter : httpRes =>
                {
                    int.TryParse(httpRes.Headers["X-Limit-App-Limit"], out limit);
                    int.TryParse(httpRes.Headers["X-Limit-App-Remaining"], out remaining);
                    reset = httpRes.Headers["X-Limit-App-Reset"] ?? "";
                });

                var response = asyncResponse.FromJson <PushResponse>();
                response.Limits = new Limitations
                {
                    Limit     = limit,
                    Remaining = remaining,
                    Reset     = reset,
                };
                return(response);
            }
            catch (WebException webEx)
            {
                return(webEx.GetResponseBody().FromJson <PushResponse>());
            }
        }
Example #2
0
        public PushResponse SendPush(PushoverMessage message)
        {
            try
            {
                var limit     = 0;
                var remaining = 0;
                var reset     = "";
                message.AppKey = _appKey;
                if (message.Recipients.Count < 1 && _defaultUserGroupSendKey != null)
                {
                    message.Recipients.Add(_defaultUserGroupSendKey);
                }

                var messageArgs = message.ToArgs();
                var response    = BASE_MESSAGE_API_URL.PostToUrl(messageArgs, responseFilter: httpRes =>
                {
                    int.TryParse(httpRes.Headers["X-Limit-App-Limit"], out limit);
                    int.TryParse(httpRes.Headers["X-Limit-App-Remaining"], out remaining);
                    reset = httpRes.Headers["X-Limit-App-Reset"] ?? "";
                })
                                  .FromJson <PushResponse>();
                response.Limits = new Limitations
                {
                    Limit     = limit,
                    Remaining = remaining,
                    Reset     = reset,
                };
                return(response);
            }
            catch (WebException webEx)
            {
                return(webEx.GetResponseBody().FromJson <PushResponse>());
            }
        }