Skip to content
This repository has been archived by the owner. It is now read-only.

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

Merged
merged 4 commits into from Mar 6, 2014

Conversation

@Sharparam
Copy link
Contributor

commented Mar 5, 2014

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)

This comment has been minimized.

Copy link
@ddevault

ddevault Mar 5, 2014

Owner

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

This comment has been minimized.

Copy link
@Sharparam

Sharparam Mar 5, 2014

Author Contributor

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 :)

This comment has been minimized.

Copy link
@ddevault

ddevault Mar 5, 2014

Owner

Oh whoops, my bad.


public string captcha;
}
}

This comment has been minimized.

Copy link
@ddevault

ddevault Mar 5, 2014

Owner

Use sensible, .NET names here, and then make an attribute that maps them to post values. Or use the anonymous type method we've been using so far.

This comment has been minimized.

Copy link
@Sharparam

Sharparam Mar 5, 2014

Author Contributor

Is there existing functionality (in RedditSharp or elsewhere) to do this conversion?

This comment has been minimized.

Copy link
@ddevault

ddevault Mar 5, 2014

Owner

Nope. So far, everything has used anonymous types for this purpose. I might be convinced to leave this in if it were an internal class, but it's marked as public here.

This comment has been minimized.

Copy link
@Sharparam

Sharparam Mar 5, 2014

Author Contributor

Hm, it's never really exposed, and it can't be provided to any public methods, so it should probably be internal anyway.

@ddevault

This comment has been minimized.

Copy link
Owner

commented Mar 5, 2014

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

@Sharparam

This comment has been minimized.

Copy link
Contributor Author

commented Mar 5, 2014

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

This comment has been minimized.

Copy link
Owner

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

This comment has been minimized.

Copy link
Contributor Author

commented Mar 5, 2014

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

This comment has been minimized.

Copy link
Owner

commented Mar 5, 2014

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

@JosephDomenici

This comment has been minimized.

Copy link

commented Mar 6, 2014

@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

This comment has been minimized.

Copy link
Contributor Author

commented Mar 6, 2014

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

This comment has been minimized.

Copy link
Contributor Author

commented Mar 6, 2014

@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

This comment has been minimized.

Copy link
Owner

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

This comment has been minimized.

Copy link
Contributor Author

commented Mar 6, 2014

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

This comment has been minimized.

Copy link

commented Mar 6, 2014

@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

This comment has been minimized.

Copy link
Contributor Author

commented Mar 6, 2014

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

This comment has been minimized.

Copy link

commented Mar 6, 2014

@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

This comment has been minimized.

Copy link

commented Mar 6, 2014

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 Sharparam:patch-4 branch Mar 7, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.