Skip to content

Commit

Permalink
Merge pull request #8 from appwrite/dev
Browse files Browse the repository at this point in the history
update to appwrite 1.3.0
  • Loading branch information
abnegate authored Apr 12, 2023
2 parents ffa40e3 + 97f76d6 commit 51f325b
Show file tree
Hide file tree
Showing 50 changed files with 1,433 additions and 936 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
platforms: [
.iOS("15.0"),
.macOS("11.0"),
.watchOS("6.0"),
.watchOS("7.0"),
.tvOS("13.0"),
],
products: [
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-swift.svg?color=green&style=flat-square)
![License](https://img.shields.io/github/license/appwrite/sdk-for-swift.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.2.0-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.3.0-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

**This SDK is compatible with Appwrite server version 1.2.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-swift/releases).**
**This SDK is compatible with Appwrite server version 1.3.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-swift/releases).**

> This is the Swift SDK for integrating with Appwrite from your Swift server-side code. If you're looking for the Apple SDK you should check [appwrite/sdk-for-apple](https://github.com/appwrite/sdk-for-apple)
Expand All @@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies:

```swift
dependencies: [
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "1.2.2"),
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "2.0.0"),
],
```

Expand Down
8 changes: 4 additions & 4 deletions Sources/Appwrite/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ open class Client {
"x-sdk-name": "Swift",
"x-sdk-platform": "server",
"x-sdk-language": "swift",
"x-sdk-version": "1.2.2",
"x-sdk-version": "2.0.0",
"X-Appwrite-Response-Format": "1.0.0"
]

