All Projects → samsymons → Redditkit

samsymons / Redditkit

Licence: mit
An Objective-C wrapper for the reddit API

Projects that are alternatives of or similar to Redditkit

cleverbot
Deprecated/unmaintained. See https://www.cleverbot.com/api/
Stars: ✭ 23 (-92.31%)
Mutual labels:  unmaintained
addon-sdk-content-scripts
DEPRECATED | Use WebExtensions instead | Add-ons demonstrating how to use content scripts in the Add-on SDK.
Stars: ✭ 23 (-92.31%)
Mutual labels:  unmaintained
confidential-survey
A Rails app for conducting confidential surveys without violating user privacy
Stars: ✭ 29 (-90.3%)
Mutual labels:  unmaintained
vinz-clortho
INACTIVE - http://mzl.la/ghe-archive - BrowserID Keymaster for LDAP enabled Identity Providers
Stars: ✭ 16 (-94.65%)
Mutual labels:  unmaintained
id-specs
INACTIVE - http://mzl.la/ghe-archive - Specifications for Mozilla's Identity Effort
Stars: ✭ 91 (-69.57%)
Mutual labels:  unmaintained
rescuefox
DEPRECATED - demo game to drive 3D engine creation: rescue your pet space fox!
Stars: ✭ 35 (-88.29%)
Mutual labels:  unmaintained
calculator
INACTIVE - http://mzl.la/ghe-archive - Resurrection of the calculator app that was pulled from gaia
Stars: ✭ 16 (-94.65%)
Mutual labels:  unmaintained
Mobx Store
A data store with declarative querying, observable state, and easy undo/redo.
Stars: ✭ 283 (-5.35%)
Mutual labels:  unmaintained
Garmr
INACTIVE - Security Testing Tool
Stars: ✭ 105 (-64.88%)
Mutual labels:  unmaintained
coma
a console mail user agent | obsolete: use mblaze
Stars: ✭ 13 (-95.65%)
Mutual labels:  unmaintained
jade-babel
Jade plugin for Babel
Stars: ✭ 39 (-86.96%)
Mutual labels:  unmaintained
rilproxy
DEPRECATED
Stars: ✭ 21 (-92.98%)
Mutual labels:  unmaintained
elmo
DEPRECATED - Elmo ~ https://mozilla.github.io/elmo/
Stars: ✭ 32 (-89.3%)
Mutual labels:  unmaintained
2015-foia-hub
A consolidated FOIA request hub.
Stars: ✭ 47 (-84.28%)
Mutual labels:  unmaintained
Colors Of Image
A PHP Library for getting colors from images DEPRECATED
Stars: ✭ 273 (-8.7%)
Mutual labels:  unmaintained
page-metadata-service
DEPRECATED - A RESTful service that returns the metadata about a given URL.
Stars: ✭ 18 (-93.98%)
Mutual labels:  unmaintained
web-forward
DEPRECATED - Innovation acceleration program from Mozilla Labs
Stars: ✭ 17 (-94.31%)
Mutual labels:  unmaintained
Rust Os Comparison
A comparison of operating systems written in Rust
Stars: ✭ 292 (-2.34%)
Mutual labels:  unmaintained
Wifi
[unmaintained] WiFi tools for linux
Stars: ✭ 281 (-6.02%)
Mutual labels:  unmaintained
reddit-comment-bot
Reddit bot that auto replies to comments on set subreddits
Stars: ✭ 59 (-80.27%)
Mutual labels:  reddit-api

RedditKit Build Status

RedditKit is a reddit API wrapper, written in Objective-C.

Documention

Documentation for RedditKit is available on CocoaDocs.

Installation

CocoaPods

Add this to your Podfile:

pod 'RedditKit', '~> 1.3'

Then run:

pod install

Submodules

Adding RedditKit:

  1. Add RedditKit as a git submodule of your project: git submodule add https://github.com/samsymons/RedditKit.git
  2. Fetch its dependencies with git submodule update --init --recursive

Adding AFNetworking:

Inside the newly created RedditKit directory, there exists an External directory containing its dependencies which the git submodule update command will have populated. Drag AFNetworking's Classes directory into your project.

Adding Mantle:

Follow Mantle's instructions on getting the project set up.

Once you have everything set up, you may need to restart Xcode to have it pick up your changes.

Getting Started

RedditKit is structured around the RKClient class. This class manages authentication for a single reddit account and performs HTTP requests on that user's behalf. RKClient can be used as a singleton with its sharedClient class method, or as a standalone object.

