Skip to content

Commit 51f325b

Browse files
authored
Merge pull request #8 from appwrite/dev
update to appwrite 1.3.0
2 parents ffa40e3 + 97f76d6 commit 51f325b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1433
-936
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let package = Package(
77
platforms: [
88
.iOS("15.0"),
99
.macOS("11.0"),
10-
.watchOS("6.0"),
10+
.watchOS("7.0"),
1111
.tvOS("13.0"),
1212
],
1313
products: [

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

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

10-
**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).**
10+
**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).**
1111

1212
> 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)
1313
@@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies:
3333

3434
```swift
3535
dependencies: [
36-
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "1.2.2"),
36+
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "2.0.0"),
3737
],
3838
```
3939

Sources/Appwrite/Client.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open class Client {
2323
"x-sdk-name": "Swift",
2424
"x-sdk-platform": "server",
2525
"x-sdk-language": "swift",
26-
"x-sdk-version": "1.2.2",
26+
"x-sdk-version": "2.0.0",
2727
"X-Appwrite-Response-Format": "1.0.0"
2828
]
2929

@@ -597,10 +597,10 @@ extension Client {
597597
device = "\(info!.modelIdentifier) iOS/\(info!.systemVersion)"
598598
#elseif os(watchOS)
599599
let info = deviceInfo.watchOSInfo
600-
device = "\(info!.systemInfo.machine) watchOS/\(info!.systemVersion)"
600+
device = "\(info!.modelIdentifier) watchOS/\(info!.systemVersion)"
601601
#elseif os(tvOS)
602-
let info = deviceInfo.tvOSInfo
603-
device = "\(info!.systemInfo.machine) tvOS/\(info!.systemVersion)"
602+
let info = deviceInfo.iOSInfo
603+
device = "\(info!.modelIdentifier) tvOS/\(info!.systemVersion)"
604604
#elseif os(macOS)
605605
let info = deviceInfo.macOSInfo
606606
device = "(Macintosh; \(info!.model))"
Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#if os(Linux)
22
import Foundation
33

4-
class LinuxDeviceInfo : DeviceInfo {
4+
class LinuxDeviceInfo {
55

66
let name: String
77
let version: String
@@ -14,53 +14,24 @@ class LinuxDeviceInfo : DeviceInfo {
1414
let variant: String
1515
let variantId: String
1616
let machineId: String
17-
18-
internal init(
19-
name: String,
20-
version: String,
21-
id: String,
22-
idLike: [String],
23-
versionCodename: String,
24-
versionId: String,
25-
prettyName: String,
26-
buildId: String,
27-
variant: String,
28-
variantId: String,
29-
machineId: String
30-
) {
31-
self.name = name
32-
self.version = version
33-
self.id = id
34-
self.idLike = idLike
35-
self.versionCodename = versionCodename
36-
self.versionId = versionId
37-
self.prettyName = prettyName
38-
self.buildId = buildId
39-
self.variant = variant
40-
self.variantId = variantId
41-
self.machineId = machineId
42-
}
43-
44-
public static func get() -> LinuxDeviceInfo {
45-
let os = getOsRelease()
46-
let lsb = getLsbRelease()
47-
let machineId = getMachineId()
48-
49-
return LinuxDeviceInfo(
50-
name: os["NAME"] ?? "Linux",
51-
version: os["VERSION"] ?? lsb["LSB_VERSION"] ?? "",
52-
id: os["ID"] ?? lsb["DISTRIB_ID"] ?? "linux",
53-
idLike: os["ID_LIKE"]?.split(separator: " ").map { String($0) } ?? [],
54-
versionCodename: os["VERSION_CODENAME"] ?? lsb["DISTRIB_CODENAME"] ?? "",
55-
versionId: os["VERSION_ID"] ?? lsb["DISTRIB_RELEASE"] ?? "",
56-
prettyName: os["PRETTY_NAME"] ?? lsb["DISTRIB_DESCRIPTION"] ?? "Linux",
57-
buildId: os["BUILD_ID"] ?? "",
58-
variant: os["VARIANT"] ?? "",
59-
variantId: os["VARIANT_ID"] ?? "",
60-
machineId: machineId
61-
)
17+
18+
public init() {
19+
let os = LinuxDeviceInfo.getOsRelease()
20+
let lsb = LinuxDeviceInfo.getLsbRelease()
21+
22+
name = os["NAME"] ?? "Linux"
23+
version = os["VERSION"] ?? lsb["LSB_VERSION"] ?? ""
24+
id = os["ID"] ?? lsb["DISTRIB_ID"] ?? "linux"
25+
idLike = os["ID_LIKE"]?.split(separator: " ").map { String($0) } ?? []
26+
versionCodename = os["VERSION_CODENAME"] ?? lsb["DISTRIB_CODENAME"] ?? ""
27+
versionId = os["VERSION_ID"] ?? lsb["DISTRIB_RELEASE"] ?? ""
28+
prettyName = os["PRETTY_NAME"] ?? lsb["DISTRIB_DESCRIPTION"] ?? "Linux"
29+
buildId = os["BUILD_ID"] ?? ""
30+
variant = os["VARIANT"] ?? ""
31+
variantId = os["VARIANT_ID"] ?? ""
32+
machineId = LinuxDeviceInfo.getMachineId()
6233
}
63-
34+
6435
private static func getOsRelease() -> [String: String] {
6536
return tryReadKeyValues(path: "/etc/os-release")
6637
}
@@ -82,19 +53,19 @@ class LinuxDeviceInfo : DeviceInfo {
8253
let url = URL(fileURLWithPath: path)
8354
let string = try! String(contentsOf: url, encoding: .utf8)
8455
let lines = string.components(separatedBy: .newlines)
85-
56+
8657
var dict = [String: String]()
8758
for line in lines {
8859
let splits = line.split(separator: "=")
8960
if splits.count > 1 {
9061
let key = String(splits[0])
9162
let value = String(splits[1])
92-
63+
9364
dict[key] = value
9465
}
9566
}
96-
67+
9768
return dict
9869
}
9970
}
100-
#endif
71+
#endif
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
#if os(macOS)
22
import Foundation
33

4-
class MacOSDeviceInfo : DeviceInfo {
5-
let computerName = Sysctl.hostName
6-
let hostName = Sysctl.osType
7-
let arch = Sysctl.machine
8-
let model = Sysctl.model
9-
let kernelVersion = Sysctl.version
10-
let osRelease = Sysctl.osRelease
11-
let activeCPUs = Sysctl.activeCPUs
12-
13-
public static func get() -> MacOSDeviceInfo {
14-
return MacOSDeviceInfo()
4+
class MacOSDeviceInfo {
5+
let computerName: String
6+
let hostName: String
7+
let arch: String
8+
let model: String
9+
let kernelVersion: String
10+
let osRelease: String
11+
let activeCPUs: Int
12+
13+
public init() {
14+
computerName = Sysctl.hostName
15+
hostName = Sysctl.osType
16+
arch = Sysctl.machine
17+
model = Sysctl.model
18+
kernelVersion = Sysctl.version
19+
osRelease = Sysctl.osRelease
20+
activeCPUs = Int(Sysctl.activeCPUs)
1521
}
1622
}
1723
#endif

Sources/Appwrite/DeviceInfo/OSDeviceInfo.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Foundation
22

3-
protocol DeviceInfo {}
4-
53
class OSDeviceInfo {
64

7-
#if os(iOS) || os(watchOS) || os(tvOS)
8-
var iOSInfo: iOSDeviceInfo?
5+
#if os(iOS) || os(tvOS)
6+
var iOSInfo: IOSDeviceInfo?
7+
#elseif os(watchOS)
8+
var watchOSInfo: WatchOSDeviceInfo?
99
#elseif os(macOS)
1010
var macOSInfo: MacOSDeviceInfo?
1111
#elseif os(Linux)
@@ -15,14 +15,16 @@ class OSDeviceInfo {
1515
#endif
1616

1717
init() {
18-
#if os(iOS) || os(watchOS) || os(tvOS)
19-
self.iOSInfo = iOSDeviceInfo.get()
18+
#if os(iOS) || os(tvOS)
19+
self.iOSInfo = IOSDeviceInfo()
20+
#elseif os(watchOS)
21+
self.watchOSInfo = WatchOSDeviceInfo()
2022
#elseif os(macOS)
21-
self.macOSInfo = MacOSDeviceInfo.get()
23+
self.macOSInfo = MacOSDeviceInfo()
2224
#elseif os(Linux)
23-
self.linuxInfo = LinuxDeviceInfo.get()
25+
self.linuxInfo = LinuxDeviceInfo()
2426
#elseif os(Windows)
25-
self.windowsInfo = LinuxDeviceInfo.get()
27+
self.windowsInfo = LinuxDeviceInfo()
2628
#endif
2729
}
2830
}
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
#if os(Windows)
22
import Foundation
33

4-
class WindowsDeviceInfo : DeviceInfo {
5-
4+
class WindowsDeviceInfo {
5+
66
let numberOfCores: String
77
let computerName: String
88
let systemMemoryInMegabytes: UInt64
9-
10-
public init(
11-
numberOfCores: String,
12-
computerName: String,
13-
systemMemoryInMegabytes: UInt64
14-
) {
15-
self.numberOfCores = numberOfCores
16-
self.computerName = computerName
17-
self.systemMemoryInMegabytes = systemMemoryInMegabytes
18-
}
199

20-
public static func get() -> WindowsDeviceInfo {
21-
let memory = ProcessInfo.processInfo.physicalMemory / 1000 / 1000 // Bytes to MB
22-
23-
return WindowsDeviceInfo(
24-
numberOfCores: ProcessInfo.processInfo.processorCount.description,
25-
computerName: Host.current().localizedName ?? "",
26-
systemMemoryInMegabytes: memory
27-
)
10+
public init() {
11+
numberOfCores = ProcessInfo.processInfo.processorCount.description
12+
computerName = Host.current().localizedName ?? ""
13+
systemMemoryInMegabytes = ProcessInfo.processInfo.physicalMemory / 1000 / 1000 // Bytes to MB
2814
}
2915
}
30-
#endif
31-
16+
#endif

Sources/Appwrite/DeviceInfo/iOS/UIDevice+ModelName.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if os(iOS) || os(tvOS) || os(watchOS)
1+
#if os(iOS) || os(tvOS)
22
import Foundation
33
import UIKit
44

@@ -14,8 +14,8 @@ public extension UIDevice {
1414
}
1515

1616
func mapToDevice(identifier: String) -> String { // swiftlint:disable:this cyclomatic_complexity
17-
#if os(iOS)
1817
switch identifier {
18+
#if os(iOS)
1919
case "iPod5,1": return "iPod touch (5th generation)"
2020
case "iPod7,1": return "iPod touch (6th generation)"
2121
case "iPod9,1": return "iPod touch (7th generation)"
@@ -49,6 +49,11 @@ public extension UIDevice {
4949
case "iPhone14,5": return "iPhone 13"
5050
case "iPhone14,2": return "iPhone 13 Pro"
5151
case "iPhone14,3": return "iPhone 13 Pro Max"
52+
case "iPhone14,6": return "iPhone SE (3rd generation)"
53+
case "iPhone14,7": return "iPhone 14"
54+
case "iPhone14,8": return "iPhone 14 Plus"
55+
case "iPhone15,2": return "iPhone 14 Pro"
56+
case "iPhone15,3": return "iPhone 14 Pro Max"
5257
case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4": return "iPad 2"
5358
case "iPad3,1", "iPad3,2", "iPad3,3": return "iPad (3rd generation)"
5459
case "iPad3,4", "iPad3,5", "iPad3,6": return "iPad (4th generation)"
@@ -77,21 +82,19 @@ public extension UIDevice {
7782
case "iPad8,5", "iPad8,6", "iPad8,7", "iPad8,8": return "iPad Pro (12.9-inch) (3rd generation)"
7883
case "iPad8,11", "iPad8,12": return "iPad Pro (12.9-inch) (4th generation)"
7984
case "iPad13,8", "iPad13,9", "iPad13,10", "iPad13,11":return "iPad Pro (12.9-inch) (5th generation)"
80-
case "AppleTV5,3": return "Apple TV"
81-
case "AppleTV6,2": return "Apple TV 4K"
82-
case "AudioAccessory1,1": return "HomePod"
83-
case "AudioAccessory5,1": return "HomePod mini"
8485
case "i386", "x86_64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))"
8586
default: return identifier
86-
}
8787
#elseif os(tvOS)
88-
switch identifier {
89-
case "AppleTV5,3": return "Apple TV 4"
90-
case "AppleTV6,2": return "Apple TV 4K"
88+
case "AppleTV1,1": return "Apple TV (1st generation)"
89+
case "AppleTV2,1": return "Apple TV (2nd generation)"
90+
case "AppleTV3,1", "AppleTV3,2": return "Apple TV (3rd generation)"
91+
case "AppleTV5,3": return "Apple TV (4th generation)"
92+
case "AppleTV6,2": return "Apple TV 4K (1st generation)"
93+
case "AppleTV11,1": return "Apple TV 4K (2nd generation)"
9194
case "i386", "x86_64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "tvOS"))"
9295
default: return identifier
93-
}
9496
#endif
97+
}
9598
}
9699

97100
return mapToDevice(identifier: identifier)
Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,27 @@
1-
#if os(iOS) || os(tvOS) || os(watchOS)
1+
#if os(iOS) || os(tvOS)
22
import Foundation
33
import UIKit
44

5-
class iOSDeviceInfo : DeviceInfo {
6-
5+
class IOSDeviceInfo {
6+
77
let name: String
88
let systemName: String
99
let systemVersion: String
1010
let model: String
1111
let localizedModel: String
1212
let identifierForVendor: String
1313
let modelIdentifier: String
14-
15-
internal init(
16-
name: String,
17-
systemName: String,
18-
systemVersion: String,
19-
model: String,
20-
localizedModel: String,
21-
identifierForVendor: String,
22-
modelIdentifier: String
23-
) {
24-
self.name = name
25-
self.systemName = systemName
26-
self.systemVersion = systemVersion
27-
self.model = model
28-
self.localizedModel = localizedModel
29-
self.identifierForVendor = identifierForVendor
30-
self.modelIdentifier = modelIdentifier
31-
}
3214

33-
public static func get() -> iOSDeviceInfo {
15+
public init() {
3416
let device = UIDevice.current
35-
36-
return iOSDeviceInfo(
37-
name: device.name,
38-
systemName: device.systemName,
39-
systemVersion: device.systemVersion,
40-
model: device.model,
41-
localizedModel: device.localizedModel,
42-
identifierForVendor: device.identifierForVendor?.uuidString ?? "",
43-
modelIdentifier: UIDevice.modelName
44-
)
17+
18+
name = device.name
19+
systemName = device.systemName
20+
systemVersion = device.systemVersion
21+
model = device.model
22+
localizedModel = device.localizedModel
23+
identifierForVendor = device.identifierForVendor?.uuidString ?? ""
24+
modelIdentifier = UIDevice.modelName
4525
}
4626
}
4727
#endif

0 commit comments

Comments
 (0)