Skip to content

Mirmeca/Mirmeca

Repository files navigation

CocoaPods Build Status

Mirmeca

Mirmeca

Mirmeca is a framework written in Swift that makes it easy for you to build apps on top of the WordPress API.

Features

  • Out of the box models for WordPress types (Post, FeaturedImage, Term, Comment, Author, etc...).
  • Built in gateways to retrieve collections of types or single items from your WordPress backend (PostsGateway, CommentGateway, etc...).
  • Start displaying content in under 5 minutes and less than 5 lines of code.

Getting started

To get started you will need a WordPress installion running the WP API plugin.

Interaction with your WordPress backend is made through Gateways (PostsGateway, TermGateway...).

Gateways let you send requests for content to WordPress in just a few lines of code.

They output types (Post, Comment, Author...) or arrays or types.

Declare your environnements in your AppDelegate

let envs = ["dev": "http://localhost:3000/wp-json", "staging": "http://staging.example.com"]
MirmecaEnv.sharedInstance.defineEnvs(envs, defaultEnv: "dev")

Send a request to get the latest posts in your ViewController

// Pass the "posts" endpoint & use the default env
PostsGateway(endpoint: "posts", env: nil).request({})

Print the posts by passing a closure to the request method

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!)
    }
  }
})

Use cases

Here are three of the numerous things Mirmeca helps you accomplish.

Types & Gateways

  • Check the list available types here.
  • Check the list available Gateways here.

Search for posts

  • Endpoint: posts?filter[s]=
  • Gateway: PostsGateway
  • Code:
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!)
    }
  }
})

List your site's categories

  • Endpoint: taxonomies/category/terms
  • Gateway: TermsGateway
  • Code:
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!)
        }
    }
})

Retrieve comments for a post

  • Endpoint: posts/40627/comments
  • Gateway: CommentsGateway
  • Code:
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!)
        }
    }
})

Installation

You can use CocoaPods to install Mirmeca.

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Mirmeca', '~> 0.04'

Contributing

Credits

Icon: Ant by Gilad Fried from the Noun Project