<commit_before>h1. Reddit PHP SDK

The Reddit SDK is a wrapper around the Reddit OAuth 2 API: http://www.reddit.com/dev/api/oauth

h2. Initiating Your Login Session

Before making requests to any of the methods of the Reddit SDK, you first need to instantiate a new OAuth 2 session by using your client id and client secret.  You may obtain these keys by creating a new app at https://ssl.reddit.com/prefs/apps and posting the key and secret into the appropriate sections in config.php.
<notextile>
<pre>
require_once("reddit.php");
$reddit = new reddit();
</pre>
</notextile>

h2. How to Build the Fullname Parameters

Frequently within these SDK methods, you will see parameters that reference the fullname or id of a message, comment, account, etc (e.g. values like t4_1kuinv).  The Reddit API uses identifiers that consist of a prefix to identify the type of the fullname (e.g. t3_ or t4_), and the identifier of that thing (e.g. 1kuinv).  To build a fullname of a thing, you must take its id, and add the prefix to the front.

The following is a list of prefixes that the Reddit API uses, and the type of thing that they reference:
* t1_ : Comment
* t2_ : Account
* t3_ : Link
* t4_ : Message
* t5_ : Subreddit
* t6_ : Award
* t8_ : PromoCampaign

h2. SDK Methods

Once you are authenticated, you may then make requests to any of the methods in the SDK.

*Needs CAPTCHA*
Checks whether CAPTCHAs are needed for API endpoints
@link http://www.reddit.com/dev/api/oauth#GET_api_needs_captcha.json
<notextile>
<pre>
$response = $reddit->getCaptchaReqs();
</pre>
</notextile>

*Get New CAPTCHA*
Gets the iden of a new CAPTCHA, if the user cannot read the current one
@link http://www.reddit.com/dev/api/oauth#POST_api_new_captcha
<notextile>
<pre>
$response = $reddit->getNewCaptcha();
$iden = $response->json->data->iden;
</pre>
</notextile>

*Get CAPTCHA Image*
Fetches a new CAPTCHA image from a given iden value
@link http://www.reddit.com/dev/api/oauth#GET_captcha_{iden}
@param string $iden The iden value of a new CAPTCHA from getNewCaptcha method
<notextile>
<pre>
$response = $reddit->getNewCaptcha();
$iden = $response->json->data->iden;
$image = $reddit->getCaptchaImg($iden);

//create and display image from stream
$im = imagecreatefromstring($image);
if ($im !== false) {
    header('Content-Type: image/png');
    imagepng($im);
    imagedestroy($im);
}
else {
    echo 'An error occurred.';
}
</pre>
</notextile>

*Creating a New Story*
Creates a new story on a particular subreddit
@link http://www.reddit.com/dev/api/oauth#POST_api_submit
@param string $title The title of the story
@param string $link The link that the story should forward to
@param string $subreddit The subreddit where the story should be added
<notextile>
<pre>
$title = "MakerBot Releases IPad App For Easy 3D Printing";
$link = "http://makezine.com/2014/07/01/makerbot-realeases-ipad-app-for-easy-3d-printing/";
$subreddit = "technology";
$response = $reddit->createStory($title, $link, $subreddit);
</pre>
</notextile>

*Get User Information*
Get data for the current user
@link http://www.reddit.com/dev/api#GET_api_v1_me
<notextile>
<pre>
$userData = $reddit->getUser();
</pre>
</notextile><commit_msg>README content adjust<commit_after>h1. Reddit PHP SDK

The Reddit SDK is a wrapper around the Reddit OAuth 2 API: http://www.reddit.com/dev/api/oauth

h2. Initiating Your Login Session

Before making requests to any of the methods of the Reddit SDK, you first need to instantiate a new OAuth 2 session by using your client id and client secret.  You may obtain these keys by creating a new app at https://ssl.reddit.com/prefs/apps and posting the key and secret into the appropriate sections in config.php.
<notextile>
<pre>
require_once("reddit.php");
$reddit = new reddit();
</pre>
</notextile>

h2. How to Build the Fullname Parameters

Frequently within these SDK methods, you will see parameters that reference the fullname or id of a message, comment, account, etc (e.g. values like t4_1kuinv).  The Reddit API uses identifiers that consist of a prefix to identify the type of the fullname (e.g. t3_ or t4_), and the identifier of that thing (e.g. 1kuinv).  To build a fullname of a thing, you must take its id, and add the prefix to the front.

The following is a list of prefixes that the Reddit API uses, and the type of thing that they reference:
* t1_ : Comment
* t2_ : Account
* t3_ : Link
* t4_ : Message
* t5_ : Subreddit
* t6_ : Award
* t8_ : PromoCampaign

h2. SDK Methods

Once you are authenticated, you may then make requests to any of the methods in the SDK.

*Needs CAPTCHA*
Checks whether CAPTCHAs are needed for API endpoints
@link http://www.reddit.com/dev/api/oauth#GET_api_needs_captcha.json
<notextile>
<pre>
$response = $reddit->getCaptchaReqs();
</pre>
</notextile>

*Get New CAPTCHA*
Gets the iden of a new CAPTCHA, if the user cannot read the current one
@link http://www.reddit.com/dev/api/oauth#POST_api_new_captcha
<notextile>
<pre>
$response = $reddit->getNewCaptcha();
$iden = $response->json->data->iden;
</pre>
</notextile>

*Get CAPTCHA Image*
Fetches a new CAPTCHA image from a given iden value
@link http://www.reddit.com/dev/api/oauth#GET_captcha_{iden}
@param string $iden The iden value of a new CAPTCHA from getNewCaptcha method
<notextile>
<pre>
$response = $reddit->getNewCaptcha();
$iden = $response->json->data->iden;
$image = $reddit->getCaptchaImg($iden);

$im = imagecreatefromstring($image);
if ($im !== false){
    header('Content-Type: image/png');
    imagepng($im);
    imagedestroy($im);
} else {
    echo 'An error occurred';
}
</pre>
</notextile>

*Creating a New Story*
Creates a new story on a particular subreddit
@link http://www.reddit.com/dev/api/oauth#POST_api_submit
@param string $title The title of the story
@param string $link The link that the story should forward to
@param string $subreddit The subreddit where the story should be added
<notextile>
<pre>
$title = "MakerBot Releases IPad App For Easy 3D Printing";
$link = "http://makezine.com/2014/07/01/makerbot-realeases-ipad-app-for-easy-3d-printing/";
$subreddit = "technology";
$response = $reddit->createStory($title, $link, $subreddit);
</pre>
</notextile>

*Get User Information*
Get data for the current user
@link http://www.reddit.com/dev/api#GET_api_v1_me
<notextile>
<pre>
$userData = $reddit->getUser();
</pre>
</notextile>
{'fraction_non_alphanumeric': 0.11023745871992452, 'fraction_numerical': 0.009120930963988048, 'mean_word_length': 4.535248041775457, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 75, 'https://': 2, 'lorem ipsum': 0, 'www.': 12, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4174880', 'n_tokens_mistral': 2170, 'n_tokens_neox': 2125, 'n_words': 805}