Latest 1.0.9
Homepage https://github.com/movabletype/mt-data-api-sdk-swift
License MIT
Platforms ios 8.0, requires ARC
Dependencies Alamofire, SwiftyJSON
Authors

Movable Type Data API SDK for Swift

Requirements

  • iOS 8.0+
  • Xcode 6.1+

Installation

pod "MTDataAPI-SDK"

Usage

list blogs

import MTDataAPI_SDK

let api = DataAPI.sharedInstance
api.APIBaseURL = "http://host/mt/mt-data-api.cgi"
api.authentication("username", password: "password", remember: true,
    success:{_ in
        api.listSites(
            success: {(result: [JSON]!, total: Int!)-> Void in
                let items = result
                println(items)
            },
            failure: {(error: JSON!)-> Void in
            }
        )
    },
    failure: {(error: JSON!)-> Void in
    }
)

create entry

import MTDataAPI_SDK

let api = DataAPI.sharedInstance
api.APIBaseURL = "http://host/mt/mt-data-api.cgi"

var entry = [String:String]()
entry["title"] = "title"
entry["body"] = "text"
entry["status"] = "Publish"

api.authentication("username", password: "password", remember: true,
    success:{_ in
        api.createEntry(siteID: "1", entry: entry,
            success: {(result: JSON!)-> Void in
                println(result)
            },
            failure: {(error: JSON!)-> Void in
            }
        )
    },
    failure: {(error: JSON!)-> Void in
    }
)

upload asset

import MTDataAPI_SDK

let api = DataAPI.sharedInstance
api.APIBaseURL = "http://host/mt/mt-data-api.cgi"
api.authentication("username", password: "password", remember: true,
    success: {_ in
        let image = UIImage(named:"photo")
        let data = UIImageJPEGRepresentation(image, 1.0)
        api.uploadAssetForSite(siteID: siteID, assetData: data, fileName: "photo.jpeg", options: ["path":"/images", "autoRenameIfExists":"true"],
            success: {(result: JSON!)-> Void  in
                println(result)
            },
            failure: {(error: JSON!)-> Void in
            }
        )
    },
    failure: {(error: JSON!)-> Void in
    }
)

Latest podspec

{
    "name": "MTDataAPI-SDK",
    "version": "1.0.9",
    "summary": "Movable Type Data API SDK for Swift.",
    "description": "This is the SDK for Movable Type Data API. You can use/redistribute under the MIT license.",
    "homepage": "https://github.com/movabletype/mt-data-api-sdk-swift",
    "license": "MIT",
    "authors": {
        "Six Apart": "[email protected]"
    },
    "source": {
        "git": "https://github.com/movabletype/mt-data-api-sdk-swift.git",
        "tag": "1.0.9"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "SDK/**/*",
    "dependencies": {
        "Alamofire": [
            "~> 3.0"
        ],
        "SwiftyJSON": []
    }
}

Pin It on Pinterest

Share This