Example #1
0
        public async Task <ICollection <HttpResponseMessage> > SendAsync(PushoverMessage message, params string[] userKeys)
        {
            var builder = ImmutableList.CreateBuilder <KeyValuePair <string, string> >();

            builder.Add(new KeyValuePair <string, string>("token", _appToken));
            builder.AddRange(message.ToKeyValuePairs());
            var immutableParameters = builder.ToImmutableList();

            var responses = new List <HttpResponseMessage>();

            foreach (var userKey in userKeys)
            {
                var parameters = immutableParameters.Add(new KeyValuePair <string, string>("user", userKey));
                var content    = new System.Net.Http.FormUrlEncodedContent(parameters);

                var response = await HttpHandler.PostAsync(RequestUri, content);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    throw new Exception(await response.Content.ReadAsStringAsync());
                }

                responses.Add(response);
            }

            return(responses);
        }
Example #2
0
        public async Task <HttpResponseMessage> SendAsync(PushoverMessage message, string userKey)
        {
            var parameters = new List <KeyValuePair <string, string> >();

            parameters.Add(new KeyValuePair <string, string>("token", _appToken));
            parameters.Add(new KeyValuePair <string, string>("user", userKey));
            parameters.AddRange(message.ToKeyValuePairs());

            var content = new System.Net.Http.FormUrlEncodedContent(parameters);

            var response = await HttpHandler.PostAsync(RequestUri, content);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception(await response.Content.ReadAsStringAsync());
            }

            return(response);
        }