Пример #1
0
        public string GetUsername()
        {
            var result = YammerWebRequest.PerformRequest(new Uri("https://www.yammer.com/api/v1/users/current.xml"),
                                                         ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, Token, TokenSecret);

            return(result.Element("response").Element("name").Value);
        }
Пример #2
0
        public bool ValidateReturnValue(string verifier)
        {
            // 2. Exchange auth.token for access.token
            var result = YammerWebRequest.PerformRequest(new Uri("https://www.yammer.com/oauth/access_token?callback_token=" + verifier),
                                                         ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, Token, TokenSecret, verifier);

            var parts = NameValueParser.GetCollection(result, "&");

            if (ChannelContext.Current == null)
            {
                throw new ArgumentNullException("ChannelContext.Current");
            }

            // Remove token from session
            SafeSession.Current.Remove("/Channels/Yammer/Redirect/Token");
            SafeSession.Current.Remove("/Channels/Yammer/Redirect/TokenSecret");

            // 7. Save auth keys
            ChannelContext.Current.ClientContext.SaveSetting("/Channels/Yammer/AuthToken", parts["oauth_token"]);
            ChannelContext.Current.ClientContext.SaveSetting("/Channels/Yammer/AuthSecret", parts["oauth_token_secret"]);

            Token       = parts["oauth_token"];
            TokenSecret = parts["oauth_token_secret"];

            return(true);
        }
Пример #3
0
        public void UpdateMyStatus(ChannelStatusUpdate update)
        {
            var p = new Dictionary <string, object> {
                { "body", update.Status }
            };

            if (!String.IsNullOrEmpty(update.InReplyTo))
            {
                p.Add("replied_to_id", update.InReplyTo);
            }

            YammerWebRequest.PerformRequest(new Uri("https://www.yammer.com/api/v1/messages/"), ChannelHelper.ConsumerKey,
                                            ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret, p);
        }
Пример #4
0
        public ChannelSocialProfile GetProfile()
        {
            var result = YammerWebRequest.PerformRequest(new Uri("https://www.yammer.com/api/v1/users/current.xml"),
                                                         ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);

            var contact = ParseYammerContact(result.Element("response"));

            return(new ChannelSocialProfile
            {
                Id = contact.Id,
                FullName = contact.FullName,
                AvatarUrl = contact.AvatarUrl
            });
        }
Пример #5
0
        public Uri BuildRedirectUri()
        {
            // 1. Get Auth Token
            var result = YammerWebRequest.PerformRequest(new Uri("https://www.yammer.com/oauth/request_token"), ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret);
            var parts  = NameValueParser.GetCollection(result, "&");

            Token       = parts["oauth_token"];
            TokenSecret = parts["oauth_token_secret"];

            // Save data in session for re-materialization
            SafeSession.Current["/Channels/Yammer/Redirect/Token"]       = Token;
            SafeSession.Current["/Channels/Yammer/Redirect/TokenSecret"] = TokenSecret;

            return(new Uri("https://www.yammer.com/oauth/authorize?oauth_token=" + Token));
        }
Пример #6
0
        public IEnumerable <ChannelStatusUpdate> GetUserUpdates(string username, int pageSize)
        {
            const string url    = "https://www.yammer.com/api/v1/messages/from_user/{0}.xml";
            var          result = YammerWebRequest.PerformRequest(new Uri(String.Format(url, username)),
                                                                  ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);

            foreach (var element in result.Element("response").Elements("messages").Elements("message"))
            {
                var update = new ChannelStatusUpdate();

                update.ChannelStatusKey = element.Element("id").Value;
                update.From             = new SourceAddress(element.Element("sender-id").Value, username);
                update.Status           = element.Element("body").Element("plain").Value;
                update.DatePosted       = DateTime.Parse(element.Element("created-at").Value);

                yield return(update);
            }
        }
Пример #7
0
        IEnumerable <YammerContact> GetYammerContacts()
        {
            int page = 1;

            while (true)
            {
                var result = YammerWebRequest.PerformRequest(new Uri("https://www.yammer.com/api/v1/users.xml?page=" + page),
                                                             ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);

                if (result.Element("response").Elements().Count() == 0)
                {
                    yield break;
                }

                foreach (var response in result.Elements("response").Elements("response"))
                {
                    yield return(ParseYammerContact(response));
                }

                page++;
            }
        }
Пример #8
0
        public IEnumerable <ChannelStatusUpdate> GetUpdates(int pageSize)
        {
            var contacts = GetYammerContacts();
            var result   = YammerWebRequest.PerformRequest(new Uri("https://www.yammer.com/api/v1/messages.xml"),
                                                           ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);

            var dict = new Dictionary <string, List <ChannelStatusUpdate> >();

            foreach (var element in result.Element("response").Elements("messages").Elements("message"))
            {
                var update  = new ChannelStatusUpdate();
                var contact = contacts.First(c => c.Id == element.Element("sender-id").Value);

                update.ChannelStatusKey = element.Element("id").Value;
                update.From             = new SourceAddress(contact.Id, contact.FullName, contact.AvatarUrl);
                update.Status           = element.Element("body").Element("plain").Value;
                update.DatePosted       = DateTime.Parse(element.Element("created-at").Value);

                foreach (var attachmentElement in element.Descendants("attachment"))
                {
                    var attachment = new ChannelStatusUpdateAttachment();
                    var type       = attachmentElement.Element("type").Value;

                    attachment.PreviewAltText = attachmentElement.Element("name").Value;
                    attachment.TargetUrl      = attachmentElement.Element("web-url").Value;

                    if (type == "image")
                    {
                        attachment.MediaType       = StatusAttachmentTypes.Photo;
                        attachment.PreviewImageUrl = attachmentElement.Element("image").Element("thumbnail-url").Value;
                    }
                    else
                    {
                        attachment.MediaType = StatusAttachmentTypes.Document;
                    }

                    update.Attachments.Add(attachment);
                }

                var threadid = element.Element("thread-id").Value;

                if (!dict.ContainsKey(threadid))
                {
                    dict.Add(threadid, new List <ChannelStatusUpdate>());
                }

                dict[threadid].Add(update);
            }

            var updates = new List <ChannelStatusUpdate>();

            foreach (var value in dict.Values)
            {
                var sortedList = value.OrderBy(c => c.DatePosted).ToList();
                var first      = sortedList.First();

                first.Children.AddRange(sortedList.Skip(1));

                updates.Add(first);
            }

            return(updates.OrderByDescending(s => s.SortDate));
        }