コード例 #1
0
        static void Main(string[] args)
        {
            Authentication authentication = new Authentication("test", "12345");

            NotifierMobileService.GetAll(authentication, null, null, null);
            NotifierMobileService.Get(5, authentication);

            Notification addModel = new Notification();
            addModel.Title = "title";
            addModel.Message = "message";
            addModel.Type = (int) NotificationType.INFO;
            addModel.CreateDate = DateTime.Now;
            NotifierMobileService.Add(addModel, authentication);

            Notification updateModel = new Notification();
            updateModel.Message = "update";
            updateModel.Title = "update";
            updateModel.Type = 2;

            NotifierMobileService.Update(5, updateModel, authentication);

            NotifierMobileService.MarkAsRead(5, authentication);

            NotifierMobileService.Delete(90, authentication);
        }
コード例 #2
0
        public static WebRequest createRequest(RequestType type, Authentication authentication, int? id, Notification model)
        {
            HttpRequestAttr requestAttrs = (HttpRequestAttr) type.GetAttr();
            WebRequest request;
            string url = requestAttrs.URL;
            if (id.HasValue)
            {
                url += ("/" + id);
            }

            url += "?username="******"&secretKey=" + authentication.SecretKey;

            request = WebRequest.Create(url);
            request.Method = requestAttrs.Method;

            if (model != null)
            {
                request.ContentType = "application/json";

                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    string json = model.GenerateJsonString();
                    streamWriter.Write(json);
                }
            }
            else
            {
                request.ContentLength = 0;
            }

            request.Timeout = CONNECTION_TIMEOUT;

            return request;
        }
コード例 #3
0
        public static WebRequest createGetRequest(RequestType requestType, Authentication authentication, int? id, int? type, bool? unread, int? fromId)
        {
            HttpRequestAttr requestAttrs = (HttpRequestAttr)requestType.GetAttr();
            WebRequest request;
            string url = requestAttrs.URL;
            if (id.HasValue)
            {
                url += ("/" + id);
            }

            url += "?username="******"&secretKey=" + authentication.SecretKey;

            if (type.HasValue)
            {
                url += "&type=" + type.Value;
            }

            if (unread.HasValue)
            {
                url += "&unread=" + unread.Value;
            }

            if (fromId.HasValue)
            {
                url += "&fromId=" + fromId.Value;
            }

            request = WebRequest.Create(url);
            request.Method = requestAttrs.Method;
            request.Timeout = CONNECTION_TIMEOUT;

            return request;
        }
コード例 #4
0
 /// <summary>
 /// Delete a notification by id
 /// </summary>
 /// <param name="id"></param>
 /// <param name="model"></param>
 public static void Delete(int id, Authentication authentication)
 {
     try
     {
         WebRequest request = HttpHelper.createRequest(RequestType.DELETE, authentication, id, null);
         HttpHelper.getResponse(request);
     }
     catch (WebException ex)
     {
         throw createNotificationException(ex);
     }
     catch (Exception ex)
     {
         throw createNotificationException(ex);
     }
 }
コード例 #5
0
 /// <summary>
 /// Add a new notification
 /// </summary>
 /// <param name="model"></param>
 public static void Add(Notification model, Authentication authentication)
 {
     try
     {
         WebRequest request = HttpHelper.createRequest(RequestType.ADD, authentication, null, model);
         HttpHelper.getResponse(request);
     }
     catch (WebException ex)
     {
         throw createNotificationException(ex);
     }
     catch (Exception ex)
     {
         throw createNotificationException(ex);
     }
 }
コード例 #6
0
        /// <summary>
        /// Get notification by id
        /// </summary>
        /// <param name="id"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static Notification Get(int id, Authentication authentication)
        {
            List<Notification> notifications = new List<Notification>();
            try
            {
                WebRequest request = HttpHelper.createGetRequest(RequestType.GET, authentication, id, null, null, null);
                notifications = HttpHelper.getResponse(request);
            }
            catch (WebException ex)
            {
                throw createNotificationException(ex);
            }
            catch (Exception ex)
            {
                throw createNotificationException(ex);
            }

            return notifications[0];
        }
コード例 #7
0
 /// <summary>
 /// Get all notifications
 /// </summary>
 /// <param name="authentication"></param>
 /// <returns></returns>
 public static List<Notification> GetAll(Authentication authentication)
 {
     return GetAll(authentication, null, null, null);
 }
コード例 #8
0
 /// <summary>
 /// Update a notification by id
 /// </summary>
 /// <param name="id"></param>
 /// <param name="model"></param>
 public static void Update(int id, Notification model, Authentication authentication)
 {
     try
     {
         WebRequest request = HttpHelper.createRequest(RequestType.UPDATE, authentication, id, model);
         HttpHelper.getResponse(request);
     }
     catch (WebException ex)
     {
         throw createNotificationException(ex);
     }
     catch (Exception ex)
     {
         throw createNotificationException(ex);
     }
 }
コード例 #9
0
 /// <summary>
 /// Mark a notification as read
 /// </summary>
 /// <param name="id"></param>
 /// <param name="model"></param>
 public static void MarkAsRead(int id, Authentication authentication)
 {
     try
     {
         WebRequest request = HttpHelper.createRequest(RequestType.MARK_AS_READ, authentication, id, null);
         HttpHelper.getResponse(request);
     }
     catch (WebException ex)
     {
         throw createNotificationException(ex);
     }
     catch (Exception ex)
     {
         throw createNotificationException(ex);
     }
 }
コード例 #10
0
        /// <summary>
        /// Get notifications by type and unread and fromId
        /// </summary>
        /// <param name="authentication"></param>
        /// <param name="type"></param>
        /// <param name="unread"></param>
        /// <param name="fromId"></param>
        /// <returns></returns>
        public static List<Notification> GetAll(Authentication authentication, int? type, bool? unread, int? fromId)
        {
            List<Notification> notifications = new List<Notification>();
            try
            {
                WebRequest request = HttpHelper.createGetRequest(RequestType.GET_ALL, authentication, null, type, unread, fromId);
                notifications = HttpHelper.getResponse(request);
            }
            catch (WebException ex)
            {
                throw createNotificationException(ex);
            }
            catch (Exception ex)
            {
                throw createNotificationException(ex);
            }

            return notifications;
        }
コード例 #11
0
 /// <summary>
 /// Get notifications by type and unread
 /// </summary>
 /// <param name="authentication"></param>
 /// <param name="type"></param>
 /// <param name="unread"></param>
 /// <returns></returns>
 public static List<Notification> GetAll(Authentication authentication, int type, bool unread)
 {
     return GetAll(authentication, type, unread, null);
 }