Exemple #1
0
        /// <summary>
        /// Posts the message, asynchronously.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        /// The message feed task.
        /// </returns>
        public async Task <MessageFeed> PostMessageAsync(PostRequest request)
        {
            request.ThrowIfNull(nameof(request));

            User currentUser = await this.GetCurrentUserAsync();

            string json = JsonConvert.SerializeObject(request);

            using (HttpContent content = new StringContent(json))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                using (HttpResponseMessage response = await this.Client.PostAsync(YammerService.BuildRequest("messages.json"), content))
                {
                    MessageFeed feed = await YammerService.GetResponseContentAsync <MessageFeed>(response);

                    return(YammerService.ProcessMessages(currentUser, feed));
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets the activity feed, asynchronously.
        /// </summary>
        /// <param name="olderThanId">The older than identifier.</param>
        /// <param name="newerThanId">The newer than identifier.</param>
        /// <param name="limit">The limit.</param>
        /// <returns>
        /// The activity feed task.
        /// </returns>
        private async Task <MessageFeed> GetMessagesAsync(string uri, Threaded?threaded, int olderThanId, int newerThanId, int limit)
        {
            List <string> parameters = new List <string>(3);

            if (threaded.HasValue)
            {
                parameters.Add("threaded");
                parameters.Add(YammerService.ThreadedValues[threaded.Value]);
            }

            if (limit > 0)
            {
                parameters.Add("limit");
                parameters.Add(limit.ToString());
            }

            if (olderThanId > 0)
            {
                parameters.Add("older_than");
                parameters.Add(olderThanId.ToString());
            }

            if (newerThanId > 0)
            {
                parameters.Add("newer_than");
                parameters.Add(newerThanId.ToString());
            }

            // forces all loaded messages to be marked read
            parameters.Add("update_last_seen_message_id");
            parameters.Add("true");

            User currentUser = await this.GetCurrentUserAsync();

            using (HttpResponseMessage response = await this.Client.GetAsync(YammerService.BuildRequest(uri, parameters.ToArray()), HttpCompletionOption.ResponseContentRead))
            {
                MessageFeed feed = await YammerService.GetResponseContentAsync <MessageFeed>(response);

                return(YammerService.ProcessMessages(currentUser, feed));
            }
        }