Latest 0.1.4
Homepage https://github.com/ssylveus/DPDSwift
License MIT
Platforms ios 8.0, requires ARC
Dependencies ObjectMapper
Frameworks UIKit
Authors

Deployd is a tool that makes building APIs simple by providing important ready-made functionality out of the box that meet the demands of complex applications (http://deployd.com).
DPDSwift is an iOS library, that helps facilitate the use of Deployd for iOS Development.

Features

  • DPDObject
  • DPDUser (Login, Logout)
  • DPDQuery
  • DPDRequest

The Basics

  • DPDSwift Uses ObjectMapper Library for object mapping. More information can be found here.
    https://github.com/Hearst-DD/ObjectMapper

  • Assuming we have a collection on Deployd called Stores. We can access the store collection as follow.

  • Using DPDObject
    
    import UIKit
    import DPDSwift
    import ObjectMapper

class Store: DPDObject {
var name: String?
var city: String?
var state: String?
var zip: String?

required init() {
    super.init()
}

required init?(_ map: Map) {
    super.init(map)
}

override func mapping(map: Map) {
    super.mapping(map)

    name <- map["name"]
    city <- map["city"]
    state <- map["state"]
    zip <- map["zip"]
}

}

//================================ Inside View Controller =============================================
import UIKit
import DPDSwift

class ViewController: UIViewController {
let rootUrl = "http://localhost:2403/"
let store = Store()

override func viewDidLoad() {
    super.viewDidLoad()
}

func createStore() {
    store.name = "Best Buy"
    store.city = "Crystal Lake"
    store.state = "IL"
    store.zip = "60012"

    store.createObject(Store(), rootUrl: rootUrl, endPoint: "stores") { (response, responseHeader, error) in
        if error == nil {
            print("store created successfully")
        } else {
            print("failed to create store")
        }
    }
}

func updateStoreCollection() {
    store.name = "Apple"
    store.updateObjectInBackground(Store(), rootUrl: rootUrl, endPoint: "stores") { (response, responseHeader, error) in
        if error == nil {
            print("store updated successfully")
        } else {
            print("failed to update store")
        }
    }
}

}

//========= If you want the response to be mapped to specific DPDObject, you can call the findMappableObject() otherwise call the findObject() method ===============
func getStores() {
let query = DPDQuery(queryCondition: DPDQuery.QueryCondition.None,
ordertype: DPDQuery.OrderType.Ascending,
limit: nil,
skip: nil,
queryField: nil,
queryFieldValue: nil,
sortField: nil)

    query.findMappableObject(Store(), rootUrl: rootUrl, endPoint: "stores") { (response, error) in
        if error == nil {
            if let stores = response as? [Store] {
                for store in stores {
                    print(store.toJSON())
                    print("nn")
                }
            }
        } else {
            print(error)
        }
    }

}

# Using DPDUser

- SubClassing DPDUser 

```swift
import UIKit
import DPDSwift
import ObjectMapper

class User: DPDUser {
    var firstName: String?
    var lastName: String?
    var fullName: String?
    var age: NSNumber?

    required init() {
        super.init()
    }

    required init?(_ map: Map) {
        super.init(map)
    }

    override func mapping(map: Map) {
        super.mapping(map)

        firstName <- map["firstName"]
        lastName <- map["lastName"]
        fullName <- map["fullName"]
        age <- map["age"]
    }
}

//========================== Creating a User Collection ===============================
func createUser() {
        DPDUser.createUser(User(), rootUrl: rootUrl, username: "[email protected]", password: "dpdswift") { (response, responseHeader, error) in
            if error == nil {
                if let users = response as? [User] {
                    print(users[0].toJSON())
                }
            } else {
                print(error)
            }
        }
    }

func updateUser() {
    if let user = DPDUser.currentUser(User()) {
        user.firstName = "DPD"
        user.lastName = "Swift"
        user.fullName = user.firstName! + " " + user.lastName!
        user.age = 28

        user.updateObjectInBackground(User(), rootUrl: rootUrl, endPoint: "users", compblock: { (response, responseHeader, error) in
            if error == nil {
                if let users = response as? [User] {
                    print(users[0].toJSON())
                }
                } else {
                    print(error)
                }
            })
        }
}

Installation

DPDSwift can be added to your project using CocoaPods 0.36 or later by adding the following line to your Podfile:

pod 'DPDSwift', :git => 'https://github.com/ssylveus/DPDSwift.git'

Latest podspec

{
    "name": "DPDSwift",
    "platforms": {
        "ios": "8.0"
    },
    "summary": "DPDSwift is an iOS library, that helps facilitate the use of Deployd for iOS Development.",
    "requires_arc": true,
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "3.0"
    },
    "version": "0.1.4",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Steeven Sylveus": "[email protected]"
    },
    "homepage": "https://github.com/ssylveus/DPDSwift",
    "source": {
        "git": "https://github.com/ssylveus/DPDSwift.git",
        "branch": "master",
        "tag": "0.1.4"
    },
    "frameworks": "UIKit",
    "dependencies": {
        "ObjectMapper": [
            "=2.2.8"
        ]
    },
    "source_files": [
        "DPDSwift",
        "DPDSwift/**/*.{swift}"
    ],
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This