public void PublishMessage(
            string channelId,
            string nick,
            string body,
            string locale,
            Dictionary <string, string> data,
            bool translate,
            bool filter,
            bool persist,
            Action <FizzException> callback)
        {
            IfOpened(() =>
            {
                if (string.IsNullOrEmpty(channelId))
                {
                    FizzUtils.DoCallback(ERROR_INVALID_CHANNEL, callback);
                    return;
                }

                try
                {
                    string path    = string.Format(FizzConfig.API_PATH_MESSAGES, channelId);
                    JSONClass json = new JSONClass();
                    json[FizzJsonChannelMessage.KEY_NICK]             = nick;
                    json[FizzJsonChannelMessage.KEY_BODY]             = body;
                    json[FizzJsonChannelMessage.KEY_PERSIST].AsBool   = persist;
                    json[FizzJsonChannelMessage.KEY_FILTER].AsBool    = filter;
                    json[FizzJsonChannelMessage.KEY_TRANSLATE].AsBool = translate;

                    string dataStr = string.Empty;
                    if (data != null)
                    {
                        JSONClass dataJson = new JSONClass();
                        foreach (KeyValuePair <string, string> pair in data)
                        {
                            dataJson.Add(pair.Key, new JSONData(pair.Value));
                        }

                        dataStr = dataJson.ToString();
                    }
                    json[FizzJsonChannelMessage.KEY_DATA] = dataStr;

                    if (!string.IsNullOrEmpty(locale))
                    {
                        json[FizzJsonChannelMessage.KEY_LOCALE] = locale;
                    }

                    _restClient.Post(FizzConfig.API_BASE_URL, path, json.ToString(), (response, ex) =>
                    {
                        FizzUtils.DoCallback(ex, callback);
                    });
                }
                catch (FizzException ex)
                {
                    FizzUtils.DoCallback(ex, callback);
                }
            });
        }
Exemple #2
0
 public void Subscribe(string userId, Action <FizzException> callback)
 {
     IfOpened(() =>
     {
         string path = string.Format(FizzConfig.API_PATH_USER_SUBCRIBERS, userId);
         _client.Post(FizzConfig.API_BASE_URL, path, string.Empty, (response, ex) =>
         {
             FizzUtils.DoCallback(ex, callback);
         });
     });
 }
 private void PostEvents(List <FizzEvent> events,
                         Action <string, FizzException> callback)
 {
     _client.Post(
         FizzConfig.API_BASE_URL,
         FizzConfig.API_PATH_EVENTS,
         ParseEvents(events),
         callback
         );
 }
Exemple #4
0
 public void Subscribe(Action <FizzException> callback)
 {
     IfOpened(() =>
     {
         string path = FizzConfig.API_PATH_USER_NOTIFICATIONS;
         _client.Post(FizzConfig.API_BASE_URL, path, string.Empty, (response, ex) =>
         {
             FizzUtils.DoCallback(ex, callback);
         });
     });
 }
        public void PublishMessage(
            string groupId,
            string nick,
            string body,
            Dictionary <string, string> data,
            bool translate,
            bool filter,
            bool persist,
            Action <FizzException> callback)
        {
            IfOpened(() =>
            {
                string path    = string.Format(FizzConfig.API_PATH_GROUP_MESSAGES, groupId);
                JSONClass json = new JSONClass();
                json[FizzJsonChannelMessage.KEY_NICK]             = nick;
                json[FizzJsonChannelMessage.KEY_BODY]             = body;
                json[FizzJsonChannelMessage.KEY_PERSIST].AsBool   = persist;
                json[FizzJsonChannelMessage.KEY_FILTER].AsBool    = filter;
                json[FizzJsonChannelMessage.KEY_TRANSLATE].AsBool = translate;

                string dataStr = string.Empty;
                if (data != null)
                {
                    JSONClass dataJson = new JSONClass();
                    foreach (KeyValuePair <string, string> pair in data)
                    {
                        dataJson.Add(pair.Key, new JSONData(pair.Value));
                    }

                    dataStr = dataJson.ToString();
                }

                json[FizzJsonChannelMessage.KEY_DATA] = dataStr;

                _restClient.Post(FizzConfig.API_BASE_URL, path, json.ToString(), (response, ex) =>
                {
                    FizzUtils.DoCallback(ex, callback);
                });
            });
        }
Exemple #6
0
        public void SanitizeText(IList <string> texts,
                                 Action <IList <string>, FizzException> callback)
        {
            IfOpened(() =>
            {
                if (texts == null)
                {
                    FizzUtils.DoCallback <IList <string> > (null, ERROR_INVALID_TEXT_LIST, callback);
                    return;
                }

                if (texts.Count > MAX_TEXT_LIST_SIZE)
                {
                    FizzUtils.DoCallback <IList <string> > (null, ERROR_INVALID_TEXT_LIST_SIZE, callback);
                    return;
                }

                foreach (string text in texts)
                {
                    if (text == null || text.Length > MAX_TEXT_LENGTH)
                    {
                        FizzUtils.DoCallback <IList <string> > (null, ERROR_INVALID_TEXT_LIST, callback);
                        return;
                    }
                }

                try
                {
                    string path    = FizzConfig.API_PATH_CONTENT_MODERATION;
                    JSONArray json = new JSONArray();
                    foreach (string text in texts)
                    {
                        json.Add(new JSONData(text));
                    }

                    _restClient.Post(FizzConfig.API_BASE_URL, path, json.ToString(), (response, ex) =>
                    {
                        if (ex != null)
                        {
                            FizzUtils.DoCallback <IList <string> > (null, ex, callback);
                        }
                        else
                        {
                            try
                            {
                                JSONArray textResultArr          = JSONNode.Parse(response).AsArray;
                                IList <string> moderatedTextList = new List <string> ();
                                foreach (JSONNode message in textResultArr.Childs)
                                {
                                    moderatedTextList.Add(message);
                                }
                                FizzUtils.DoCallback <IList <string> > (moderatedTextList, null, callback);
                            }
                            catch
                            {
                                FizzUtils.DoCallback <IList <string> > (null, ERROR_INVALID_RESPONSE_FORMAT, callback);
                            }
                        }
                    });
                }
                catch (FizzException ex)
                {
                    FizzUtils.DoCallback <IList <string> > (null, ex, callback);
                }
            });
        }