Expand Down Expand Up @@ -597,10 +597,10 @@ extension Client {
device = "\(info!.modelIdentifier) iOS/\(info!.systemVersion)"
#elseif os(watchOS)
let info = deviceInfo.watchOSInfo
device = "\(info!.systemInfo.machine) watchOS/\(info!.systemVersion)"
device = "\(info!.modelIdentifier) watchOS/\(info!.systemVersion)"
#elseif os(tvOS)
let info = deviceInfo.tvOSInfo
device = "\(info!.systemInfo.machine) tvOS/\(info!.systemVersion)"
let info = deviceInfo.iOSInfo
device = "\(info!.modelIdentifier) tvOS/\(info!.systemVersion)"
#elseif os(macOS)
let info = deviceInfo.macOSInfo
device = "(Macintosh; \(info!.model))"
Expand Down
73 changes: 22 additions & 51 deletions Sources/Appwrite/DeviceInfo/Linux/LinuxDeviceInfo.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if os(Linux)
import Foundation

class LinuxDeviceInfo : DeviceInfo {
class LinuxDeviceInfo {

let name: String
let version: String
Expand All @@ -14,53 +14,24 @@ class LinuxDeviceInfo : DeviceInfo {
let variant: String
let variantId: String
let machineId: String

internal init(
name: String,
version: String,
id: String,
idLike: [String],
versionCodename: String,
versionId: String,
prettyName: String,
buildId: String,
variant: String,
variantId: String,
machineId: String
) {
self.name = name
self.version = version
self.id = id
self.idLike = idLike
self.versionCodename = versionCodename
self.versionId = versionId
self.prettyName = prettyName
self.buildId = buildId
self.variant = variant
self.variantId = variantId
self.machineId = machineId
}

public static func get() -> LinuxDeviceInfo {
let os = getOsRelease()
let lsb = getLsbRelease()
let machineId = getMachineId()

return LinuxDeviceInfo(
name: os["NAME"] ?? "Linux",
version: os["VERSION"] ?? lsb["LSB_VERSION"] ?? "",
id: os["ID"] ?? lsb["DISTRIB_ID"] ?? "linux",
idLike: os["ID_LIKE"]?.split(separator: " ").map { String($0) } ?? [],
versionCodename: os["VERSION_CODENAME"] ?? lsb["DISTRIB_CODENAME"] ?? "",
versionId: os["VERSION_ID"] ?? lsb["DISTRIB_RELEASE"] ?? "",
prettyName: os["PRETTY_NAME"] ?? lsb["DISTRIB_DESCRIPTION"] ?? "Linux",
buildId: os["BUILD_ID"] ?? "",
variant: os["VARIANT"] ?? "",
variantId: os["VARIANT_ID"] ?? "",
machineId: machineId
)

public init() {
let os = LinuxDeviceInfo.getOsRelease()
let lsb = LinuxDeviceInfo.getLsbRelease()

name = os["NAME"] ?? "Linux"
version = os["VERSION"] ?? lsb["LSB_VERSION"] ?? ""
id = os["ID"] ?? lsb["DISTRIB_ID"] ?? "linux"
idLike = os["ID_LIKE"]?.split(separator: " ").map { String($0) } ?? []
versionCodename = os["VERSION_CODENAME"] ?? lsb["DISTRIB_CODENAME"] ?? ""
versionId = os["VERSION_ID"] ?? lsb["DISTRIB_RELEASE"] ?? ""
prettyName = os["PRETTY_NAME"] ?? lsb["DISTRIB_DESCRIPTION"] ?? "Linux"
buildId = os["BUILD_ID"] ?? ""
variant = os["VARIANT"] ?? ""
variantId = os["VARIANT_ID"] ?? ""
machineId = LinuxDeviceInfo.getMachineId()
}

private static func getOsRelease() -> [String: String] {
return tryReadKeyValues(path: "/etc/os-release")
}
Expand All @@ -82,19 +53,19 @@ class LinuxDeviceInfo : DeviceInfo {
let url = URL(fileURLWithPath: path)
let string = try! String(contentsOf: url, encoding: .utf8)
let lines = string.components(separatedBy: .newlines)

var dict = [String: String]()
for line in lines {
let splits = line.split(separator: "=")
if splits.count > 1 {
let key = String(splits[0])
let value = String(splits[1])

dict[key] = value
}
}

return dict
}
}
#endif
#endif
28 changes: 17 additions & 11 deletions Sources/Appwrite/DeviceInfo/MacOS/MacOSDeviceInfo.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#if os(macOS)
import Foundation

class MacOSDeviceInfo : DeviceInfo {
let computerName = Sysctl.hostName
let hostName = Sysctl.osType
let arch = Sysctl.machine
let model = Sysctl.model
let kernelVersion = Sysctl.version
let osRelease = Sysctl.osRelease
let activeCPUs = Sysctl.activeCPUs

public static func get() -> MacOSDeviceInfo {
return MacOSDeviceInfo()
class MacOSDeviceInfo {
let computerName: String
let hostName: String
let arch: String
let model: String
let kernelVersion: String
let osRelease: String
let activeCPUs: Int

public init() {
computerName = Sysctl.hostName
hostName = Sysctl.osType
arch = Sysctl.machine
model = Sysctl.model
kernelVersion = Sysctl.version
osRelease = Sysctl.osRelease
activeCPUs = Int(Sysctl.activeCPUs)
}
}
#endif
20 changes: 11 additions & 9 deletions Sources/Appwrite/DeviceInfo/OSDeviceInfo.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Foundation

protocol DeviceInfo {}

class OSDeviceInfo {

#if os(iOS) || os(watchOS) || os(tvOS)
var iOSInfo: iOSDeviceInfo?
#if os(iOS) || os(tvOS)
var iOSInfo: IOSDeviceInfo?
#elseif os(watchOS)
var watchOSInfo: WatchOSDeviceInfo?
#elseif os(macOS)
var macOSInfo: MacOSDeviceInfo?
#elseif os(Linux)
Expand All @@ -15,14 +15,16 @@ class OSDeviceInfo {
#endif

init() {
#if os(iOS) || os(watchOS) || os(tvOS)
self.iOSInfo = iOSDeviceInfo.get()
#if os(iOS) || os(tvOS)
self.iOSInfo = IOSDeviceInfo()
#elseif os(watchOS)
self.watchOSInfo = WatchOSDeviceInfo()
#elseif os(macOS)
self.macOSInfo = MacOSDeviceInfo.get()
self.macOSInfo = MacOSDeviceInfo()
#elseif os(Linux)
self.linuxInfo = LinuxDeviceInfo.get()
self.linuxInfo = LinuxDeviceInfo()
#elseif os(Windows)
self.windowsInfo = LinuxDeviceInfo.get()
self.windowsInfo = LinuxDeviceInfo()
#endif
}
}
Expand Down
29 changes: 7 additions & 22 deletions Sources/Appwrite/DeviceInfo/Windows/WindowsDeviceInfo.swift
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
#if os(Windows)
import Foundation

class WindowsDeviceInfo : DeviceInfo {
class WindowsDeviceInfo {

let numberOfCores: String
let computerName: String
let systemMemoryInMegabytes: UInt64

public init(
numberOfCores: String,
computerName: String,
systemMemoryInMegabytes: UInt64
) {
self.numberOfCores = numberOfCores
self.computerName = computerName
self.systemMemoryInMegabytes = systemMemoryInMegabytes
}

public static func get() -> WindowsDeviceInfo {
let memory = ProcessInfo.processInfo.physicalMemory / 1000 / 1000 // Bytes to MB

return WindowsDeviceInfo(
numberOfCores: ProcessInfo.processInfo.processorCount.description,
computerName: Host.current().localizedName ?? "",
systemMemoryInMegabytes: memory
)
public init() {
numberOfCores = ProcessInfo.processInfo.processorCount.description
computerName = Host.current().localizedName ?? ""
systemMemoryInMegabytes = ProcessInfo.processInfo.physicalMemory / 1000 / 1000 // Bytes to MB
}
}
#endif

#endif
25 changes: 14 additions & 11 deletions Sources/Appwrite/DeviceInfo/iOS/UIDevice+ModelName.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if os(iOS) || os(tvOS) || os(watchOS)
#if os(iOS) || os(tvOS)
import Foundation
import UIKit

Expand All @@ -14,8 +14,8 @@ public extension UIDevice {
}

func mapToDevice(identifier: String) -> String { // swiftlint:disable:this cyclomatic_complexity
#if os(iOS)
switch identifier {
#if os(iOS)
case "iPod5,1": return "iPod touch (5th generation)"
case "iPod7,1": return "iPod touch (6th generation)"
case "iPod9,1": return "iPod touch (7th generation)"
Expand Down Expand Up @@ -49,6 +49,11 @@ public extension UIDevice {
case "iPhone14,5": return "iPhone 13"
case "iPhone14,2": return "iPhone 13 Pro"
case "iPhone14,3": return "iPhone 13 Pro Max"
case "iPhone14,6": return "iPhone SE (3rd generation)"
case "iPhone14,7": return "iPhone 14"
case "iPhone14,8": return "iPhone 14 Plus"
case "iPhone15,2": return "iPhone 14 Pro"
case "iPhone15,3": return "iPhone 14 Pro Max"
case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4": return "iPad 2"
case "iPad3,1", "iPad3,2", "iPad3,3": return "iPad (3rd generation)"
case "iPad3,4", "iPad3,5", "iPad3,6": return "iPad (4th generation)"
Expand Down Expand Up @@ -77,21 +82,19 @@ public extension UIDevice {
case "iPad8,5", "iPad8,6", "iPad8,7", "iPad8,8": return "iPad Pro (12.9-inch) (3rd generation)"
case "iPad8,11", "iPad8,12": return "iPad Pro (12.9-inch) (4th generation)"
case "iPad13,8", "iPad13,9", "iPad13,10", "iPad13,11":return "iPad Pro (12.9-inch) (5th generation)"
case "AppleTV5,3": return "Apple TV"
case "AppleTV6,2": return "Apple TV 4K"
case "AudioAccessory1,1": return "HomePod"
case "AudioAccessory5,1": return "HomePod mini"
case "i386", "x86_64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))"
default: return identifier
}
#elseif os(tvOS)
switch identifier {
case "AppleTV5,3": return "Apple TV 4"
case "AppleTV6,2": return "Apple TV 4K"
case "AppleTV1,1": return "Apple TV (1st generation)"
case "AppleTV2,1": return "Apple TV (2nd generation)"
case "AppleTV3,1", "AppleTV3,2": return "Apple TV (3rd generation)"
case "AppleTV5,3": return "Apple TV (4th generation)"
case "AppleTV6,2": return "Apple TV 4K (1st generation)"
case "AppleTV11,1": return "Apple TV 4K (2nd generation)"
case "i386", "x86_64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "tvOS"))"
default: return identifier
}
#endif
}
}

return mapToDevice(identifier: identifier)
Expand Down
44 changes: 12 additions & 32 deletions Sources/Appwrite/DeviceInfo/iOS/iOSDeviceInfo.swift
Original file line number Diff line number Diff line change
@@ -1,47 +1,27 @@
#if os(iOS) || os(tvOS) || os(watchOS)
#if os(iOS) || os(tvOS)
import Foundation
import UIKit

class iOSDeviceInfo : DeviceInfo {
class IOSDeviceInfo {

let name: String
let systemName: String
let systemVersion: String
let model: String
let localizedModel: String
let identifierForVendor: String
let modelIdentifier: String

internal init(
name: String,
systemName: String,
systemVersion: String,
model: String,
localizedModel: String,
identifierForVendor: String,
modelIdentifier: String
) {
self.name = name
self.systemName = systemName
self.systemVersion = systemVersion
self.model = model
self.localizedModel = localizedModel
self.identifierForVendor = identifierForVendor
self.modelIdentifier = modelIdentifier
}

public static func get() -> iOSDeviceInfo {
public init() {
let device = UIDevice.current

return iOSDeviceInfo(
name: device.name,
systemName: device.systemName,
systemVersion: device.systemVersion,
model: device.model,
localizedModel: device.localizedModel,
identifierForVendor: device.identifierForVendor?.uuidString ?? "",
modelIdentifier: UIDevice.modelName
)

name = device.name
systemName = device.systemName
systemVersion = device.systemVersion
model = device.model
localizedModel = device.localizedModel
identifierForVendor = device.identifierForVendor?.uuidString ?? ""
modelIdentifier = UIDevice.modelName
}
}
#endif
Loading

0 comments on commit 51f325b

Please sign in to comment.