Example #1
0
        public async Task <ChannelState> Query(ChannelQueryParams queryParams)
        {
            var payload = JObject.FromObject(queryParams);

            payload.Add("data", this._data.ToJObject());

            string tpl      = "channels/{0}{1}/query";
            string idStr    = this.ID == null ? "" : "/" + this.ID;
            string endpoint = string.Format(tpl, this.Type, idStr);

            var request = this._client.BuildAppRequest(endpoint, HttpMethod.POST);

            request.SetJsonBody(JsonConvert.SerializeObject(payload));

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                var stateObj = JObject.Parse(response.Content);
                stateObj.Remove("duration");
                var chanState = ChannelState.FromJObject(stateObj);
                if (string.IsNullOrEmpty(this.ID))
                {
                    this.ID = chanState.Channel.ID;
                }
                return(chanState);
            }
            throw StreamChatException.FromResponse(response);
        }
Example #2
0
        public async Task Ban(string targetUserID, string id, string reason, Channel channel, int timeoutMinutes = 0)
        {
            var payload = new Dictionary <string, object>()
            {
                { "target_user_id", targetUserID },
                { "reason", reason },
                { "timeout", timeoutMinutes },
                { "user_id", id },
            };

            if (channel != null)
            {
                payload["type"] = channel.Type;
                payload["id"]   = channel.ID;
            }
            var request = this._client.BuildAppRequest("moderation/ban", HttpMethod.POST);

            request.SetJsonBody(JsonConvert.SerializeObject(payload));

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode != System.Net.HttpStatusCode.Created)
            {
                throw StreamChatException.FromResponse(response);
            }
        }
Example #3
0
        public async Task <UpdateChannelResponse> Update(GenericData customData, MessageInput msg = null, bool skipPush = false)
        {
            var payload = new JObject();

            payload.Add(new JProperty("data", customData.ToJObject()));
            if (msg != null)
            {
                payload.Add(new JProperty("message", msg.ToJObject()));

                if (skipPush)
                {
                    payload.Add("skip_push", true);
                }
            }

            var request = this._client.BuildAppRequest(this.Endpoint, HttpMethod.POST);

            request.SetJsonBody(payload.ToString());

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                this._data = customData;
                var respObj = JObject.Parse(response.Content);
                return(UpdateChannelResponse.FromJObject(respObj));
            }
            throw StreamChatException.FromResponse(response);
        }
Example #4
0
        public async Task RemoveMembers(IEnumerable <string> userIDs, MessageInput msg = null)
        {
            var payload = new JObject(new JProperty("remove_members", userIDs));

            if (msg != null)
            {
                if (msg.User != null)
                {
                    msg.User = new User()
                    {
                        ID = msg.User.ID
                    };
                }
                payload.Add("message", msg.ToJObject());
            }

            var request = this._client.BuildAppRequest(this.Endpoint, HttpMethod.POST);

            request.SetJsonBody(JsonConvert.SerializeObject(payload));

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode != System.Net.HttpStatusCode.Created)
            {
                throw StreamChatException.FromResponse(response);
            }
        }
Example #5
0
        public async Task <Message> SendMessage(MessageInput msg, string userID)
        {
            if (msg.User == null)
            {
                msg.User = new User();
            }
            msg.User.ID = userID;

            var payload = new JObject(new JProperty("message", msg.ToJObject()));


            var request = this._client.BuildAppRequest(this.Endpoint + "/message", HttpMethod.POST);

            request.SetJsonBody(payload.ToString());

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                var respObj = JObject.Parse(response.Content);
                var msgObj  = respObj.Property("message").Value as JObject;
                return(Message.FromJObject(msgObj));
            }
            throw StreamChatException.FromResponse(response);
        }
Example #6
0
        public async Task <MessagePartialUpdateResponse> UpdateMessagePartial(string messageId, MessagePartialUpdateRequest partialUpdateRequest)
        {
            if (string.IsNullOrWhiteSpace(messageId))
            {
                throw new ArgumentException("The messageId must be set.", nameof(messageId));
            }

            var endpoint = string.Format("messages/{0}", messageId);
            var request  = this.BuildAppRequest(endpoint, HttpMethod.PUT);

            request.SetJsonBody(JsonConvert.SerializeObject(partialUpdateRequest));

            var response = await MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                var respObj = JObject.Parse(response.Content);
                var msgObj  = respObj.Property("message").Value as JObject;

                return(new MessagePartialUpdateResponse
                {
                    Duration = respObj.Property("duration").Value.ToString(),
                    Message = Message.FromJObject(msgObj)
                });
            }
            throw StreamChatException.FromResponse(response);
        }
