TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Aug 2016 |
SPMSupports SPM | ✗ |
Maintained by Ben Le Cam.
Depends on: | |
SwiftyJSON | ~> 2.3.0 |
Alamofire | ~> 3.1.4 |
EVReflection | ~> 2.32.0 |
OrderCloudSwifty is a SDK for Four51’s OrderCloud API written in Swift and compatible with Objective-C.
If you do not wish to use a dependency manager, you can install OrderCloudSwifty manually.
$ cd /path/to/my/project
$ git init
$ git submodule add https://github.com/OrderCloud/OrderCloudSwifty.git
Open the OrderCloudSwifty
folder and drag the OrderCloudSwifty.xcodeproj
into the Project Navigator of your application’s Xcode project.
Select your Project and edit the target configuration of your application. Under the general panel, add an Embedded Binaries
under the “General” panel.
Select the OrderCloudSwifty
for the platform you are targeting.
The
OrderCloudSwifty.framework
is automatically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.
In order to interact with the API, you need to give OrderCloudSwifty your client id. See here to learn how to create one.
import OrderCloudSwifty
OrderCloud.setupClientId("my-client-id")
#import <OrderCloudSwifty.h>
int main() {
[OrderCloud.setupClientId: "client-id"]
}
Once you have set up the client ID, you can now log in using a User account created in the OrderCloud DevCenter console.
OrderCloud.Auth.currentUser.authenticate("username", password: "password")
[OrderCloud.Auth.currentUser authenticate:"username" password:"password"]
You can also specify the scope of the user as well as the callback to use.
OrderCloud.User.currentUser.authenticate("username", password: "password", scope: "scope", completionHandler: { response in
// Do something with response
})
Most functions that call the API will give you the possibility to define your own callback. This ensures that your application stays asynchronous, especially in the context of a GUI. To handle the response of the request, default callbacks are provided in the Util.swift
file. Here is a good structure to use:
{ response in
switch response.result {
case .Success:
if let value = response.result.value {
let json = JSON(value)
}
case .Failure(let error):
print("error:", error)
}
}
{ response in
}
OrderCloudSwifty is available under the MIT license. See the LICENSE file for more info.