Skip to content
This repository has been archived by the owner on Nov 8, 2017. It is now read-only.

Added captcha handling for Subreddit.Submit(Text)Post #64

Merged
merged 4 commits into from Mar 6, 2014
Merged

Added captcha handling for Subreddit.Submit(Text)Post #64

merged 4 commits into from Mar 6, 2014

Conversation

Sharparam
Copy link
Contributor

Untested, if someone could test to make sure this works, that would be great.

Edit: Requested from #45

/// <param name="title">The title of the submission</param>
/// <param name="url">The url of the submission link</param>
public Post SubmitPost(string title, string url)
private Post Submit(SubmitData data)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking API change here! I'd rather not do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below, this is just a wrapper method that posts a request to the reddit API. The normal SubmitPost and SubmitTextPost are still there with the regular signature :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh whoops, my bad.

@ddevault
Copy link
Owner

ddevault commented Mar 5, 2014

Can you implement a default capcha handler that prompts at the console? Also, paging @JosephDomenici for testing.

@Sharparam
Copy link
Contributor Author

Made the data classes internal (for now, at least), since they are only used internally anyway.
And a default captcha handler that gets set when the Reddit object is instantiated. It will simply output captcha id and url to console and ask for a response to be typed in.

@ddevault
Copy link
Owner

ddevault commented Mar 5, 2014

Could you make it output the full URL to the capcha image, instead of just the ID? That should be done at a lower level, the capcha code should offer that URL to any capcha handler.

@Sharparam
Copy link
Contributor Author

It already is, below the line that outputs the ID there is also a line outputting the URL (available as the Url property on the Captcha object.)

@ddevault
Copy link
Owner

ddevault commented Mar 5, 2014

Oh, neato. I'll wait until I've heard from @JosephDomenici and then get this merged.

@JosephDomenici
Copy link

@Sharparam I just tested it and I'm getting a NullReferenceException error. See pic for more information: https://mediacru.sh//KacBqNiH-W0r.png

I'm pretty new, so it's quite possible that I messed something up. I can drop in IRC to help you troubleshoot if you'd like.

@Sharparam
Copy link
Contributor Author

I was able to create a post after the latest commit, I had a different error though. ArgumentOutOfRange on WebAgent.CreatePost due to the properties being internal.

I didn't get a NullReferenceException.

Example of test post created:
Test post with RedditSharp

@Sharparam
Copy link
Contributor Author

@SirCmpwn Would there be a problem with CreatePost including non-public properties in the post data? On reddit's side I don't think it will matter since it most likely ignores data that is not relevant.

@ddevault
Copy link
Owner

ddevault commented Mar 6, 2014

That's probably not a problem. @JosephDomenici, can you share your code so that someone more experienced can take a whack at debugging it?

@Sharparam
Copy link
Contributor Author

And just to have the info here.

Lines 27-35 of Thing.cs (constructor):

/* 27 */ internal Thing(JToken json)
/* 28 */ {
/* 29 */    if (json == null)
/* 30 */        return;
/* 31 */    var data = json["data"];
/* 32 */    FullName = data["name"].ValueOrDefault<string>();
/* 33 */    Id = data["id"].ValueOrDefault<string>();
/* 34 */    Kind = json["kind"].ValueOrDefault<string>();
/* 35 */ }

It seems that json["data"] is null in this case, in order to produce a NullReference on line 32. I think.

Edit: I'm not sure how he got that far though, as the code should have thrown an ArgumentOutOfRangeException way before that point... ?

@JosephDomenici
Copy link

@Sharparam I just dummied up a test program and got a similar error: ArgumentOutOfRange exception on WebAgent.WritePostBody.

@SirCmpwn This is my first time using branches in git and I can't quite figure out how to include @Sharparam's test branch of RedditSharp that I used. Sorry! https://github.com/JosephDomenici/Reddit-Readability-Bot/tree/Testing

@Sharparam
Copy link
Contributor Author

With the latest commit you should no longer be getting ArgumentOutOfRangeException.

To check out the patch-4 branch in this PR. You can do the following on command line:

git remote add sharparam git://github.com/Sharparam/RedditSharp.git
git checkout -b sharparam-patch-4
git pull sharparam patch-4

Now the code in the repo should be updated with the one from this PR.
To switch back to the regular one, use git checkout master.

@JosephDomenici
Copy link

@Sharparam Was having git issues so I just downloaded the .zip. Worked perfectly fine with my dummy test program, and the captcha went flawlessly. Thanks!

Still getting the same NullReferenceException error with my regular program, however. Going to strip it down and see if I can figure out exactly what's causing the issue.

@JosephDomenici
Copy link

My regular program is working now! Turns out I was referencing .dlls from a previous version of RedditSharp. Whoops.

@SirCmpwn, it looks like everything is in order now.

ddevault added a commit that referenced this pull request Mar 6, 2014
Added captcha handling for Subreddit.Submit(Text)Post
@ddevault ddevault merged commit 4ce753c into ddevault:master Mar 6, 2014
@Sharparam Sharparam deleted the patch-4 branch March 7, 2014 01:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants