Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Commit

Permalink
Added CKAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyKJohnson committed Jul 27, 2016
1 parent f3b8e4b commit 8804dcf
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 4 deletions.
47 changes: 47 additions & 0 deletions Sources/CKAccount.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// CKAccount.swift
// OpenCloudKit
//
// Created by Ben Johnson on 27/07/2016.
//
//

import Foundation

public enum CKAccountType {
case primary
case anoymous
case server
}

public struct CKAccount: CKAccountInfoProvider {

let accountType: CKAccountType

var isAnonymousAccount: Bool {
return accountType == .anoymous
}

var isServerAccount: Bool {
return accountType == .server
}

var containerInfo: CKContainerInfo

var iCloudAuthToken: String?

let cloudKitAuthToken: String

init(type: CKAccountType, containerInfo: CKContainerInfo, cloudKitAuthToken: String) {
self.accountType = type
self.containerInfo = containerInfo
self.cloudKitAuthToken = cloudKitAuthToken
}

init(containerInfo: CKContainerInfo,cloudKitAuthToken: String, iCloudAuthToken: String) {
self.accountType = .primary
self.containerInfo = containerInfo
self.iCloudAuthToken = iCloudAuthToken
}

}
Empty file modified Sources/CKCodable.swift
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions Sources/CKContainerConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ public struct CKContainerConfig {
}
}

extension CKContainerConfig {
var containerInfo: CKContainerInfo {
return CKContainerInfo(containerID: containerIdentifier, environment: environment)
}
}

public struct CKServerToServerKeyAuth {
// A unique identifier for the key generated using CloudKit Dashboard. To create this key, read
public let keyID: String
Expand Down
36 changes: 36 additions & 0 deletions Sources/CKModifyRecordsURLRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// CKModifyRecordsURLRequest.swift
// OpenCloudKit
//
// Created by Ben Johnson on 27/07/2016.
//
//

import Foundation

class CKModifyRecordsURLRequest: CKURLRequest {

var recordsToSave: [CKRecord]?

var recordIDsToDelete: [CKRecordID]?

var recordsByRecordIDs: [CKRecordID: CKRecord] = [:]

var atomic: Bool = true

var sendAllFields: Bool

init(recordsToSave: [CKRecord], recordIDsToDelete: [CKRecordID], sendAllFields: Bool) {

self.recordsToSave = recordsToSave
self.recordIDsToDelete = recordIDsToDelete
self.sendAllFields = sendAllFields

}






}
Empty file modified Sources/CKOperationMetrics.swift
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion Sources/CKPredicateReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct CKPredicateReader {

func consumeWhitespace(_ input: Index) -> Index? {
var index = input
while let (char, nextIndex) = source.takeCharacter(index) , char == " " {
while let (char, nextIndex) = source.takeCharacter(index) where char == " " {
index = nextIndex
}
return index
Expand Down
Empty file modified Sources/CKQueryFilter.swift
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion Sources/CKQueryOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class CKQueryOperation: CKDatabaseOperation {


let queryOperationURLRequest = CKQueryURLRequest(query: query!, cursor: cursor?.data as? Data, limit: resultsLimit, requestedFields: desiredKeys, zoneID: zoneID)

queryOperationURLRequest.accountInfoProvider = CloudKit.shared.defaultAccount

queryOperationURLRequest.completionBlock = { (result) in

Expand Down
2 changes: 1 addition & 1 deletion Sources/CKQueryURLRequest.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CKQueryURLRequest: CKURLRequest {
var parameters: [String: AnyObject] = [:]

let isZoneWide = false
if let zoneID = zoneID , zoneID.zoneName != CKRecordZoneDefaultName {
if let zoneID = zoneID where zoneID.zoneName != CKRecordZoneDefaultName {
// Add ZoneID Dictionary to parameters

}
Expand Down
2 changes: 1 addition & 1 deletion Sources/CKRecordZone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension CKRecordZone {

self.init(zoneID: zoneID)

if let isAtomic = dictionary["atomic"] as? Bool , isAtomic {
if let isAtomic = dictionary["atomic"] as? Bool where isAtomic {
capabilities = CKRecordZoneCapabilities.atomic
}
}
Expand Down
14 changes: 14 additions & 0 deletions Sources/OpenCloudKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class CloudKit {

public var environment: CKEnvironment = .development

public var defaultAccount: CKAccount!

public private(set) var containers: [CKContainerConfig] = []

public static let shared = CloudKit()
Expand All @@ -24,6 +26,18 @@ public class CloudKit {

public func configure(with configuration: CKConfig) {
self.containers = configuration.containers

// Setup DefaultAccount
let container = self.containers.first!
if serverAuth = container.serverToServerKeyAuth {
// Setup Server Account

defaultAccount = CKAccount(type: .Server, containerInfo: container.containerInfo, cloudKitAuthToken: container.serverToServerKeyAuth?.keyID)

} else if let apiTokenAuth = container.apiTokenAuth {
// Setup Anoymous Account
defaultAccount = CKAccount(type: .Anoymous, containerInfo: container.containerInfo, cloudKitAuthToken: apiTokenAuth)
}
}

func containerConfig(forContainer container: CKContainer) -> CKContainerConfig? {
Expand Down

0 comments on commit 8804dcf

Please sign in to comment.