IMPORTANT:
This framework is still under development. DO NOT use it… just yet 😂.
And if you are willing to help, feel free to creat pull requests.
The Movie Database API wrapper in Swift.
I’m just a very beginner to the Swift world. And I decide to take this project as my first step. So any issue and pull request are welcomed :-)
Project progress
v3 current progress:
v4 current progress:
Will begin soon.
Usage
Installation
With CocoaPods:
use_frameworks! target 'TMDBKitDemo' do platform :osx, '10.12' pod 'TMDBKit' end
Or simply drag all
.swift files in
Common folder to your project (please note that TMDBKit needs SwiftyJSON as dependency).
Meet TMDBManager
All you need with TMDBKit is wrapped in the
TMDBManager singleton instance, like this:
import TMDBKit let manager = TMDBManager.shared
Setup the TMDBManager
In your AppDelegate’s
applicationDidFinishLaunching method:
let manager = TMDBManager.shared manager.setupClient(withApiKey: "Your-API-key", persistencePrefix: "com.yourTeamName.yourAppName")
Get user authentication
First you need to fetch a request token by:
let manager = TMDBManager.shared manager.createRequestToken() { result in switch result { case .success: // Forward your user to the authentication page. For macOS: let redirectURL = "yourAppURLScheme://auth_done" NSWorkspace.shared.open(TMDBManager.shared.authentication.authenticationURL(redirectURL: redirectURL)!) case .fail(let error): print(error) } }
And after the user authorizes the request token, fetch a session ID:
let manager = TMDBManager.shared manager.authentication.createSession() { result in switch result { case .success: print(Session ID Fetched: (TMDBManager.shared.sessionId!)) case .fail(let error): print(error) } }
The session ID will be persisted in the keychain.
Completion hanlders
Almost all TMDBKit methods needs a
completion parameter. The handler will pass in a enum by which you can check if the request has been fullfied. And to those methods that returns data, the enum will carry a model object. It works like this:
let manager = TMDBManager.shared manager.account.getDetails() { result in // Check if the request has been fullfied switch result { // If success, you will recive a model object case .success(let accountInfo): print(accountInfo) // Otherwise, you will get an optional error case .fail(let error): print(error) } }
Need help?
All methods are equiped with full documentation comments. All you need to do is Option⌥ click the method name. Or switch to the Quick Help Inspector:
License
TMDBKit is available under the MIT license. See the LICENSE file for more info.
Latest podspec
{ "name": "TMDBKit", "version": "0.0.1", "summary": "The Movie Database API wrapper in Swift.", "description": "The Movie Database API wrapper in Swift.nSee the Github page for usage and other info.", "homepage": "", "license": { "type": "MIT", "file": "LICENSE" }, "authors": { "Siyuan Cao": "[email protected]" }, "platforms": { "ios": "10.0", "osx": "10.12", "watchos": "3.0", "tvos": "10.0" }, "source": { "git": "", "tag": "0.0.1" }, "source_files": [ "Common/**/*.swift" ], "requires_arc": true, "pod_target_xcconfig": { "SWIFT_VERSION": "4.0" }, "dependencies": { "SwiftyJSON": [] }, "pushed_with_swift_version": "4.0" }
Thu, 26 Oct 2017 12:00:09 +0000