Home

Awesome

Medium SDK - Swift

A library to allow access to Medium API for any Swift iOS application.

Swift Version License Platform

Features

Compatibility

Installation

  pod 'MediumSDKSwift'

and run pod install in the directory to load dependencies.

Configuration

Add your MEDIUM_CLIENT_ID, MEDIUM_CLIENT_SECRET, MEDIUM_CALLBACK_URL in Build settings -> User-Define

In the project right click on your Info.plist file, choose "Open As" - "Source code" and add these lines :

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>mediumswift</string>
        </array>
    </dict>
</array>

<key>MediumCallbackURL</key>
<string>$(MEDIUM_CALLBACK_URL)</string>

<key>MediumClientID</key>
<string>$(MEDIUM_CLIENT_ID)</string>

<key>MediumClientSecret</key>
<string>$(MEDIUM_CLIENT_SECRET)</string>

right before the </dict> tag.

Handle the callback in App Delegate:

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
        if (url.host == "mediumswift-callback") {
            OAuthSwift.handleOpenURL(url)
        }
        return true
    }

Note that the redirect is done via a free Heroku app and it's highly recommended to setup your own redirect service by cloning and running this repo (courtesy of the original oauthswift.herokuapp.com repo). Change all the mediumswift strings in the repo to the name of your app and make related changes in Info.plist and App Delegate files. The deployment with Heroku is easy - just link your GitHub repo and the app is built automatically.

You are all set!

Usage

MediumSDKManager class is designed as a singleton, you can access all it's methods by calling a shared instance:

let mediumSession = MediumSDKManager.sharedInstance

List of methods of the MediumSDKManager class:

doOAuthMedium(completionHandler: (String, String) -> Void)
checkCred(completionHandler: (String, String) -> Void)
getUserID(completionHandler: (String, String) -> Void)
getToken(completionHandler: (String, String) -> Void)
signOutMedium(completionHandler: (String, String) -> Void)
ownCredentialsRequest(completionHandler: (String, String) -> Void)
userPublicationsListRequest(completionHandler: (String, String, JSON) -> Void)
getListOfContributors(publicationId: String, completionHandler: (String, String, JSON) -> Void)
createPost(title: String, contentFormat: String, content: String, canonicalUrl: String?=nil, tags: [String]?=nil,  publishStatus: MediumPublishStatus?=nil, license: MediumLicense?=nil, completionHandler: (String, String) -> Void)
createPostUnderPublication(rootPublication: String, title: String, contentFormat: String, content: String, canonicalUrl: String?=nil, tags: [String]?=nil, publishStatus: MediumPublishStatus?=nil, license: MediumLicense?=nil, completionHandler: (String, String) -> Void)

Note that publish status and licence fields are coded as enums with all the possible states of these parameters, when creating a publication just use the proper values.

Release History

Contribute

We would love for you to contribute to Medium SDK - Swift, check the LICENSE file for more info.

Meta

Original author:

Maintained:

Contributions by

Created as a part of development internship, distributed under the MIT license. See LICENSE for more information.

https://github.com/96-problems/medium-sdk-swift