Example #7
0
        public async Task <List <Reaction> > GetReactions(string messageID, int offset = 0, int limit = 50)
        {
            var endpoint = string.Format("messages/{0}/reactions", messageID);
            var request  = this._client.BuildAppRequest(endpoint, HttpMethod.GET);

            request.AddQueryParameter("offset", offset.ToString());
            request.AddQueryParameter("limit", limit.ToString());

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var respObj      = JObject.Parse(response.Content);
                var reactionObjs = respObj.Property("reactions").Value as JArray;

                var result = new List <Reaction>();
                foreach (var reactionTok in reactionObjs)
                {
                    var r = reactionTok as JObject;
                    result.Add(Reaction.FromJObject(r));
                }
                return(result);
            }
            throw StreamChatException.FromResponse(response);
        }
        public async Task <ReactionResponse> SendReaction(string messageID, Reaction reaction, string userID, bool skipPush = false)
        {
            if (reaction.User == null)
            {
                reaction.User = new User();
            }
            reaction.User.ID = userID;

            var payload = new JObject(new JProperty("reaction", reaction.ToJObject()));

            if (skipPush)
            {
                payload.Add("skip_push", true);
            }

            var endpoint = string.Format("messages/{0}/reaction", messageID);
            var request  = this._client.BuildAppRequest(endpoint, HttpMethod.POST);

            request.SetJsonBody(payload.ToString());

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                var respObj = JObject.Parse(response.Content);
                return(ReactionResponse.FromJObject(respObj));
            }
            throw StreamChatException.FromResponse(response);
        }
Example #9
0
        public async Task AddDevice(Device d)
        {
            var request = BuildAppRequest("devices", HttpMethod.POST);
            request.SetJsonBody(JsonConvert.SerializeObject(d));

            var response = await this.MakeRequest(request);
            if (response.StatusCode != System.Net.HttpStatusCode.Created)
                throw StreamChatException.FromResponse(response);
        }
Example #10
0
        public async Task UpdateAppSettings(AppSettings settings)
        {
            var request = BuildAppRequest("app", HttpMethod.PATCH);
            request.SetJsonBody(JsonConvert.SerializeObject(settings));

            var response = await this.MakeRequest(request);
            if (response.StatusCode != System.Net.HttpStatusCode.OK)
                throw StreamChatException.FromResponse(response);
        }
Example #11
0
        public async Task Delete()
        {
            var request  = this._client.BuildAppRequest(this.Endpoint, HttpMethod.DELETE);
            var response = await this._client.MakeRequest(request);

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw StreamChatException.FromResponse(response);
            }
        }
Example #12
0
        public async Task DeleteChannelType(string type)
        {
            var endpoint = string.Format("channeltypes/{0}", type);
            var request = BuildAppRequest(endpoint, HttpMethod.DELETE);

            var response = await this.MakeRequest(request);

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
                throw StreamChatException.FromResponse(response);
        }
Example #13
0
        public async Task RemoveDevice(string deviceID, string userID)
        {
            var request = BuildAppRequest("devices", HttpMethod.DELETE);
            request.AddQueryParameter("user_id", userID);
            request.AddQueryParameter("id", deviceID);

            var response = await this.MakeRequest(request);
            if (response.StatusCode != System.Net.HttpStatusCode.OK)
                throw StreamChatException.FromResponse(response);
        }
Example #14
0
        public async Task Truncate()
        {
            var request  = this._client.BuildAppRequest(this.Endpoint + "/truncate", HttpMethod.POST);
            var response = await this._client.MakeRequest(request);

            if (response.StatusCode != System.Net.HttpStatusCode.Created)
            {
                throw StreamChatException.FromResponse(response);
            }
        }
Example #15
0
        public async Task <ExportedUser> Export(string id)
        {
            var request  = this._client.BuildAppRequest(Users.Endpoint(id) + "/export", HttpMethod.GET);
            var response = await this._client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(ExportedUser.FromJObject(JObject.Parse(response.Content)));
            }

            throw StreamChatException.FromResponse(response);
        }
Example #16
0
        public async Task<ChannelTypeInfo> GetChannelType(string type)
        {
            var endpoint = string.Format("channeltypes/{0}", type);
            var request = BuildAppRequest(endpoint, HttpMethod.GET);

            var response = await this.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
                return JsonConvert.DeserializeObject<ChannelTypeInfo>(response.Content);

            throw StreamChatException.FromResponse(response);
        }
Example #17
0
        public async Task<List<Device>> GetDevices(string userID)
        {
            var request = BuildAppRequest("devices", HttpMethod.GET);
            request.AddQueryParameter("user_id", userID);
            var response = await this.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var obj = JObject.Parse(response.Content);
                return (List<Device>)obj.Property("devices").Value.ToObject(typeof(List<Device>));
            }
            throw StreamChatException.FromResponse(response);
        }
Example #18
0
        public async Task<AppSettingsWithDetails> GetAppSettings()
        {
            var request = BuildAppRequest("app", HttpMethod.GET);

            var response = await this.MakeRequest(request);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var obj = JObject.Parse(response.Content);
                return (AppSettingsWithDetails)obj.Property("app").Value.ToObject(typeof(AppSettingsWithDetails));
            }

            throw StreamChatException.FromResponse(response);
        }
Example #19
0
        public async Task <TaskStatus> GetTaskStatus(string taskId)
        {
            var endpoint = string.Format("tasks/{0}", taskId);
            var request  = this.BuildAppRequest(endpoint, HttpMethod.GET);

            var response = await this.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(JsonConvert.DeserializeObject <TaskStatus>(response.Content));
            }
            throw StreamChatException.FromResponse(response);
        }