[[RKClient sharedClient] signInWithUsername:@"name" password:@"password" completion:^(NSError *error) {
    if (!error)
    {
        NSLog(@"Successfully signed in!");
    }
}];

Once you're signed in, RKClient will keep track of any necessary authentication state. You can then call methods which require authentication, such as getting the subreddits you are subscribed to.

Note: RedditKit does not persist your authentication credentials itself; you'll have to do this manually via the Keychain, and call signInWithUsername:password:completion: on your application's launch.

[[RKClient sharedClient] subscribedSubredditsWithCompletion:^(NSArray *subreddits, NSError *error) {
    NSLog(@"Subreddits: %@", subreddits);
}];

Retrieving the current top links in a subreddit is simple.

RKSubreddit *subreddit = [[self subreddits] firstObject];

[[RKClient sharedClient] linksInSubreddit:subreddit pagination:nil completion:^(NSArray *links, RKPagination *pagination, NSError *error) {
    NSLog(@"Links: %@", links);
}];

You can then upvote a link.

RKLink *link = [[self links] firstObject];

[[RKClient sharedClient] upvote:link completion:^(NSError *error) {
    NSLog(@"Upvoted the link!");
}];

RedditKit doesn't have any built-in rate limiting. reddit's API rules require that you make no more than 30 requests per minute and try to avoid requesting the same page more than once every 30 seconds. You can read up on the API rules on their wiki page.

More Examples

Get the top comments for a link:

RKLink *link = [[self links] firstObject];

[[RKClient sharedClient] commentsForLink:link completion:^(NSArray *comments, NSError *error) {
	if (comments)
	{
		NSLog(@"Comments: %@", comments);
	}
}];

Fetch a user's account:

[[RKClient sharedClient] userWithUsername:@"name" completion:^(RKUser *account, NSError *error) {
	if (account)
	{
		NSLog(@"%@", account);
	}
}];

Send private messages:

[[RKClient sharedClient] sendMessage:@"Hello!" subject:nil recipient:@"samsymons" completion:nil];

Canceling a request:

Each of RedditKit's methods return a NSURLSessionDataTask, which can be used to cancel a request before it has completed.

NSURLSessionDataTask *task = [[RKClient sharedClient] frontPageLinksWithCompletion:nil];
[task cancel];

When using RedditKit's APIs, it's important to remember that users who have reddit gold may have settings which affect the response from the server. For example, users who have disabled promoted links will see an empty array returned when retrieving links from the promoted category of a subreddit.

Pagination

Methods which are paginated can accept RKPagination objects.

RKPagination lets you change the sorting of returned objects. For example, when fetching the top 25 links in a subreddit, setting the subredditCategory property changes whether you get the top 25 links right now or the top links overall.

In addition to letting you change the pagination of your requests, RedditKit also gives you pagination information for any requests made. A request for links in a subreddit has a pagination object as an argument in its completion block.

Due to the way reddit's API is structured, comments do not have support for pagination. Instead, comment listings will return RKMoreComments object which can then be used to retrieve the comments in question.

The example project implements pagination in a table view controller, loading new links when the user scrolls to the bottom.

Multiple Accounts

RKClient manages a single reddit account. When supporting multiple accounts, all you need to do is switch from using the sharedClient method to using one RKClient instance per account.

For example, this code:

[[RKClient sharedClient] signInWithUsername:@"username" password:@"password" completion:nil];
[[RKClient sharedClient] upvote:someLink completion:nil];

Becomes this:

RKClient *client = [[RKClient alloc] init];

[client signInWithUsername:@"username" password:@"password" completion:nil];
[client upvote:someLink completion:nil];

How you manage the various RKClient instances is up to you. Probably with an NSDictionary, using reddit usernames as keys.

Configuration

You can configure various aspects of RedditKit, including its default API endpoint and user agent. Check out the RKClient header file for more.

You should set your user agent to the name and version of your app, along with your reddit username. That way, if you ever have a buggy version of your app in the wild, the reddit admins will know who to contact.

If you do not set one manually, the user agent will be provided by AFNetworking.

Requirements

RedditKit requires either iOS 7.0+ or Mac OS X 10.9+. Xcode 5 or greater is required in order to run its test suite.

ARC is required. For projects that don't use ARC, you can set the -fobjc-arc compiler flag on the RedditKit source files.

Dependencies

Credits

SAMCategories by Sam Soffes is used for unescaping HTML entities in reddit link titles.

Also, a big thanks to all of the contributors to RedditKit.

Need Help?

Open an issue, or hit me up on Twitter.

License

Copyright (c) 2013 Sam Symons (http://samsymons.com/)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].