public async Task <Result <CreatedNotificationVM> > SendNotificationsToAll(string heading, string message) { if (string.IsNullOrEmpty(_ionicPush.Profile)) { throw new Exception("Ionic IO Profile is not provided."); } Result <CreatedNotificationVM> token = new Result <CreatedNotificationVM>(); using (IonicWebClient client = new IonicWebClient(_ionicPush.ApiKey, _ionicPush.BaseUrl)) { var postData = new { send_to_all = true, profile = _ionicPush.Profile, notification = new { message = message, title = heading } }; //var myContent = JsonConvert.SerializeObject(postData); HttpResponseMessage response = await client.PostAsJsonAsync("/push/notifications", postData); if (response.IsSuccessStatusCode) { var jsonString = await response.Content.ReadAsStringAsync(); token = JsonConvert.DeserializeObject <Result <CreatedNotificationVM> >(jsonString); } } return(token); }
public async Task <Result <List <CreatedNotificationVM> > > GetNotifications(int?pageSize, int?page) { Result <List <CreatedNotificationVM> > tokens = new Result <List <CreatedNotificationVM> >(); using (IonicWebClient client = new IonicWebClient(_ionicPush.ApiKey, _ionicPush.BaseUrl)) { var query = HttpUtility.ParseQueryString(""); if (pageSize.HasValue) { query["page_size"] = pageSize.Value.ToString(); } if (page.HasValue) { query["page"] = page.Value.ToString(); } string queryString = "/push/notifications?" + query?.ToString() ?? ""; HttpResponseMessage response = await client.GetAsync(queryString); if (response.IsSuccessStatusCode) { var jsonString = await response.Content.ReadAsStringAsync(); tokens = JsonConvert.DeserializeObject <Result <List <CreatedNotificationVM> > >(jsonString); } } return(tokens); }
public async Task <Result <List <DeviceTokenVM> > > GetTokens(bool?showInvalid, int?pageSize, int?page, string userId = "") { Result <List <DeviceTokenVM> > tokens = new Result <List <DeviceTokenVM> >(); using (IonicWebClient client = new IonicWebClient(_ionicPush.ApiKey, _ionicPush.BaseUrl)) { var query = HttpUtility.ParseQueryString(""); if (showInvalid.HasValue) { query["show_invalid"] = showInvalid.Value.ToString(); } if (pageSize.HasValue) { query["page_size"] = pageSize.Value.ToString(); } if (page.HasValue) { query["page"] = page.Value.ToString(); } if (!string.IsNullOrEmpty(userId)) { query["user_id"] = userId.ToString(); } string queryString = "/push/tokens?" + query?.ToString() ?? ""; HttpResponseMessage response = await client.GetAsync(queryString); if (response.IsSuccessStatusCode) { var jsonString = await response.Content.ReadAsStringAsync(); tokens = JsonConvert.DeserializeObject <Result <List <DeviceTokenVM> > >(jsonString); } } return(tokens); }