All Projects → sonsongithub → Reddift

sonsongithub / Reddift

Licence: mit
Swift Reddit API Wrapper

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Reddift

Updoot
A reddit client built for android
Stars: ✭ 51 (-76.28%)
Mutual labels:  oauth, reddit
Praw
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.
Stars: ✭ 2,675 (+1144.19%)
Mutual labels:  oauth, reddit
aPRAW
Asynchronous Python Reddit API Wrapper
Stars: ✭ 49 (-77.21%)
Mutual labels:  oauth, reddit
Jraw
The Java Reddit API Wrapper
Stars: ✭ 320 (+48.84%)
Mutual labels:  oauth, reddit
Oauth
🔗 OAuth 2.0 implementation for various providers in one place.
Stars: ✭ 336 (+56.28%)
Mutual labels:  oauth, reddit
Netcore Postgres Oauth Boiler
A basic .NET Core website boilerplate using PostgreSQL for storage, Adminer for db management, Let's Encrypt for SSL certificates and NGINX for routing.
Stars: ✭ 57 (-73.49%)
Mutual labels:  oauth, reddit
Shreddit
Remove your comment history on Reddit as deleting an account does not do so.
Stars: ✭ 669 (+211.16%)
Mutual labels:  oauth, reddit
Login With
Stateless login-with microservice for OAuth
Stars: ✭ 2,301 (+970.23%)
Mutual labels:  oauth, reddit
External Auth Server
easy auth for reverse proxies
Stars: ✭ 189 (-12.09%)
Mutual labels:  oauth
Media Scraper
Scrapes all photos and videos in a web page / Instagram / Twitter / Tumblr / Reddit / pixiv / TikTok
Stars: ✭ 206 (-4.19%)
Mutual labels:  reddit
Angular2 Login Seed
(deprecated) Seed app w/ Angular2, Node, Express, and OAuth login
Stars: ✭ 181 (-15.81%)
Mutual labels:  oauth
Oauthlib
A generic, spec-compliant, thorough implementation of the OAuth request-signing logic
Stars: ✭ 2,323 (+980.47%)
Mutual labels:  oauth
Tiup
A component manager for TiDB
Stars: ✭ 207 (-3.72%)
Mutual labels:  playground
Design Patterns In Swift
📖 Design Patterns implemented in Swift 5.0
Stars: ✭ 13,146 (+6014.42%)
Mutual labels:  playground
Twitch4j
Modular Async/Sync/Reactive Twitch API Client / IRC Client
Stars: ✭ 209 (-2.79%)
Mutual labels:  oauth
Redd
Redd is a batteries-included API wrapper for reddit.
Stars: ✭ 180 (-16.28%)
Mutual labels:  reddit
Hwioauthbundle
OAuth client integration for Symfony. Supports both OAuth1.0a and OAuth2.
Stars: ✭ 2,150 (+900%)
Mutual labels:  oauth
Express Starter
It's a hackathon-starter fork, but designed to use PostgreSQL by default (or MySQL)
Stars: ✭ 215 (+0%)
Mutual labels:  oauth
Reddit Hyped Stocks
A web application to explore currently hyped stocks on Reddit
Stars: ✭ 173 (-19.53%)
Mutual labels:  reddit
Docker
Docker playground
Stars: ✭ 202 (-6.05%)
Mutual labels:  playground

Carthage compatible Version License Platform Build Status

reddift

reddift is Swift Reddit API Wrapper framework, and includes a browser is developed using the framework.

  • Supports OAuth2(is not supported on tvOS currently).
  • Supports multi-accounts.
  • Includes a sample application(iOS only).

Browser

  • It's a typical browser of reddit.com.
  • This application uses "reddift framework" in order to access reddit.com.
  • Includes almost all of functions, such as image thumbnails, browsing comments, search subreddits and so on.
  • If you need more features to this, please send pull requests to me.

reddift-comments reddift-images

Document

How to build

Now, it's under developing. You have to pay attention to use this library.

1. Check out source code.

# check out reddift and its submodules.
> git clone --recursive https://github.com/sonsongithub/reddift.git

Check that these libraries are checked out at each path correctly.

/framework/vendor/HTMLSpecialCharacters
/framework/vendor/MiniKeychain

2. Create application(installed app) at reddit.com

Create new installed app via preference page at reddit.com. And then, check your app's cliend_id and fill out redirect_uri for OAuth2. For example, redirect_uri is set to myapp://response. In following sample, redirect_uri is set to reddift://response.

