TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2016 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by evermeer.
Depends on: | |
Alamofire | >= 0 |
KeychainAccess | >= 0 |
EVReflection | >= 0 |
AlamofireOauth2 | >= 0 |
AlamofireJsonToObjects | >= 0 |
A Swift implementation of the WordPress (Jetpack) API.
EVWordPressAPI maps WordPress (Jetpack) API calls to method calls where the result is returnd as easy to use Objects
For more information see the WordPress API documentation
The test calls that require authentication will be executed from the demo app. You have to configure the Oauth2Settings. See the ViewController.swift for more information. The calls that do not require authentication are tested from the unittests in EVWordPressAPITests.swift
The EVWordPressAPI is using the folowing (cocoapods) libraries:
This project started as a trial for AlamofireJsonToObjects. There are more than 100 wordpress API callse. It will take some time to map all of these (help is welcome :) ). So far only the folowing API calles are implemented:
API sections - status (for now only the get calls)
'EVWordPressAPI' is now available through the dependency manager CocoaPods. You do have to use cocoapods version 0.36. At this moment this can be installed by executing:
[sudo] gem install cocoapods
Version 0.36 of cocoapods will make a dynamic framework of all the pods that you use. Because of that it's only supported in iOS 8.0 or later. When using a framework, you also have to add an import at the top of your swift file like this:
import EVWordPressAPI
1) Clone the repo to a working directory
2) CocoaPods is used to manage dependencies. Pods are setup easily and are distributed via a ruby gem. Follow the simple instructions on the website to setup. After setup, run the following command from the toplevel directory of EVWordPressAPI to download the dependencies:
pod install
3) Open the EVWordPressAPI.xcworkspace
in Xcode.
4) Create your own clientID and clientSecret at https://developer.wordpress.com/docs/oauth2/
5) set the clientID and clientSecret in the wordpressOauth2Settings object in the ViewController.swift
and you are ready to go!
Below is the sample code for a simple call:
let api = EVWordPressAPI(baseUrl: "https://public-api.wordpress.com/rest/v1.1", site: "evict.nl")
api.posts([.number(19)]) { posts in
// now use the posts object
}
There is also support for API calls that require authentication (OAuth2). Here is a sample code for that:
let wordpressOauth2Settings = Oauth2Settings(
baseURL: "https://public-api.wordpress.com/rest/v1.1",
authorizeURL: "https://public-api.wordpress.com/oauth2/authorize",
tokenURL: "https://public-api.wordpress.com/oauth2/token",
redirectURL: "alamofireoauth2://wordpress/oauth_callback",
clientID: "????????????",
clientSecret: "????????????"
)
let api = EVWordPressAPI(wordpressOauth2Settings: self.wordpressOauth2Settings, site: "evict.nl")
api.users(self, parameters:[.number(19), .authors_only(false)]) { users in
// now use the users object
}
All calls have a parameters array that can contain a list of an enum where the value will be passed on as the associated value. You only have to specify the parameters with none default values.
All result objects have an error and a message property. These will have a value if something went wrong. These could contain the error information from the service (See the documentation for each call). Besides that it could also contain "OAuth2 error" or "Network error .." plus the message details.
When authentication is required, then the method call will hava a parameter that should be populated with the active ViewController. The authentication webview will be created as a child of that viewcontroller.
EVWordPressAPI is available under the MIT 3 license. See the LICENSE file for more info.
Also see my other open source iOS libraries: