Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
439 changes: 424 additions & 15 deletions DALI Lab.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions DALI Lab.xcodeproj/xcshareddata/xcschemes/Stickers.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,23 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "526A5F9D22ECB2D5001A96FA"
BuildableName = "DALITests.xctest"
BlueprintName = "DALITests"
ReferencedContainer = "container:DALI Lab.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "52E2F4331F853FEE00CED245"
BuildableName = "Stickers.appex"
BlueprintName = "Stickers"
BlueprintIdentifier = "52B138B51F47D4590021D7AE"
BuildableName = "iOS.app"
BlueprintName = "iOS"
ReferencedContainer = "container:DALI Lab.xcodeproj">
</BuildableReference>
</MacroExpansion>
Expand Down
10 changes: 10 additions & 0 deletions DALI Lab.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@
ReferencedContainer = "container:DALI Lab.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "526A5F9D22ECB2D5001A96FA"
BuildableName = "DALITests.xctest"
BlueprintName = "DALITests"
ReferencedContainer = "container:DALI Lab.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
Expand Down
50 changes: 50 additions & 0 deletions DALI/CheckOutRecord.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// CheckOutRecord.swift
// ChromaColorPicker
//
// Created by John Kotz on 12/22/18.
//

import Foundation
import FutureKit
import SwiftyJSON

extension DALIEquipment {
/**
A record of a peice of equipment being checked out
*/
final public class CheckOutRecord {
private var memberID: String?
/// The member that checked this out
public var member: DALIMember
/// The time it was checked out
public let startDate: Date
/// The time it was returned
public let endDate: Date?
/// The day the user anticipates returning the equipment
public let expectedReturnDate: Date?

/// Setup using json
internal init?(json: JSON) {
guard let dict = json.dictionary,
let startDateString = dict["startDate"]?.string,
let startDate = DALIEvent.dateFormatter().date(from: startDateString),
let memberJSON = dict["user"],
let member = DALIMember(json: memberJSON)
else {
return nil
}

let endDateString = dict["endDate"]?.string
let projectedEndDateString = dict["projectedEndDate"]?.string

let endDate = endDateString != nil ? DALIEvent.dateFormatter().date(from: endDateString!) : nil
let projectedEndDate = projectedEndDateString != nil ? DALIEvent.dateFormatter().date(from: projectedEndDateString!) : nil

self.member = member
self.startDate = startDate
self.endDate = endDate
self.expectedReturnDate = projectedEndDate
}
}
}
19 changes: 19 additions & 0 deletions DALI/DALI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// DALI.h
// DALI
//
// Created by John Kotz on 7/27/19.
// Copyright © 2019 BrunchLabs. All rights reserved.
//

#import <UIKit/UIKit.h>

//! Project version number for DALI.
FOUNDATION_EXPORT double DALIVersionNumber;

//! Project version string for DALI.
FOUNDATION_EXPORT const unsigned char DALIVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <DALI/PublicHeader.h>


132 changes: 132 additions & 0 deletions DALI/DALIConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//
// HandleConfigFile.swift
// DALIapi
//
// Created by John Kotz on 7/28/17.
// Copyright © 2017 DALI Lab. All rights reserved.
//

import Foundation
import SwiftyJSON

/**
Configurations for the DALIapi framework can be stored and handled using this

Example usage:

let file = NSDictionary(dictionary: [
"server_url": "https://dalilab-api.herokuapp.com/"
])
let config = DALIConfig(dict: file)
DALIapi.configure(config: config)
*/
open class DALIConfig: Codable {
/// The URL to the server. This is required
public var serverURL: String
/// Used to connect to the server without needing user signin
internal var apiKey: String?

/// Token. This is needed for requests when needing user signin
internal var token_stored: String?
public var token: String? {
/*
The token is stored in the UserDefaults so it can be recalled after the app is restarted
*/
get {
if let token_stored = token_stored {
return token_stored
}else if let token = UserDefaults.standard.string(forKey: "DALIapi:token") {
token_stored = token
return token
} else {
return nil
}
}
set {
self.token_stored = newValue
if let token = newValue {
UserDefaults.standard.set(token, forKey: "DALIapi:token")
} else {
UserDefaults.standard.removeObject(forKey: "DALIapi:token")
}
}
}

internal var serverURLobject: URL {
return URL(string: DALIapi.config.serverURL)!
}

/// The current member signed in
internal var member_stored: DALIMember?
internal var member: DALIMember? {
get {
if let member_stored = member_stored {
return member_stored
}else if let stored = UserDefaults.standard.data(forKey: "DALIapi:member"), let member = DALIMember(json: JSON(stored)) {
member_stored = member
return member
}
return nil
}
set {
self.member_stored = newValue
if let data = ((try? newValue?.json.rawData()) as Data??) {
UserDefaults.standard.set(data, forKey: "DALIapi:member")
}else if newValue == nil {
UserDefaults.standard.removeObject(forKey: "DALIapi:member")
}
}
}

/// A default value for the sharing preference
public var sharingDefault = true
private var enableSockets_internal = false
/// Allows to enable or disable the use of sockets
public var enableSockets: Bool {
get { return enableSockets_internal }
set { enableSockets_internal = newValue; if newValue { DALIapi.enableSockets() } else { DALIapi.disableSockets() } }
}
/// Enables automatic connecting and disconnecting of sockets when going between forground and background
public var socketAutoSwitching = true
public var forceWebsockets = false

/**
Creates a DALIConfig object

- parameter dict: A dictionary containing server_url
*/
public convenience init(dict: NSDictionary) {
guard let serverURL = dict["server_url"] as? String else {
fatalError("DALIConfig: Server URL Missing! Make sure server_url is in your config dictionary")
}

self.init(serverURL: serverURL, apiKey: dict["api_key"] as? String, enableSockets: dict["enableSockets"] as? Bool)
}

/**
Initializes the configuration with a server url and an API key

- parameter serverURL: The base URL for the server to use
- parameter apiKey: The key to use to authenticate requests
- parameter enableSockets: Allows sockets to be used
*/
public init(serverURL: String, apiKey: String? = nil, enableSockets: Bool? = true) {
self.serverURL = serverURL
self.apiKey = apiKey

if self.serverURL.last == "/" {
self.serverURL = String(self.serverURL[..<self.serverURL.endIndex])
}

self.enableSockets_internal = enableSockets ?? false
}

enum CodingKeys: String, CodingKey {
case serverURL
case apiKey
case socketAutoSwitching
case forceWebsockets
case sharingDefault
case enableSockets_internal
}
}
Loading