DALI

CI Status Version License Platform

A framework used by DALI Lab members to access the internal API, which stores all information about DALI’s projects, members, and events.

Getting Started

Authenticate

The API protects its data using two methods: private API key and Google OAuth2. This is done to support two different use cases: static installment or user-personal device.

Google OAuth2 (User-Personal)

A user-personal product could be an iOS app, Watch OS app, or anything that is personal to a user. This type of authentication uses the user’s login credentials with Google to authenticate and identify them.

Qualifications:

  • The application acts on behalf of a single member
  • The application modifies member information
  • The application needs access to protected member information

Authenticating Using Google Signin:

  1. Choose a method of Google sign-in. Some good options are:
  2. When the user has signed in successfully with Google, extract their accessToken and refreshToken
    • Using GoogleSignIn the information is stored in user.authentication
  3. Use those tokens to sign-in with the API swift DALIapi.signin(accessToken: accessToken, refreshToken: refreshToken) { (success, error) in if success { // Continue into the app // Your api will handle authenticated requests from here on } else if let error = error { // There was an error // Most likely the user didn't use a @dali.dartmouth.edu email } }

Althernate Method: Google OAuth2:

Some Google Signing sign-in systems (Not GoogleSignIn) may not sign the user in all the way, and instead of giving access and refresh tokens gives an authCode. In this case use DALIapi.signin(authCode: authCode) { ... }.

API Key Auth (Static-Installment)

A static-installment product could be an Apple TV app, a kiosk-type desktop application, or pretty much anything that doesn’t need user sign-in. Its up to your imagination 😀!

Qualifications:

  • The application does not act on behalf of any single member
  • The application does not need to modify member information

Authenticating Using API Key:

  1. Contact an API administrator to register for an API key to be made for your app.
    • The key’s access will be limited to the routes you need, but you can request more routes later if you need them
    • Keep the key you get secret! It is an all access pass to the routes you were granted
  2. Create a plist file (sample shown below) to store the key and add it to .gitignore envFile
  3. Load the file and load the config: swift let file = NSDictionary(contentsOfFile: "path/to/your/file.plist") let config = DALIConfig(dict: file)
  4. Configure the API with your credentials swift // ... let config = DALIConfig(dict: file) DALIapi.configure(config)

Done! Now you may make all the requests you are authorized to.

Events

Now that you have authenticated your system you can move on to Events. The event route is one of the simplest because it requires no special data and no requirements on authentication usage.

Get all events

DALIEvent.getAll { (events, error) in
  if let error = error {
    // Encountered a problem
    // Check the type;
    if error == DALIError.General.Unauthorized {
      // ...
    }else if ... {
      // ...
    }
    return
  }

  // The events list is a [DALIEvent]? object
}

Get events within a week of now

DALIEvent.getUpcoming { (events, error) in
  // ...
}

Create an event

DALIEvent.create { (success, error) in
  // ...
}

Location

DALI uses bluetooth beacon technology to identify when a device is in the lab. You can use this to gain access to the location flag (in DALI or not) for Tim or any other member.

Get Tim’s Location

DALILocation.Tim.get { (tim, error) in
  if let error = error {
    // Encountered error...
    return
  }

  if tim.inDALI {
    // ...
  }else if tim.inOffice {
    // ...
  }
}

Get shared users in DALI

DALILocation.Shared.get { (members, error) in
  if let error = error {
    //...
  }

  guard let members: [DALIMember] = members else {
    return
  }
  // ..
}

Installation

DALI is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "DALI"

Example

Example project is still in alpha

To run the example project, clone the repo, and run pod install from the Example directory first.

Author

John Kotz, john.kotz@dali.dartmouth.edu

Requirements

Usage Requirements

You must be a member of the DALI Lab or be working on behalf (with the permission) of the DALI Lab to use this pod. By using this cocoapod you acknowledge this requirement.

Dependencies
  • SwiftJSON
Function Specific Requirements

Some routes will intentionally crash your app if you use them without proper permission. Check out the docs on Protected Functions.

License

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