Skip to content

Commit 58c4e6d

Browse files
authored
Merge branch '2.0-.Net-Core' into 2.0-Patch
2 parents 5e15416 + dde0cdb commit 58c4e6d

File tree

8 files changed

+84
-52
lines changed

8 files changed

+84
-52
lines changed

RedditSharp.sln

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26430.6
4+
VisualStudioVersion = 15.0.27130.2010
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{46584E90-4894-4EB7-A0B9-FDAF29B4AF8B}"
77
ProjectSection(SolutionItems) = preProject
@@ -51,6 +51,9 @@ Global
5151
GlobalSection(SolutionProperties) = preSolution
5252
HideSolutionNode = FALSE
5353
EndGlobalSection
54+
GlobalSection(ExtensibilityGlobals) = postSolution
55+
SolutionGuid = {514A772A-D1DB-4442-8346-DA11C175CF80}
56+
EndGlobalSection
5457
GlobalSection(MonoDevelopProperties) = preSolution
5558
StartupItem = TestRedditSharp\TestRedditSharp.csproj
5659
EndGlobalSection

RedditSharp/AuthProvider.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ public class AuthProvider
1919
private const string OauthGetMeUrl = "https://oauth.reddit.com/api/v1/me";
2020
private const string RevokeUrl = "https://www.reddit.com/api/v1/revoke_token";
2121

22-
/// <summary>
23-
/// OAuth2 token.
24-
/// </summary>
25-
public string OAuthToken { get; set; }
26-
27-
/// <summary>
28-
/// OAuth2 refresh token.
29-
/// </summary>
30-
public string RefreshToken { get; set; }
31-
3222
#pragma warning disable 1591
3323
[Flags]
3424
public enum Scope
@@ -137,9 +127,6 @@ public async Task<string> GetOAuthTokenAsync(string code, bool isRefresh = false
137127
}).ConfigureAwait(false);
138128
if (json["access_token"] != null)
139129
{
140-
if (json["refresh_token"] != null)
141-
RefreshToken = json["refresh_token"].ToString();
142-
OAuthToken = json["access_token"].ToString();
143130
return json["access_token"].ToString();
144131
}
145132
throw new AuthenticationException("Could not log in.");
@@ -173,9 +160,6 @@ public async Task<string> GetOAuthTokenAsync(string username, string password)
173160
}).ConfigureAwait(false);
174161
if (json["access_token"] != null)
175162
{
176-
if (json["refresh_token"] != null)
177-
RefreshToken = json["refresh_token"].ToString();
178-
OAuthToken = json["access_token"].ToString();
179163
return json["access_token"].ToString();
180164
}
181165
throw new AuthenticationException("Could not log in.");

RedditSharp/Listing.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ internal ListingStream(Listing<T> listing)
5151
public IDisposable Subscribe(IObserver<T> observer)
5252
{
5353
if (!_observers.Contains(observer))
54+
{
5455
_observers.Add(observer);
56+
}
57+
5558
return new Unsubscriber(_observers, observer);
5659
}
5760

