A swift SDK for Medium's OAuth2 API

Overview

Medium SDK - Swift

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

Swift Version License Platform

Features

  • Medium.com authorization & token handling
  • Login state saved in user defaults
  • Supported scopes: basicProfile, listPublications, publishPost
  • Implemented all the related requests from the Medium API docs
  • Support Safari View Controller

Compatibility

  • iOS 9.0+ - osx 10.10

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 :


   
    CFBundleURLTypes
   

   
    
    
        
     
      CFBundleURLName
     
        
     
      $(PRODUCT_BUNDLE_IDENTIFIER)
     
        
     
      CFBundleURLSchemes
     
        
     
            
      
       mediumswift
      
        
     
    
    

   


   
    MediumCallbackURL
   

   
    $(MEDIUM_CALLBACK_URL)
   


   
    MediumClientID
   

   
    $(MEDIUM_CLIENT_ID)
   


   
    MediumClientSecret
   

   
    $(MEDIUM_CLIENT_SECRET)
   

right before the 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:

  • Authorize, completion handler returns state: success/failure and user's medium token or error string:
doOAuthMedium(completionHandler: (String, String) -> Void)
  • Check login credentials, completion handler returns state: success/failure and medium token or error string:
checkCred(completionHandler: (String, String) -> Void)
  • Get current user ID, completion handler returns state: success/failure and user ID or error string:
getUserID(completionHandler: (String, String) -> Void)
  • Get current Medium token, completion handler returns state: success/failure and medium token or error string:
getToken(completionHandler: (String, String) -> Void)
  • Sign out, completion handler returns state: success/failure, and message or error string:
signOutMedium(completionHandler: (String, String) -> Void)
  • Get current user's credentials, completion handler returns state: success/failure, and user ID as or error string:
ownCredentialsRequest(completionHandler: (String, String) -> Void)
  • Get list of current user's publications, completion handler returns state: success/failure, number of users publications or error string and publications JSON if present:
userPublicationsListRequest(completionHandler: (String, String, JSON) -> Void)
  • Get list of a publication's contributors, completion handler returns state: success/failure, number of users publications or error string and publications JSON if present:
getListOfContributors(publicationId: String, completionHandler: (String, String, JSON) -> Void)
  • Create new post, completion handler returns state: success/failure, and message or error string:
createPost(title: String, contentFormat: String, content: String, canonicalUrl: String?=nil, tags: [String]?=nil,  publishStatus: MediumPublishStatus?=nil, license: MediumLicense?=nil, completionHandler: (String, String) -> Void)
  • Create a post under existing publication, completion handler returns state: success/failure, and message or error string:
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

  • 0.1.1
    • Remove OSX
  • 0.1.0
    • Update syntax for Swift 3.0
    • Drop support <= iOS 9.0
    • Update dependencies
  • 0.0.4
    • add User-defnie variables
    • current version
  • 0.0.3
    • bug fixies
  • 0.0.2
    • update dependencies
  • 0.0.1
    • The first release

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

You might also like...
A Swift library for the Forecast.io Dark Sky API
A Swift library for the Forecast.io Dark Sky API

Requirements To use ForecastIO, all you need is an API key for the Dark Sky API. ForecastIO supports iOS (≥9.0), macOS (≥10.10), watchOS (≥2.0), and t

Questrade API written in Swift.

QuestradeAPI Getting Started The QuestAPI is made up of two main concepts: ResponseProviders API ResponseProviders The job of the provider is to retur

Endless-Api-OP - A swift server for Endless
Endless-Api-OP - A swift server for Endless

Endless-Api Introduce Hear is endless-api open source library. Endless-Api is us

The best way to use the Zora API in your Swift projects.

ZoraKit The best way to use the Zora API in your Swift projects. Disclaimer This is still very much a work in progress, and is really a proof-of-conce

A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1
A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1

STTwitter A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1 Like a FOSS version of Twitter Fabric TwitterKit, without th

Twitter API for Cocoa developers

FHSTwitterEngine Twitter API for Cocoa developers Created by Nathaniel Symer FHSTwitterEngine can: Authenticate using OAuth and/or xAuth. Make a reque

Giphy API client for iOS in Objective-C

Giphy-iOS Giphy-iOS is a Giphy API client for iOS in Objective-C. Usage To run the example project, clone the repo, and run pod install from the Examp

An easy-to-use Objective-C wrapper for the Uber API (no longer supported)
An easy-to-use Objective-C wrapper for the Uber API (no longer supported)

UberKit UberKit is a simple Objective-C wrapper for the new Uber API . Installation Cocoapods UberKit is available through Cocoapods. To install it, s

Unofficial Dribbble iOS wrapper allows you to integrate Dribble API into iOS application (Designer, Shot, Comment, User Story, Like, Follow)

DribbbleSDK DribbbleSDK is easy-to-use iOS wrapper for Dribbble SDK. We're working hard to complete the full coverage of available methods and make th

Comments
  • Update library to support Swift 3.0

    Update library to support Swift 3.0

    Bump version to 0.1.0 Update dependencies to the bleeding versions. Drop support below iOS 9 (Alamofire support requires >= iOS 9) Updated Readme Renamed Sample_Project to medium-sdk-swift-example

    opened by reejosamuel 1
Owner
null
The Waterwheel Swift SDK provides classes to natively connect iOS, macOS, tvOS, and watchOS applications to Drupal 7 and 8.

Waterwheel Swift SDK for Drupal Waterwheel makes using Drupal as a backend with iOS, macOS, tvOS, or watchOS enjoyable by combining the most used feat

Kyle Browning 414 Jul 26, 2022
The unofficial Instagram iOS SDK

InstagramKit An extensive Objective C wrapper for the Instagram API, completely compatible with Swift. Here's a quick example to retrieve trending med

Shyam Bhat 955 Dec 12, 2022
This repository is for the new ARGear SDK library for the iOS platform

This repository is for the new ARGear SDK library for the iOS platform. The library is not official yet. The library will be updated frequently by applying user feedback. When the APIs are fixed, the official library will be released.

ARGear 2 Apr 5, 2022
Wanikani-swift - Unofficial Swift client for the WaniKani API

WaniKani A Swift library and client for the WaniKani REST API. It currently supp

Aaron Sky 5 Oct 28, 2022
A Swift wrapper for Foursquare API. iOS and OSX.

Das Quadrat Das Quadrat is Foursquare API wrapper written in Swift. Features Supports iOS and OSX. Covers all API endpoints. Authorization process imp

Constantine Fry 171 Jun 18, 2022
Unofficial GitHub API client in Swift

Github.swift ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut

Khoa 184 Nov 25, 2022
An Elegant Spotify Web API Library Written in Swift for iOS and macOS

Written in Swift 4.2 Spartan is a lightweight, elegant, and easy to use Spotify Web API wrapper library for iOS and macOS written in Swift 3. Under th

Dalton Hinterscher 107 Nov 8, 2022
Swift Wrapper For Bittrex API

BittrexApiKit Swift client for Bittrex api. It support all APIs with most recent changes. more info here let api = Bittrex(apikey: "api key", secretke

Saeid 8 Apr 5, 2021
Instagram API client written in Swift

SwiftInstagram is a wrapper for the Instagram API written in Swift. It allows you to authenticate users and request data from Instagram effortlessly.

Ander Goig 579 Dec 31, 2022
A Slack API Client for the Perfect Server-Side Swift Framework

PerfectSlackAPIClient is an API Client to access the Slack API from your Perfect Server Side Swift application. It is build on top of PerfectAPIClient

Cap.雪ノ下八幡 2 Dec 1, 2019