installedapp

3. Set up reddift_config.json

This JSON file saves application information to use OAuth. Rename reddift_config.json.sample to reddift_config.json. And fill out DeveloperName, redirect_uri and client_id. redirect_uri must be same one you registered at reddit.com. You can check client_id at application tab. reddift generates http's user-agent property using this JSON and application's info.plist.

{
  "DeveloperName": "<YOUR NAME>",
  "redirect_uri": "<YOUR REDIRECT URI>",
  "client_id": "<YOUR ID>"
}

4. Set up your URI on Xcode

In Xcode, set up URL Types in order to receive call back from Safari. Set URL Schemes to redirect_uri that you set at reddit.com. You don't have to include ://response to this form. These URI must be identical. If they are not identical, reddit.com does not authorize your OAuth request. In following sample, URL Schemes is set to reddift.

reddit2

How to build test

1. Register user script app

Test uses Application Only OAuth to remove user interaction from test process. If you want to run tests of reddift, you have to create another "Script" type application(personal use script) at reddit.com.

userscript

2. Fill out test_config.json

At first, rename test_config.json.sample to test_config.json. Fill each following value using above preference pain of reddit.com.

{
  "username": "test user account",
  "password": "test user password",
  "client_id": "test app client ID(must be script type app)",
  "secret": "test app secret"
}

3. Start test

Cmd + U.

How to build browser sample

You have to build dependent frameworks using carthage before building a sample application using Xcode.

# before open xcode project file.
> carthage update --platform iOS

carthage works corretly, you can get following frameworks at each path.

/Carthage/Build/iOS/FLAnimatedImage.framework
/Carthage/Build/iOS/YouTubeGetVideoInfoAPIParser.framework
/Carthage/Build/iOS/UZTextView.framework

And, you get to edit URI types and reddift_config.json as same as the framework.

Create you app.

Get something & Error handling

reddift returns Result<T> object as a result. Get the value or error from Result<T> object. Concretely, you can access either value evaluating enum state like a following code.

// do not use "!" in your code
switch(result) {
case .failure(let error):
    println(error)
case .success(let listing):
    // do something to listing
}

In more detail about this coding style, see "Efficient JSON in Swift with Functional Concepts and Generics".

Create session

At first, you have to implement codes to receive the response of OAuth2 in UIAppDelegate. reddift let you save tokens as a specified name into KeyChain. Specifically, following sample code saves token as user name at reddit.com.

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    return OAuth2Authorizer.sharedInstance.receiveRedirect(url, completion:{(result) -> Void in
        switch result {
        case .failure(let error):
            print(error)
        case .success(let token):
            dispatch_async(dispatch_get_main_queue(), { () -> Void in
                OAuth2TokenRepository.saveIntoKeychainToken(token, name:token.name)
            })
        }
    })
}

To communicate with reddit.com via OAuth2, you have to create Session object. See following section about getting response or error handling.

let result = OAuth2TokenRepository.restoreFromKeychainWithName(name)
switch result {
case .failure(let error):
    print(error.description)
case .success(let token):
    con.session = Session(token: token)
}

You can get contents from reddit via Session object like following codes.

session?.getList(paginator, subreddit:subreddit, sort:sortTypes[seg.selectedSegmentIndex], timeFilterWithin:.All, completion: { (result) in
    switch result {
    case .failure(let error):
        print(error)
    case .success(let listing):
        self.links.appendContentsOf(listing.children.flatMap{$0 as? Link})
    }
})

Use Application Only OAuth

You can use OAuth2AppOnlyToken when you want to write a code for test or personal script tool(such as CLI). OAuth2AppOnlyToken enabled to access reddit without human action in order to authorize in web browser apps. Do not use Oauth2AppOnlyToken in installed app in terms of security.

OAuth2AppOnlyToken.getOAuth2AppOnlyToken(
    username: username,
    password: password,
    clientID: clientID,
    secret: secret,
    completion:( { (result) -> Void in
    switch result {
    case .failure(let error):
        print(error)
    case .success(let token):
        self.session = Session(token: token)
    }
}))

Further more,

In more detail, See my sample application, test code or Playground code included in this repository.

Playground

You can play with reddift in Playground. In more detail, check reddift.playground package. Before using, you have to copy test_config.json into ./reddift.playground/Resources in order to specify user account and your application informatin because reddift on Playground uses "Application Only OAuth".

playground

Dependency

License

MIT License.

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].