@@ -85,7 +88,9 @@ public Unsubscriber(ICollection<IObserver<T>> observers,
8588
public void Dispose()
8689
{
8790
if (_observer != null && _observers.Contains(_observer))
91+
{
8892
_observers.Remove(_observer);
93+
}
8994
}
9095

9196
}
@@ -131,7 +136,9 @@ internal Listing(IWebAgent agent, string url, int maxLimit = -1, int limitPerReq
131136
internal static Listing<T> Create(IWebAgent agent, string url, int max, int perRequest)
132137
{
133138
if (max > 0 && max <= perRequest)
139+
{
134140
perRequest = max;
141+
}
135142

136143
return new Listing<T>(agent, url, max, perRequest);
137144
}
@@ -167,7 +174,7 @@ public IAsyncEnumerator<T> GetEnumerator(int limitPerRequest, int maximumLimit =
167174
/// <inheritdoc/>
168175
public IAsyncEnumerator<T> GetEnumerator()
169176
{
170-
return GetEnumerator(LimitPerRequest,MaximumLimit,IsStream);
177+
return GetEnumerator(LimitPerRequest, MaximumLimit, IsStream);
171178
}
172179

173180
/// <summary>
@@ -219,9 +226,13 @@ public ListingEnumerator(Listing<T> listing, int limitPerRequest, int maximumLim
219226
private Task FetchNextPageAsync()
220227
{
221228
if (stream)
229+
{
222230
return PageForwardAsync();
231+
}
223232
else
233+
{
224234
return PageBackAsync();
235+
}
225236
}
226237

227238
string AppendQueryParam(string url, string param, string value) =>
@@ -268,7 +279,10 @@ private async Task PageBackAsync()
268279
var json = await Listing.WebAgent.Get(url).ConfigureAwait(false);
269280
//json = json.Last();
270281
if (json["kind"].ValueOrDefault<string>() != "Listing")
282+
{
271283
throw new FormatException("Reddit responded with an object that is not a listing.");
284+
}
285+
272286
Parse(json);
273287
}
274288

@@ -286,7 +300,10 @@ private async Task PageForwardAsync()
286300
url = AppendCommonParams(url);
287301
var json = await Listing.WebAgent.Get(url).ConfigureAwait(false);
288302
if (json["kind"].ValueOrDefault<string>() != "Listing")
303+
{
289304
throw new FormatException("Reddit responded with an object that is not a listingStream.");
305+
}
306+
290307
Parse(json);
291308
}
292309

@@ -298,7 +315,9 @@ private void Parse(JToken json)
298315
for (int i = 0; i < children.Count; i++)
299316
{
300317
if (!stream)
318+
{
301319
things.Add(Thing.Parse<T>(Listing.WebAgent, children[i]));
320+
}
302321
else
303322
{
304323
var kind = children[i]["kind"].ValueOrDefault<string>();
@@ -312,15 +331,19 @@ private void Parse(JToken json)
312331
{
313332
var replyId = reply["data"]["id"].ValueOrDefault<string>();
314333
if (done.Contains(replyId))
334+
{
315335
continue;
336+
}
316337

317338
things.Add(Thing.Parse<T>(Listing.WebAgent, reply));
318339
done.Add(replyId);
319340
}
320341
}
321342

322343
if (String.IsNullOrEmpty(id) || done.Contains(id))
344+
{
323345
continue;
346+
}
324347

325348
things.Add(Thing.Parse<T>(Listing.WebAgent, children[i]));
326349
done.Add(id);
@@ -329,7 +352,9 @@ private void Parse(JToken json)
329352

330353
// this doesn't really work when we're processing messages with replies.
331354
if (stream)
355+
{
332356
things.Reverse();
357+
}
333358

334359
CurrentPage = new ReadOnlyCollection<T>(things);
335360
// Increase the total count of items returned
@@ -405,7 +430,9 @@ private async Task<bool> MoveNextForwardAsync(CancellationToken cancellationToke
405430
tries++;
406431

407432
if (MaximumLimit != -1 && Count >= MaximumLimit)
433+
{
408434
return false;
435+
}
409436

410437
try
411438
{
@@ -420,7 +447,9 @@ private async Task<bool> MoveNextForwardAsync(CancellationToken cancellationToke
420447

421448
// the page is only populated if there are *new* items to yielded from the listing.
422449
if (CurrentPage.Count > 0)
450+
{
423451
break;
452+
}
424453

425454
// No listings were returned in the page.
426455
await Sleep(tries, cancellationToken).ConfigureAwait(false);
@@ -439,7 +468,9 @@ private async Task Sleep(int tries, CancellationToken cancellationToken, Excepti
439468
if (tries > 36)
440469
{
441470
if (ex != null)
471+
{
442472
throw ex;
473+
}
443474
}
444475
else
445476
{

RedditSharp/Polyfills/Serializable.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

RedditSharp/Reddit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public Listing<Post> AdvancedSearch(Expression<Func<AdvancedSearchFilter, bool>>
403403
string sort = sortE.ToString().ToLower();
404404
string time = timeE.ToString().ToLower();
405405
string final = string.Format(SearchUrl, query, sort, time);
406-
return new Listing<Post>(this,final,WebAgent);
406+
return new Listing<Post>(WebAgent, final);
407407
}
408408

409409
/// <summary>

RedditSharp/RedditSharp.csproj

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,24 @@
33
<PropertyGroup>
44
<AssemblyTitle>RedditSharp</AssemblyTitle>
55
<VersionPrefix>2.0.0</VersionPrefix>
6-
<TargetFrameworks>netstandard1.3</TargetFrameworks>
6+
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">net462;netstandard1.3;netstandard2.0;</TargetFrameworks>
7+
<TargetFrameworks Condition="'$(LibraryFrameworks)'!=''">$(LibraryFrameworks)</TargetFrameworks>
78
<AssemblyName>RedditSharp</AssemblyName>
89
<PackageId>RedditSharp</PackageId>
910
<PackageProjectUrl>https://github.com/CrustyJew/RedditSharp</PackageProjectUrl>
10-
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'net462' ">$(PackageTargetFallback);dnx462</PackageTargetFallback>
11-
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.3' ">$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
12-
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.6' ">$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
1311
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1412
</PropertyGroup>
1513

16-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard1.6|AnyCPU'">
17-
<DocumentationFile>bin\Debug\netstandard1.3\RedditSharp.xml</DocumentationFile>
18-
<DefineConstants>TRACE;DEBUG;NETSTANDARD1_3</DefineConstants>
19-
<OutputPath>bin\Debug\netstandard1.3\</OutputPath>
20-
</PropertyGroup>
21-
2214
<ItemGroup>
2315
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="1.1.1" />
24-
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
25-
<PackageReference Include="System.Net.Http" Version="4.3.2" />
26-
<PackageReference Include="System.Net.Security" Version="4.3.1" />
27-
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.1.0" />
28-
<PackageReference Include="System.Threading.Thread" Version="4.0.0" />
16+
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
17+
<PackageReference Include="System.Net.Http" Version="4.3.3" />
18+
<PackageReference Include="System.Net.Security" Version="4.3.2" />
19+
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
20+
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
21+
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
2922
<PackageReference Include="System.Reactive.Linq" Version="3.1.1" />
30-
<PackageReference Include="System.Interactive.Async" Version="3.1.0" />
23+
<PackageReference Include="System.Interactive.Async" Version="3.1.1" />
3124
</ItemGroup>
3225

3326
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">

0 commit comments

Comments
 (0)