示例#1
0
        //Send notifications
        /// <summary>
        /// The method can be used to send a notification to a specific segment
        /// </summary>
        /// <param name="segmant">a segmant object which represents the recipient (Required)</param>
        /// <param name="content">a Content object which represet the content of the notifications (Required)</param>
        /// <param name="attachment">an attachment object which describe the attachments of the notifications</param>
        /// <param name="actionButton">an ActionButton which represent the buttons of the notifications</param>
        /// <returns>the server response</returns>
        public string SendNotification(Segmant segmant, ContentAndLanguage content,
                                       Attachment attachment, Buttons actionButton)
        {
            var dynObject = new ExpandoObject() as IDictionary <String, Object>;

            dynObject.Add("app_id", _app_id);

            //Gather the data into one object


            //Segment
            if (segmant != null)
            {
                segmant.PopulateDynamicObject(dynObject);
            }
            else
            {
                throw new Exception("Segmant can't be null");
            }
            //Content and Language
            if (content != null)
            {
                content.PopulateDynamicObject(dynObject);
            }
            else
            {
                throw new Exception("Content can't be null");
            }
            //Content and Language
            if (attachment != null)
            {
                attachment.PopulateDynamicObject(dynObject);
            }
            //Content and Language
            if (actionButton != null)
            {
                actionButton.PopulateDynamicObject(dynObject);
            }

            string Link   = "https://onesignal.com/api/v1/notifications";
            string Method = "POST";

            return(SendRequest(Link, Method, _rest_api_key, dynObject));
        }
示例#2
0
        private static ContentAndLanguage BuildNotificationContent(Request model, string arMessage, out Attachment attachment)
        {
            Dictionary <string, string> contents = new Dictionary <string, string>();

            contents.Add("ar", arMessage);
            contents.Add("en", arMessage);

            Dictionary <string, string> headings = new Dictionary <string, string>();

            headings.Add("ar", "");
            headings.Add("en", "");

            ContentAndLanguage content = new ContentAndLanguage(contents, headings, null, false);


            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("Id", model.Id.ToString());

            attachment      = new Attachment();
            attachment.data = data;
            return(content);
        }