Пример #1
0
 private XboxClient(Connection connection)
 {
     Profile      = new ProfileClient(connection);
     Friends      = new FriendsClient(connection);
     Games        = new GamesClient(connection);
     Achievements = new AchievementsClient(connection);
     Search       = new SearchClient(connection);
 }
Пример #2
0
        public void GetLists(long CurrentUserId, long ListOwnerId)
        {
            FriendsClient friends = new FriendsClient(CurrentUserId);
            WebClientResult<FriendsList> friendsList = friends.FriendIds(ListOwnerId.ToString(), null, null);

            ListClient list = new ListClient(CurrentUserId);

            WebClientResult<Lists> lists = list.Lists(ListOwnerId.ToString(), null);
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GoodreadsClient"/> class.
        /// Use this constructor if you already have OAuth permissions for the user.
        /// </summary>
        /// <param name="apiKey">Your Goodreads API key.</param>
        /// <param name="apiSecret">Your Goodreads API secret.</param>
        /// <param name="accessToken">The user's OAuth access token.</param>
        /// <param name="accessSecret">The user's OAuth access secret.</param>
        public GoodreadsClient(string apiKey, string apiSecret, string accessToken, string accessSecret)
        {
            var client = new RestClient(new Uri(GoodreadsUrl))
            {
                UserAgent = "goodreads-dotnet"
            };

            client.AddDefaultParameter("key", apiKey, ParameterType.QueryString);
            client.AddDefaultParameter("format", "xml", ParameterType.QueryString);

            var apiCredentials = new ApiCredentials(client, apiKey, apiSecret, accessToken, accessSecret);

            // Setup the OAuth authenticator if they have passed on the appropriate tokens
            if (!string.IsNullOrWhiteSpace(accessToken) &&
                !string.IsNullOrWhiteSpace(accessSecret))
            {
                client.Authenticator = OAuth1Authenticator.ForProtectedResource(
                    apiKey, apiSecret, accessToken, accessSecret);
            }

            Connection       = new Connection(client, apiCredentials);
            Authors          = new AuthorsClient(Connection);
            Books            = new BooksClient(Connection);
            Shelves          = new ShelvesClient(Connection);
            Users            = new UsersClient(Connection);
            Reviews          = new ReviewsClient(Connection);
            Series           = new SeriesClient(Connection);
            AuthorsFollowing = new AuthorsFollowingClient(Connection);
            Events           = new EventsClient(Connection);
            Followers        = new FollowersClient(Connection);
            Friends          = new FriendsClient(Connection);
            Notifications    = new NotificationsClient(Connection);
            Groups           = new GroupClient(Connection);
            Quotes           = new QuotesClient(Connection);
            UserStatuses     = new UserStatusesClient(Connection);
            Updates          = new UpdatesClient(Connection);
            Recommendations  = new RecommendationsClient(Connection);
            ReadStatuses     = new ReadStatusesClient(Connection);
        }
Пример #4
0
        public int SyncToDatabase(SyncToDatabaseOp Op, CurrentUser currentUser, long UserId)
        {
            logger.Debug("SyncFollowersToDatabase(Op: {0}, CurrentUser: {1}, UserId: {2})", (object) Op, (object) currentUser.Id, (object) UserId);

            FriendsClient friends = new FriendsClient(currentUser.Id);
            WebClientResult<FriendsList> FriendsList;

            if (Op == SyncToDatabaseOp.GetFollowers)
                FriendsList = friends.FollowerIds(UserId.ToString(), null, null);
            else
                FriendsList = friends.FriendIds(UserId.ToString(), null, null);

            using (var db = new ToketeeData().Context)
            {

                // TODO Handle deletes

                // Get the current known followers list from the DB
                // TODO find a way to create an IQueryable when specific columns are returned
                IQueryable<TwitterFriends> qFriendsInDb;
                if (Op == SyncToDatabaseOp.GetFollowers)
                {
                    qFriendsInDb = from f in db.TwitterFriends
                                   where f.FriendId == UserId
                                   select f;
                }
                else
                {
                    qFriendsInDb = from f in db.TwitterFriends
                                   where f.OwnerId == UserId
                                   select f;
                }

                logger.Trace("Known friends in DB for {0} / Count: {1}", UserId.ToString(), qFriendsInDb.Count().ToString());

                var qtest = qFriendsInDb.Where(x => x.FriendId == 13348).Count();
                // Determine which followers are not in the friend tracking table

                //ownerid

                IEnumerable<long> NewFollowers;
                IEnumerable<TwitterFriends> DeletedFollowers;
                if (Op == SyncToDatabaseOp.GetFollowers)
                {
                    // Followers are identified by the OwnerId having a FriendId of the method's UserId
                    NewFollowers = from f in FriendsList.Object
                                   where !(from a in qFriendsInDb
                                           select a.OwnerId).Contains(f)
                                   select f;

                    var tempFriendsList = FriendsList.Object.ToList();
                    DeletedFollowers = from f in qFriendsInDb
                                       where !tempFriendsList.Contains(f.OwnerId)
                                       select f;

                    //DeletedFollowers = from f in qFriendsInDb
                    //                   where !(from a in FriendsList.Object
                    //                           select a).Contains(f.OwnerId)
                    //                   select f;
                }
                else
                {
                    // Friends are identified by the FriendId having the OwnerId of the method's UserId
                    NewFollowers = from f in FriendsList.Object
                                   where !(from a in qFriendsInDb
                                           select a.FriendId).Contains(f)
                                   select f;

                    var tempFriendsList = FriendsList.Object.ToList();
                    DeletedFollowers = from f in qFriendsInDb
                                       where !tempFriendsList.Contains(f.FriendId)
                                       select f;

                    //DeletedFollowers = from f in qFriendsInDb
                    //                   where !(from a in FriendsList.Object
                    //                           select a).Contains(f.FriendId)
                    //                   select f;
                }

                logger.Trace("New followers: {0} / Unfollows: {1}", NewFollowers.Count(), DeletedFollowers.Count());

                var NewFollowersList = new List<long>();
                foreach (long Id in NewFollowers)
                {
                    var tFriends = new TwitterFriends()
                    {
                        OwnerId = (Op == SyncToDatabaseOp.GetFollowers) ? Id : UserId,
                        FriendId = (Op == SyncToDatabaseOp.GetFollowers) ? UserId : Id
                    };
                    db.TwitterFriends.Add(tFriends);
                    NewFollowersList.Add(Id);
                }

                var userOps = new UserOps(currentUser.Id);
                Users users = userOps.Lookup(NewFollowersList);

                string s = string.Join(",", FriendsList.Object.ToArray());
                var qExistingUsers = db.TwitterUser.SqlQuery("select * from TwitterUser where Id in (" + s + ");");

                // for each User in Users, find the corresponding TwitterUser to update

                // Filter out the users that do exist so we can insert the new ones

                var qDontExist = from u in users
                                 where !(from a in qExistingUsers
                                         select a.Id.ToString()).Contains(u.Id)
                                 select u;

                logger.Trace("Users to be inserted: {0}", qDontExist.Count().ToString());

                foreach (TwitterAPI.User u in qDontExist)
                {
                    if (qExistingUsers.Where(x => x.Id.ToString() == u.Id).Count() > 0)
                        logger.Error("User already exists, but shouldn't! {0}", u.Id);

                }

                TwitterUser tUser;

                foreach (TwitterAPI.User u in qDontExist.Distinct())
                {
                    tUser = new TwitterUser();
                    UserOps.UserObjToTwitterUser(u, tUser);
                    db.TwitterUser.Add(tUser);
                    logger.Trace("Inserted TwitterUser: {0}", tUser.Id);
                }

                foreach (TwitterUser tu in qExistingUsers)
                {
                    try
                    {
                        var q2 = (from u in users
                                  where u.Id == tu.Id.ToString()
                                  select u).SingleOrDefault();
                        if (q2 != null) UserOps.UserObjToTwitterUser(q2, tu);
                        logger.Trace("Updated TwitterUser: {0}", tu.Id);
                    }
                    catch (InvalidOperationException e)
                    {
                        string sError = String.Format("UserObjToTwitterUser unable to match existing user TwitterUser {0} to friends list user", tu.Id);
                        logger.ErrorException(sError, e);
                    }
                }

                // Process unfollows

                int iFriendshipsDeleted = 0;
                foreach (TwitterFriends tf in DeletedFollowers)
                {
                    logger.Trace("Deleting friendship: Owner {0} Friend {1}", tf.OwnerId, tf.FriendId);
                    db.TwitterFriends.Remove(tf);
                    iFriendshipsDeleted++;
                }
                if (iFriendshipsDeleted > 0) logger.Debug("Friendships deleted: {0}", iFriendshipsDeleted);
                return db.SaveChanges();
            }
        }
Пример #5
0
            public async Task GetFriendRequestMethod()
            {
                var requests = await FriendsClient.GetFriendRequests();

                Assert.NotNull(requests);
            }