stacky / trunk / source / Stacky.Net35 / StackyClientAsync / UserMethods.cs

using System;
using System.Collections.Generic;
using System.Linq;

namespace Stacky
{
#if SILVERLIGHT
    public partial class StackyClient
#else
    public partial class StackyClientAsync
#endif
    {
        private void GetUsers(Action<IPagedList<User>> onSuccess, Action<ApiException> onError, string[] urlParameters, UserOptions options)
        {
            MakeRequest<User>("users", urlParameters, new
            {
                site = this.SiteUrlName,
                page = options.Page ?? null,
                pagesize = options.PageSize ?? null,
                filter = options.Filter,
                sort = options.SortBy.ToString().ToLower(),
                order = GetSortDirection(options.SortDirection),
                fromdate = GetDateValue(options.FromDate),
                todate = GetDateValue(options.ToDate),
                min = options.Min ?? null,
                max = options.Max ?? null
            }, (items) => onSuccess(new PagedList<User>(items)), onError);
        }

        public virtual void GetUsers(Action<IPagedList<User>> onSuccess, Action<ApiException> onError)
        {
            GetUsers(onSuccess, onError, new UserOptions());
        }

        public virtual void GetUsers(Action<IPagedList<User>> onSuccess, Action<ApiException> onError, UserOptions options)
        {
            GetUsers(onSuccess, onError, null, options);
        }

        public virtual void GetUsers(IEnumerable<int> userIds, Action<IPagedList<User>> onSuccess, Action<ApiException> onError)
        {
            GetUsers(userIds, onSuccess, onError, new UserOptions());
        }

        public virtual void GetUsers(IEnumerable<int> userIds, Action<IPagedList<User>> onSuccess, Action<ApiException> onError, UserOptions options)
        {
            GetUsers(onSuccess, onError, new string[] { userIds.Vectorize() }, options);
        }

        public virtual void GetUser(int userId, Action<User> onSuccess, Action<ApiException> onError)
        {
            GetUsers(new int[] { userId }, results => onSuccess(results.FirstOrDefault()), onError, new UserOptions());
        }

        public virtual void GetUserMentions(int userId, Action<IPagedList<Comment>> onSuccess, Action<ApiException> onError)
        {
            GetUserMentions(userId, onSuccess, onError, new UserOptions());
        }

        public virtual void GetUserMentions(int userId, Action<IPagedList<Comment>> onSuccess, Action<ApiException> onError, UserOptions options)
        {
            GetUserMentions(new int[] { userId }, onSuccess, onError, options);
        }

        public virtual void GetUserMentions(IEnumerable<int> userIds, Action<IPagedList<Comment>> onSuccess, Action<ApiException> onError)
        {
            GetUserMentions(userIds, onSuccess, onError, new UserOptions());
        }

        public virtual void GetUserMentions(IEnumerable<int> userIds, Action<IPagedList<Comment>> onSuccess, Action<ApiException> onError, UserOptions options)
        {
            MakeRequest<Comment>("users", new string[] { userIds.Vectorize(), "mentioned" }, new
            {
                site = this.SiteUrlName,
                page = options.Page ?? null,
                pagesize = options.PageSize ?? null,
                filter = options.Filter,
                sort = options.SortBy.ToString().ToLower(),
                order = GetSortDirection(options.SortDirection),
                fromdate = GetDateValue(options.FromDate),
                todate = GetDateValue(options.ToDate),
                min = options.Min ?? null,
                max = options.Max ?? null
            }, (items) => onSuccess(new PagedList<Comment>(items)), onError);
        }

        public virtual void GetUserTimeline(int userId, Action<IPagedList<UserEvent>> onSuccess, Action<ApiException> onError)
        {
            GetUserTimeline(userId, onSuccess, onError, new UserTimelineOptions());
        }

        public virtual void GetUserTimeline(int userId, Action<IPagedList<UserEvent>> onSuccess, Action<ApiException> onError, UserTimelineOptions options)
        {
            GetUserTimeline(new int[] { userId }, onSuccess, onError, options);
        }

        public virtual void GetUserTimeline(IEnumerable<int> userIds, Action<IPagedList<UserEvent>> onSuccess, Action<ApiException> onError)
        {
            GetUserTimeline(userIds, onSuccess, onError, new UserTimelineOptions());
        }

        public virtual void GetUserTimeline(IEnumerable<int> userIds, Action<IPagedList<UserEvent>> onSuccess, Action<ApiException> onError, UserTimelineOptions options)
        {
            MakeRequest<UserEvent>("users", new string[] { userIds.Vectorize(), "timeline" }, new
            {
                site = this.SiteUrlName,
                fromdate = GetDateValue(options.FromDate),
                todate = GetDateValue(options.ToDate),
                page = options.Page ?? null,
                pagesize = options.PageSize ?? null
            }, (items) => onSuccess(new PagedList<UserEvent>(items)), onError);
        }

        public virtual void GetUserReputation(int userId, Action<IPagedList<Reputation>> onSuccess, Action<ApiException> onError)
        {
            GetUserReputation(userId, onSuccess, onError, new ReputationOptions());
        }

        public virtual void GetUserReputation(int userId, Action<IPagedList<Reputation>> onSuccess, Action<ApiException> onError, ReputationOptions options)
        {
            GetUserReputation(new int[] { userId }, onSuccess, onError, options);
        }

        public virtual void GetUserReputation(IEnumerable<int> userIds, Action<IPagedList<Reputation>> onSuccess, Action<ApiException> onError)
        {
            GetUserReputation(userIds, onSuccess, onError, new ReputationOptions());
        }

        public virtual void GetUserReputation(IEnumerable<int> userIds, Action<IPagedList<Reputation>> onSuccess, Action<ApiException> onError, ReputationOptions options)
        {
            MakeRequest<Reputation>("users", new string[] { userIds.Vectorize(), "reputation" }, new
            {
                site = this.SiteUrlName,
                fromdate = GetDateValue(options.FromDate),
                todate = GetDateValue(options.ToDate),
                page = options.Page ?? null,
                pagesize = options.PageSize ?? null
            }, (items) => onSuccess(new PagedList<Reputation>(items)), onError);
        }
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.