测试测试通过 | ✓ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2015 年 8 月 |
SPM支持 SPM | ✗ |
由 Solal Fitoussi 维护。
依赖项 | |
Alamofire | = 1.3.1 |
ObjectMapper | = 0.15 |
Mirmeca 是一个用 Swift 编写的框架,它可以让你轻松地在 WordPress API 上构建应用程序。
Post
、FeaturedImage
、Term
、Comment
、Author
等)的现成模型。PostsGateway
、CommentGateway
等)。要开始,您需要一个运行 WP API 插件的 WordPress 安装。
通过 网关(PostsGateway
、TermGateway
等)与您的 WordPress 后端进行交互。
网关可以让您使用几行代码向 WordPress 发送内容请求。
它们输出 类型(Post
、Comment
、Author
)或类型的数组。
let envs = ["dev": "https://:3000/wp-json", "staging": "http://staging.example.com"]
MirmecaEnv.sharedInstance.defineEnvs(envs, defaultEnv: "dev")
// Pass the "posts" endpoint & use the default env
PostsGateway(endpoint: "posts", env: nil).request({})
PostsGateway(endpoint: "posts", env: nil).request({ (value: AnyObject?, error: NSError?) -> Void in
// Make sure that something was returned
if (error != nil) {
println("Something went wrong")
} else {
// Cast the return value as an array of posts
let posts = value as! [Post]
for post in posts {
println(post.title!)
}
}
})
以下是 Mirmeca 帮助您完成的众多事情中的三个。
posts?filter[s]=
PostsGateway
let query = "chocolate%20cake"
PostsGateway(endpoint: "posts?filter[s]=\(query)", env: nil).request({ (value: AnyObject?, error: NSError?) -> Void in
// Make sure that something was returned
if (error != nil) {
println("Something went wrong")
} else {
// Cast the return value as an array of posts
let posts = value as! [Post]
for post in posts {
println(post.title!)
}
}
})
taxonomies/category/terms
TermsGateway
TermsGateway(endpoint: "taxonomies/category/terms", env: nil).request({ (value: AnyObject?, error: NSError?) -> Void in
// Make sure that something was returned
if (error != nil) {
println("Something went wrong")
} else {
// Cast the return value as an array of terms
let categories = value as! [Term]
for category in categories {
println(category.name!)
}
}
})
posts/40627/comments
CommentsGateway
CommentsGateway(endpoint: "posts/40627/comments", env: nil).request({ (value: AnyObject?, error: NSError?) -> Void in
// Make sure that something was returned
if (error != nil) {
println("Something went wrong")
} else {
// Cast the return value as an array of comments
let comments = value as! [Comment]
for comment in comments {
println(comment.author!.name!)
}
}
})