Skip to content

Commit de648ab

Browse files
committed
Merge pull request #169 from RobThree/upstream
* Even when specifying useSsl in the Reddit(username, password, useSs…
2 parents 04a48ea + a0b55eb commit de648ab

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

RedditSharp/Reddit.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,31 +86,37 @@ public Subreddit RSlashAll
8686
}
8787

8888
public Reddit()
89+
: this(true) { }
90+
91+
public Reddit(bool useSsl)
8992
{
9093
JsonSerializerSettings = new JsonSerializerSettings
9194
{
9295
CheckAdditionalContent = false,
9396
DefaultValueHandling = DefaultValueHandling.Ignore
9497
};
98+
WebAgent.Protocol = useSsl ? "https" : "http";
9599
_webAgent = new WebAgent();
96100
CaptchaSolver = new ConsoleCaptchaSolver();
97101
}
98102

99-
public Reddit(WebAgent.RateLimitMode limitMode) : this()
103+
public Reddit(WebAgent.RateLimitMode limitMode, bool useSsl = true)
104+
: this(useSsl)
100105
{
101106
WebAgent.UserAgent = "";
102107
WebAgent.RateLimit = limitMode;
103108
WebAgent.RootDomain = "www.reddit.com";
104109
}
105110

106-
public Reddit(string username, string password, bool useSsl = true) : this()
111+
public Reddit(string username, string password, bool useSsl = true)
112+
: this(useSsl)
107113
{
108114
LogIn(username, password, useSsl);
109115
}
110116

111-
public Reddit(string accessToken) : this()
117+
public Reddit(string accessToken)
118+
: this(true)
112119
{
113-
WebAgent.Protocol = "https";
114120
WebAgent.RootDomain = OAuthDomainUrl;
115121
_webAgent.AccessToken = accessToken;
116122
InitOrUpdateUser();
@@ -218,7 +224,7 @@ public async Task<Subreddit> GetSubredditAsync(string name)
218224
name = name.Substring(2);
219225
if (name.StartsWith("/r/"))
220226
name = name.Substring(3);
221-
return await GetThingAsync<Subreddit>(string.Format(SubredditAboutUrl, name));
227+
return await GetThingAsync<Subreddit>(string.Format(SubredditAboutUrl, name));
222228
}
223229

224230
public Domain GetDomain(string domain)
@@ -339,7 +345,7 @@ public Comment GetComment(Uri uri)
339345
var response = request.GetResponse();
340346
var data = _webAgent.GetResponseString(response.GetResponseStream());
341347
var json = JToken.Parse(data);
342-
348+
343349
var sender = new Post().Init(this, json[0]["data"]["children"][0], _webAgent);
344350
return new Comment().Init(this, json[1]["data"]["children"][0], _webAgent, sender);
345351
}
@@ -357,13 +363,13 @@ public Listing<T> Search<T>(string query) where T : Thing
357363

358364
#region Helpers
359365

360-
protected async internal Task<T> GetThingAsync<T>(string url) where T : Thing
366+
protected async internal Task<T> GetThingAsync<T>(string url) where T : Thing
361367
{
362368
var request = _webAgent.CreateGet(url);
363369
var response = request.GetResponse();
364370
var data = _webAgent.GetResponseString(response.GetResponseStream());
365371
var json = JToken.Parse(data);
366-
var ret = await Thing.ParseAsync(this, json, _webAgent);
372+
var ret = await Thing.ParseAsync(this, json, _webAgent);
367373
return (T)ret;
368374
}
369375

0 commit comments

Comments
 (0)