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

https://github.com/svick/stacky · C# · 141 lines · 123 code · 18 blank · 0 comment · 0 complexity · 9b07d0e47b0bef72292ec1f6c1a05ece MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Stacky
  5. {
  6. #if SILVERLIGHT
  7. public partial class StackyClient
  8. #else
  9. public partial class StackyClientAsync
  10. #endif
  11. {
  12. private void GetUsers(Action<IPagedList<User>> onSuccess, Action<ApiException> onError, string[] urlParameters, UserOptions options)
  13. {
  14. MakeRequest<UserResponse>("users", urlParameters, new
  15. {
  16. key = apiKey,
  17. page = options.Page ?? null,
  18. pagesize = options.PageSize ?? null,
  19. filter = options.Filter,
  20. sort = options.SortBy.ToString().ToLower(),
  21. order = GetSortDirection(options.SortDirection),
  22. fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
  23. todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
  24. min = options.Min ?? null,
  25. max = options.Max ?? null
  26. }, (items) => onSuccess(new PagedList<User>(items.Users, items)), onError);
  27. }
  28. public virtual void GetUsers(Action<IPagedList<User>> onSuccess, Action<ApiException> onError)
  29. {
  30. GetUsers(onSuccess, onError, new UserOptions());
  31. }
  32. public virtual void GetUsers(Action<IPagedList<User>> onSuccess, Action<ApiException> onError, UserOptions options)
  33. {
  34. GetUsers(onSuccess, onError, null, options);
  35. }
  36. public virtual void GetUsers(IEnumerable<int> userIds, Action<IPagedList<User>> onSuccess, Action<ApiException> onError)
  37. {
  38. GetUsers(userIds, onSuccess, onError, new UserOptions());
  39. }
  40. public virtual void GetUsers(IEnumerable<int> userIds, Action<IPagedList<User>> onSuccess, Action<ApiException> onError, UserOptions options)
  41. {
  42. GetUsers(onSuccess, onError, new string[] { userIds.Vectorize() }, options);
  43. }
  44. public virtual void GetUser(int userId, Action<User> onSuccess, Action<ApiException> onError)
  45. {
  46. GetUsers(new int[] { userId }, results => onSuccess(results.FirstOrDefault()), onError, new UserOptions());
  47. }
  48. public virtual void GetUserMentions(int userId, Action<IPagedList<Comment>> onSuccess, Action<ApiException> onError)
  49. {
  50. GetUserMentions(userId, onSuccess, onError, new UserOptions());
  51. }
  52. public virtual void GetUserMentions(int userId, Action<IPagedList<Comment>> onSuccess, Action<ApiException> onError, UserOptions options)
  53. {
  54. GetUserMentions(new int[] { userId }, onSuccess, onError, options);
  55. }
  56. public virtual void GetUserMentions(IEnumerable<int> userIds, Action<IPagedList<Comment>> onSuccess, Action<ApiException> onError)
  57. {
  58. GetUserMentions(userIds, onSuccess, onError, new UserOptions());
  59. }
  60. public virtual void GetUserMentions(IEnumerable<int> userIds, Action<IPagedList<Comment>> onSuccess, Action<ApiException> onError, UserOptions options)
  61. {
  62. MakeRequest<CommentResponse>("users", new string[] { userIds.Vectorize(), "mentioned" }, new
  63. {
  64. key = apiKey,
  65. page = options.Page ?? null,
  66. pagesize = options.PageSize ?? null,
  67. filter = options.Filter,
  68. sort = options.SortBy.ToString().ToLower(),
  69. order = GetSortDirection(options.SortDirection),
  70. fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
  71. todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
  72. min = options.Min ?? null,
  73. max = options.Max ?? null
  74. }, (items) => onSuccess(new PagedList<Comment>(items.Comments, items)), onError);
  75. }
  76. public virtual void GetUserTimeline(int userId, Action<IPagedList<UserEvent>> onSuccess, Action<ApiException> onError)
  77. {
  78. GetUserTimeline(userId, onSuccess, onError, new UserTimelineOptions());
  79. }
  80. public virtual void GetUserTimeline(int userId, Action<IPagedList<UserEvent>> onSuccess, Action<ApiException> onError, UserTimelineOptions options)
  81. {
  82. GetUserTimeline(new int[] { userId }, onSuccess, onError, options);
  83. }
  84. public virtual void GetUserTimeline(IEnumerable<int> userIds, Action<IPagedList<UserEvent>> onSuccess, Action<ApiException> onError)
  85. {
  86. GetUserTimeline(userIds, onSuccess, onError, new UserTimelineOptions());
  87. }
  88. public virtual void GetUserTimeline(IEnumerable<int> userIds, Action<IPagedList<UserEvent>> onSuccess, Action<ApiException> onError, UserTimelineOptions options)
  89. {
  90. MakeRequest<UserEventResponse>("users", new string[] { userIds.Vectorize(), "timeline" }, new
  91. {
  92. key = apiKey,
  93. fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
  94. todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
  95. page = options.Page ?? null,
  96. pagesize = options.PageSize ?? null
  97. }, (items) => onSuccess(new PagedList<UserEvent>(items.Events, items)), onError);
  98. }
  99. public virtual void GetUserReputation(int userId, Action<IPagedList<Reputation>> onSuccess, Action<ApiException> onError)
  100. {
  101. GetUserReputation(userId, onSuccess, onError, new ReputationOptions());
  102. }
  103. public virtual void GetUserReputation(int userId, Action<IPagedList<Reputation>> onSuccess, Action<ApiException> onError, ReputationOptions options)
  104. {
  105. GetUserReputation(new int[] { userId }, onSuccess, onError, options);
  106. }
  107. public virtual void GetUserReputation(IEnumerable<int> userIds, Action<IPagedList<Reputation>> onSuccess, Action<ApiException> onError)
  108. {
  109. GetUserReputation(userIds, onSuccess, onError, new ReputationOptions());
  110. }
  111. public virtual void GetUserReputation(IEnumerable<int> userIds, Action<IPagedList<Reputation>> onSuccess, Action<ApiException> onError, ReputationOptions options)
  112. {
  113. MakeRequest<ReputationResponse>("users", new string[] { userIds.Vectorize(), "reputation" }, new
  114. {
  115. key = apiKey,
  116. fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
  117. todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
  118. page = options.Page ?? null,
  119. pagesize = options.PageSize ?? null
  120. }, (items) => onSuccess(new PagedList<Reputation>(items.Reputation, items)), onError);
  121. }
  122. }
  123. }