Example #20
0
        public async Task <Dictionary <string, ChannelTypeInfo> > ListChannelTypes()
        {
            var request  = BuildAppRequest("channeltypes", HttpMethod.GET);
            var response = await this.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var obj = JObject.Parse(response.Content);
                return((Dictionary <string, ChannelTypeInfo>)obj.Property("channel_types").Value.ToObject(typeof(Dictionary <string, ChannelTypeInfo>)));
            }

            throw StreamChatException.FromResponse(response);
        }
Example #21
0
        public async Task <IEnumerable <User> > Query(QueryUserOptions opts)
        {
            var request = this._client.BuildAppRequest(Users.Endpoint(), HttpMethod.GET);

            opts.Apply(request);

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(Users.GetResults(response.Content));
            }
            throw StreamChatException.FromResponse(response);
        }
Example #22
0
        public async Task <string> DeleteMany(DeleteUsersRequest req)
        {
            var request = this._client.BuildAppRequest(Users.Endpoint("delete"), HttpMethod.POST);

            request.SetJsonBody(JsonConvert.SerializeObject(req));

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                return(JObject.Parse(response.Content).Property("task_id").Value.ToString());
            }
            throw StreamChatException.FromResponse(response);
        }
Example #23
0
        public async Task <MessageSearchResponse> Search(SearchOptions opts)
        {
            var request = this.BuildAppRequest("search", HttpMethod.GET);

            opts.Apply(request);

            var response = await this.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(JsonConvert.DeserializeObject <MessageSearchResponse>(response.Content));
            }
            throw StreamChatException.FromResponse(response);
        }
Example #24
0
        public async Task Show(string userID)
        {
            var request = this._client.BuildAppRequest(this.Endpoint + "/show", HttpMethod.POST);
            var payload = new JObject(new JProperty("user_id", userID));

            request.SetJsonBody(JsonConvert.SerializeObject(payload));

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                throw StreamChatException.FromResponse(response);
            }
        }
Example #25
0
        public async Task <RateLimitsMap> GetRateLimits(GetRateLimitsOptions opts)
        {
            var request = BuildAppRequest("rate_limits", HttpMethod.GET);

            opts.Apply(request);

            var response = await this.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(JsonConvert.DeserializeObject <RateLimitsMap>(response.Content));
            }
            throw StreamChatException.FromResponse(response);
        }
Example #26
0
        public async Task <Message> DeleteMessage(string messageID)
        {
            var endpoint = string.Format("messages/{0}", messageID);
            var request  = this.BuildAppRequest(endpoint, HttpMethod.DELETE);

            var response = await this.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var respObj = JObject.Parse(response.Content);
                var msgObj  = respObj.Property("message").Value as JObject;
                return(Message.FromJObject(msgObj));
            }
            throw StreamChatException.FromResponse(response);
        }
Example #27
0
        public async Task Hide(string userID, bool clearHistory = false)
        {
            var request = this._client.BuildAppRequest(this.Endpoint + "/hide", HttpMethod.POST);
            var payload = new JObject();

            payload.Add("user_id", userID);
            payload.Add("clear_history", clearHistory);
            request.SetJsonBody(JsonConvert.SerializeObject(payload));

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                throw StreamChatException.FromResponse(response);
            }
        }
Example #28
0
        public async Task<ChannelTypeOutput> CreateChannelType(ChannelTypeInput channelType)
        {
            if (channelType.Commands == null || channelType.Commands.Count == 0)
            {
                channelType.Commands = new List<string>() { Commands.All };
            }
            var request = BuildAppRequest("channeltypes", HttpMethod.POST);
            request.SetJsonBody(JsonConvert.SerializeObject(channelType));

            var response = await this.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
                return JsonConvert.DeserializeObject<ChannelTypeOutput>(response.Content);

            throw StreamChatException.FromResponse(response);
        }
Example #29
0
        public async Task <ReactionResponse> DeleteReaction(string messageID, string reactionType, string userID)
        {
            var endpoint = string.Format("messages/{0}/reaction/{1}", messageID, reactionType);
            var request  = this._client.BuildAppRequest(endpoint, HttpMethod.DELETE);

            request.AddQueryParameter("user_id", userID);

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var respObj = JObject.Parse(response.Content);
                return(ReactionResponse.FromJObject(respObj));
            }
            throw StreamChatException.FromResponse(response);
        }
Example #30
0
        public async Task<ChannelTypeOutput> UpdateChannelType(string type, ChannelTypeInput channelType)
        {
            var payload = JObject.FromObject(channelType);
            payload.Remove("name");

            var endpoint = string.Format("channeltypes/{0}", type);
            var request = BuildAppRequest(endpoint, HttpMethod.PUT);
            request.SetJsonBody(payload.ToString());

            var response = await this.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
                return JsonConvert.DeserializeObject<ChannelTypeOutput>(response.Content);

            throw StreamChatException.FromResponse(response);
        }