/Twifter

Twitter API Client written in Swift

Primary LanguageSwiftMIT LicenseMIT

Twifter

SwiftVersion License Platform Build Status codecov

❗ This is a beta version!

Task

  • Twitter OAuth Authentication
    • OAuth
    • iOS internal twitter account
    • App Only Authentication
  • Twitter REST APIs
  • Installation
    • Cocoapods
    • Carthage
    • Swift Package Manager
  • Document
  • Platform
    • iOS
    • Mac
    • Linux
    • tvOS
    • watchOS

Requirements

iOS 11.0+

Installation

Cocoapods

pod 'Twifter'

Carthage

github 'simorgh3196/Twifter'

Swift Package Manager

.package(url: "https://github.com/simorgh3196/Twifter.git", .upToNextMajor(from: "0.2.0")),

Setup

  • Set URL Types in Info.plist
  • Set ConsumerToken, Secret and OAuth callback handler in AppDeleagte.swift
import UIKit
import Twifter

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Set consumerToken and consumerSecret
        Twifter.registerConsumerKey(token: "*************************",
                                    secret: "**************************************************")
        return true
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        // Set handler of twitter oauth callback
        Twifter.handleOpenURL(url: url)

        return true
    }

}

Usage

OAuth Authentication

callbackURL is defined by URL Types in Info.plist

let callbackURL = URL(string: "twifter://")!
Twifter.authentication(viewController: self, callbackURL: callbackURL, handler: { result in
    switch result {
    case .success(let accessToken):
        print("success!!!")
        print("AccessToken is " + accessToken)

    case .failure(let error):
        print(error)
    }
})

Get Tweets

let twifter = Twifter(accessToken: accessToken)
twifter.getTimeline { tweets in
  print(tweets)
}

Document

TODO

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/simorgh3196/Twifter.

License

The module is available as open source under the terms of the MIT License.