Esempio n. 1
0
        public Feed PostFeed(FeedModel request)
        {
            Feed result = null;

            var user = repository.AsQueryable<User>(x => x.Id == request.UserId).FirstOrDefault();

            if (user.FacebookEnabled)
            {
                result = facebookService.PostFeed(request);
            }

            if (user.TwitterEnabled)
            {
                var twitterResult = twitterService.PostFeed(request);
                if (result != null)
                {
                    result.TwitterExternalId = twitterResult.TwitterExternalId;
                }
                else
                {
                    result = twitterResult;
                }
            }

            if (result != null)
            {
                repository.Save(result);
                repository.Commit();
            }

            return result;
        }
Esempio n. 2
0
 public HttpResponseMessage Post(FeedModel request)
 {
     var feedItem = feedService.PostFeed(request);
     var feedItemModel =
     new FeedItemModel
     {
         Message = feedItem.Message,
         Time = feedItem.Time.ToLongDateString(),
         IsPostedToFacebook = string.IsNullOrEmpty(feedItem.FacebookExternalId) ? false : true,
         IsPostedToTwitter = string.IsNullOrEmpty(feedItem.TwitterExternalId) ? false : true
     };
     var response = Request.CreateResponse(HttpStatusCode.Created, feedItemModel);
     return response;
 }
Esempio n. 3
0
        public IList<Feed> GetFeed(FeedModel request)
        {
            var result = facebookService.GetFeed(request);
            var tweets = twitterService.GetFeed(request);

            foreach (Feed tweet in tweets)
            {
                if (!result.Where(x => x.Message == tweet.Message && x.TwitterExternalId == tweet.TwitterExternalId).Any())
                {
                    result.Add(tweet);
                }
            }

            return result;
        }
Esempio n. 4
0
        public IList<Feed> GetFeed(FeedModel request)
        {
            var result = new List<Feed>();

            var user = repository.AsQueryable<Sociopath.DataEntities.Entities.User>().FirstOrDefault(x => x.Id == request.UserId);
            if (user == null || user.TwitterToken == null || user.TwitterSecret == null)
            {
                return result;
            }

            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new InMemoryCredentialStore
                {
                    ConsumerKey = ConsumerKey,
                    ConsumerSecret = ConsumerSecret,
                    OAuthToken = user.TwitterToken,
                    OAuthTokenSecret = user.TwitterSecret
                }
            };
            var twitterCtx = new TwitterContext(auth);

            var tweets = twitterCtx.Status.Where(tweet => tweet.Type == StatusType.User).ToList();

            foreach (Status tweet in tweets)
            {
                Feed feedItem = repository.AsQueryable<Feed>().FirstOrDefault(x => x.TwitterExternalId == tweet.StatusID.ToString()) ?? new Feed();
                feedItem.TwitterExternalId = tweet.StatusID.ToString();
                feedItem.Message = tweet.Text;
                feedItem.Time = tweet.CreatedAt;
                repository.Save(feedItem);
                result.Add(feedItem);
            }

            repository.Commit();
            return result;
        }
Esempio n. 5
0
        public Feed PostFeed(FeedModel model)
        {
            var user = repository.AsQueryable<Sociopath.DataEntities.Entities.User>().FirstOrDefault(x => x.Id == model.UserId);
            if (user == null)
            {
                return null;
            }

            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new InMemoryCredentialStore
                {
                    ConsumerKey = ConsumerKey,
                    ConsumerSecret = ConsumerSecret,
                    OAuthToken = user.TwitterToken,
                    OAuthTokenSecret = user.TwitterSecret
                }
            };
            var twitterCtx = new TwitterContext(auth);

            //var twitterService = new TweetSharp.TwitterService(ConsumerKey, ConsumerSecret);
            //twitterService.AuthenticateWith(user.TwitterToken, user.TwitterSecret);
            //var tweet = twitterService.SendTweet(new SendTweetOptions { Status = model.Message });
            var tweet = twitterCtx.TweetAsync(model.Message).Result;
            var feed = new Feed { TwitterExternalId = tweet.StatusID.ToString(), Time = tweet.CreatedAt, Message = tweet.Text };
            return feed;
        }