1
1
using Newtonsoft . Json ;
2
2
using Newtonsoft . Json . Linq ;
3
+ using RedditSharp . Things . User ;
3
4
using System ;
4
5
using System . Threading . Tasks ;
5
6
@@ -8,7 +9,7 @@ namespace RedditSharp.Things
8
9
/// <summary>
9
10
/// A reddit user.
10
11
/// </summary>
11
- public class RedditUser : CreatedThing
12
+ public class RedditUser : PartialUser
12
13
{
13
14
/// <inheritdoc />
14
15
public RedditUser ( IWebAgent agent , JToken json ) : base ( agent , json )
@@ -30,10 +31,13 @@ public RedditUser(IWebAgent agent, JToken json) : base(agent, json)
30
31
internal override JToken GetJsonData ( JToken json ) => json [ "name" ] == null ? json [ "data" ] : json ;
31
32
32
33
/// <summary>
33
- /// Reddit username.
34
+ /// This method returns itself as the full <see cref="RedditUser"/> is
35
+ /// already initalized so no more further initialization needs to
36
+ /// be done.
34
37
/// </summary>
35
- [ JsonProperty ( "name" ) ]
36
- public string Name { get ; internal set ; }
38
+ /// <returns>This same <see cref="RedditUser"/>.</returns>
39
+ /// <seealso cref="PartialUser.GetFullUserAsync"/>
40
+ public override Task < RedditUser > GetFullUserAsync ( ) => Task . FromResult ( this ) ;
37
41
38
42
/// <summary>
39
43
/// Returns true if the user has reddit gold.
@@ -106,43 +110,8 @@ public RedditUser(IWebAgent agent, JToken json) : base(agent, json)
106
110
[ JsonProperty ( "pref_show_snoovatar" ) ]
107
111
public bool ShowSnoovatar { get ; private set ; }
108
112
109
- /// <summary>
110
- /// Prefix for fullname. Includes trailing underscore
111
- /// </summary>
112
- public static string KindPrefix { get { return "t2_" ; } }
113
-
114
113
#endregion
115
114
116
- /// <summary>
117
- /// Return the users overview.
118
- /// </summary>
119
- public Listing < VotableThing > GetOverview ( int max = - 1 ) => Listing < VotableThing > . Create ( WebAgent , OverviewUrl , max , 100 ) ;
120
-
121
- /// <summary>
122
- /// Return a <see cref="Listing{T}"/> of posts liked by the logged in user.
123
- /// </summary>
124
- public Listing < Post > GetLikedPosts ( int max = - 1 ) => Listing < Post > . Create ( WebAgent , LikedUrl , max , 100 ) ;
125
-
126
- /// <summary>
127
- /// Return a <see cref="Listing{T}"/> of posts disliked by the logged in user.
128
- /// </summary>
129
- public Listing < Post > GetDislikedPosts ( int max = - 1 ) => Listing < Post > . Create ( WebAgent , DislikedUrl , max , 100 ) ;
130
-
131
- /// <summary>
132
- /// Return a <see cref="Listing{T}"/> of comments made by the user.
133
- /// </summary>
134
- public Listing < Comment > GetComments ( int max = - 1 ) => Listing < Comment > . Create ( WebAgent , CommentsUrl , max , 100 ) ;
135
-
136
- /// <summary>
137
- /// Return a <see cref="Listing{T}"/> of posts made by the user.
138
- /// </summary>
139
- public Listing < Post > GetPosts ( int max = - 1 ) => Listing < Post > . Create ( WebAgent , LinksUrl , max , 100 ) ;
140
-
141
- /// <summary>
142
- /// Return a list of subscribed subreddits for the logged in user.
143
- /// </summary>
144
- public Listing < Subreddit > GetSubscribedSubreddits ( int max = - 1 ) => Listing < Subreddit > . Create ( WebAgent , SubscribedSubredditsUrl , max , 100 ) ;
145
-
146
115
static string QueryString ( Sort sort , int limit , FromTime time ) =>
147
116
$ "?sort={ sort . ToString ( "g" ) } &limit={ limit } &t={ time . ToString ( "g" ) } ";
148
117
@@ -151,77 +120,6 @@ static void CheckRange(int limit, int max_limit)
151
120
if ( ( limit < 1 ) || ( limit > max_limit ) )
152
121
throw new ArgumentOutOfRangeException ( nameof ( limit ) , $ "Valid range: [1, { max_limit } ]") ;
153
122
}
154
- /// <summary>
155
- /// Returns a <see cref="RedditUser"/> by username
156
- /// </summary>
157
- /// <param name="agent">WebAgent to perform search</param>
158
- /// <param name="username">Username of user to return</param>
159
- /// <returns></returns>
160
- public static async Task < RedditUser > GetUserAsync ( IWebAgent agent , string username )
161
- {
162
- var json = await agent . Get ( string . Format ( UserInfoUrl , username ) ) . ConfigureAwait ( false ) ;
163
- return new RedditUser ( agent , json ) ;
164
- }
165
-
166
- /// <summary>
167
- /// Get a listing of comments and posts from the user sorted by <paramref name="sorting"/>, from time <paramref name="fromTime"/>
168
- /// and limited to <paramref name="limit"/>.
169
- /// </summary>
170
- /// <param name="sorting">How to sort the comments (hot, new, top, controversial).</param>
171
- /// <param name="limit">How many comments to fetch per request. Max is 100.</param>
172
- /// <param name="fromTime">What time frame of comments to show (hour, day, week, month, year, all).</param>
173
- /// <returns>The listing of comments requested.</returns>
174
- public Listing < VotableThing > GetOverview ( Sort sorting = Sort . New , int limit = 25 , FromTime fromTime = FromTime . All )
175
- {
176
- CheckRange ( limit , MAX_LIMIT ) ;
177
- string overviewUrl = OverviewUrl + QueryString ( sorting , limit , fromTime ) ;
178
- return new Listing < VotableThing > ( WebAgent , overviewUrl ) ;
179
- }
180
-
181
- /// <summary>
182
- /// Get a listing of comments from the user sorted by <paramref name="sorting"/>, from time <paramref name="fromTime"/>
183
- /// and limited to <paramref name="limit"/>.
184
- /// </summary>
185
- /// <param name="sorting">How to sort the comments (hot, new, top, controversial).</param>
186
- /// <param name="limit">How many comments to fetch per request. Max is 100.</param>
187
- /// <param name="fromTime">What time frame of comments to show (hour, day, week, month, year, all).</param>
188
- /// <returns>The listing of comments requested.</returns>
189
- public Listing < Comment > GetComments ( Sort sorting = Sort . New , int limit = 25 , FromTime fromTime = FromTime . All )
190
- {
191
- CheckRange ( limit , MAX_LIMIT ) ;
192
- string commentsUrl = CommentsUrl + QueryString ( sorting , limit , fromTime ) ;
193
- return new Listing < Comment > ( WebAgent , commentsUrl ) ;
194
- }
195
-
196
- /// <summary>
197
- /// Get a listing of posts from the user sorted by <paramref name="sorting"/>, from time <paramref name="fromTime"/>
198
- /// and limited to <paramref name="limit"/>.
199
- /// </summary>
200
- /// <param name="sorting">How to sort the posts (hot, new, top, controversial).</param>
201
- /// <param name="limit">How many posts to fetch per request. Max is 100.</param>
202
- /// <param name="fromTime">What time frame of posts to show (hour, day, week, month, year, all).</param>
203
- /// <returns>The listing of posts requested.</returns>
204
- public Listing < Post > GetPosts ( Sort sorting = Sort . New , int limit = 25 , FromTime fromTime = FromTime . All )
205
- {
206
- CheckRange ( limit , 100 ) ;
207
- string linksUrl = LinksUrl + QueryString ( sorting , limit , fromTime ) ;
208
- return new Listing < Post > ( WebAgent , linksUrl ) ;
209
- }
210
-
211
- /// <summary>
212
- /// Get a listing of comments and posts saved by the user sorted by <paramref name="sorting"/>, from time <paramref name="fromTime"/>
213
- /// and limited to <paramref name="limit"/>.
214
- /// </summary>
215
- /// <param name="sorting">How to sort the comments (hot, new, top, controversial).</param>
216
- /// <param name="limit">How many comments to fetch per request. Max is 100.</param>
217
- /// <param name="fromTime">What time frame of comments to show (hour, day, week, month, year, all).</param>
218
- /// <returns>The listing of posts and/or comments requested that the user saved.</returns>
219
- public Listing < VotableThing > GetSaved ( Sort sorting = Sort . New , int limit = 25 , FromTime fromTime = FromTime . All )
220
- {
221
- CheckRange ( limit , 100 ) ;
222
- string savedUrl = SavedUrl + QueryString ( sorting , limit , fromTime ) ;
223
- return new Listing < VotableThing > ( WebAgent , savedUrl ) ;
224
- }
225
123
226
124
/// <inheritdoc/>
227
125
public override string ToString ( ) => Name ;
0 commit comments