Code Monkey home page Code Monkey logo

typetalkkit's Introduction

TypetalkKit

TravisCI codecov.io Platform License Version Carthage

TypetalkKit is an unofficial web API client for Typetalk.

Basic Usage

The following code gets user's topics and prints these.

TypetalkAPI.sendRequest(GetTopics(spaceKey: spaceKey)) { result in
    switch result {
    case .Success(let ts):
        for i in ts {
            print(i)
        }
    case .Failure(let error):
        // error
    }
}

TypetalkKit supports almost all Typetalk API.

If you want to know further information about API, please visit official page.

Features

  • Pure Swift API
  • Full REST API support with APIKit
  • Streaming API support with Starscream

Authorization

To use TypetalkKit, you need to register your app at the Official Developer page first.

When you register your app, choose "Authorization Code" for Grant Type and set URI including custom URL scheme, which should be unique to complete authorization process.

In your app, set developer settings:

TypetalkAPI.setDeveloperSettings(
    clientId:     "Your ClientID",
    clientSecret: "Your SecretID",
    redirectURI:  "Your custome scheme",    // e.g. typetalkkit+<YOUR_APP_ID>://auth/success
    scopes: [Scope.my, Scope.topic_read])

And then call authorize.

TypetalkAPI.authorize { (error) -> Void in
   ...
}

TypetalkKit use Safari for Typetalk's authorization process. You, thearefore, have to add a custom URL scheme for "redirect URI" to your Info.plist in order to switch back to your app from Safari.

When your app is back from Safari, call TypetalkAPI.authorizationDone in your application(openURL, sourceApplication, annotation) as follows:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
    if TypetalkAPI.isRedirectURL(url) && sourceApplication? == "com.apple.mobilesafari" {
        return TypetalkAPI.authorizationDone(URL: url)
    }
    return false
}

If you don't call authorizationDone, the callback of authorize never be called.

In OS X, you can use TypetalkAPI.authorizationDone in handleGetURLEvent as follows:

func handleGetURLEvent(event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?) {
    if let ev = event,
        url_str = ev.descriptorForKeyword(AEKeyword(keyDirectObject))?.stringValue,
        url = NSURL(string: url_str) where TypetalkAPI.isRedirectURL(url) {
            TypetalkAPI.authorizationDone(URL: url)
    }
}

For more information of Typetalk's authorization, please see official page.

Install

CocoaPods

pod 'TypetalkKit'

Carthage

github "safx/TypetalkKit"

Manual Install

  1. Add TypetalkKit as a submodule:

     git submodule add https://github.com/safx/TypetalkKit.git
    
  2. Add TypetalkKit.xcodeproj to your project.

  3. Add TypetalkKit to "Target Dependencies" of "Build Phases" tab of your app's target.

  4. Add "Copy Files" to copy TypetalkKit.framework:

    1. Click "+" button, and select "New Copy Files Phase" to add "Copy Files" to choose.
    2. Set the "Destination" to "Frameworks", and add TypetalkKit.framework.

typetalkkit's People

Contributors

safx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.