Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
SDK
 
 
 
 
 
 
 
 

README.md

Movable Type Data API SDK for Swift

Requirements

  • iOS 8.0+
  • Xcode 8.0+

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
                if let items = result {
                    print(items)
                }
            },
            failure: { (error: JSON?) -> Void in
            })
    },
    failure: { (error: JSON?) -> Void in
    }
)

create entry

import MTDataAPI_SDK

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

let api = DataAPI.sharedInstance
api.APIBaseURL = "http://host/mt/mt-data-api.cgi"
api.authentication("username", password: "password", remember: true,
    success:{_ in
        api.createEntry(siteID: "1", entry: entry,
            success: {(result: JSON?)-> Void in
                print(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
                print(result)
            },
            failure: {(error: JSON?)-> Void in
            }
        )
    },
    failure: {(error: JSON?)-> Void in
    }
)
You can’t perform that action at this time.