TypetalkKit is an unofficial web API client for Typetalk.
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.
- Pure Swift API
- Full REST API support with APIKit
- Streaming API support with Starscream
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.
pod 'TypetalkKit'
github "safx/TypetalkKit"
-
Add TypetalkKit as a submodule:
git submodule add https://github.com/safx/TypetalkKit.git
-
Add TypetalkKit.xcodeproj to your project.
-
Add TypetalkKit to "Target Dependencies" of "Build Phases" tab of your app's target.
-
Add "Copy Files" to copy TypetalkKit.framework:
- Click " " button, and select "New Copy Files Phase" to add "Copy Files" to choose.
- Set the "Destination" to "Frameworks", and add TypetalkKit.framework.