OrderCloudSwifty 0.1.4

OrderCloudSwifty 0.1.4

DocsDocumented
TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Aug 2016
SPMSupports SPM

Maintained by Ben Le Cam.


Downloads

Total11
Week0
Month0

Installs

Apps3
Test Targets2
powered by Segment

Code

Files88
SizeIntegration Size 440 kb
FrameworkCreates Framework
LOCLines of Code 2,703


 
Depends on:
SwiftyJSON~> 2.3.0
Alamofire~> 3.1.4
EVReflection~> 2.32.0
 

  • By
  • Ben Le Cam

OrderCloudSwifty

OrderCloudSwifty is a SDK for Four51’s OrderCloud API written in Swift and compatible with Objective-C.

Requirements

  • iOS 8.0+ / Mac OS X 10.9+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 7.2+

Communication

  • If you need help, use Stack Overflow. (Tag ‘ordercloud’)
  • If you’d like to ask a general question, use Stack Overflow.
  • If you have any questions or need help, join the #ordercloudevs channel on Slack
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.

Installation

Manually as an embedded framework

If you do not wish to use a dependency manager, you can install OrderCloudSwifty manually.

  • Using the terminal, go to your project directory:
$ cd /path/to/my/project
  • If you have not initialized a Git repository in your project directory, do so with :
$ git init
  • Add OrderCloudSwifty as a submodule by running the following command:
$ 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.

Usage

Setup

In order to interact with the API, you need to give OrderCloudSwifty your client id. See here to learn how to create one.

  • Swift
import OrderCloudSwifty

OrderCloud.setupClientId("my-client-id")
  • Objective-C
#import <OrderCloudSwifty.h>

int main() {
  [OrderCloud.setupClientId: "client-id"]
}

Authenticating

Once you have set up the client ID, you can now log in using a User account created in the OrderCloud DevCenter console.

  • Swift
OrderCloud.Auth.currentUser.authenticate("username", password: "password")
  • Objective-C
[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
})

Handling request 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 

}

License

OrderCloudSwifty is available under the MIT license. See the LICENSE file for more info.