Skip to content

Commit 4bd60e9

Browse files
Merge pull request #19 from appwrite/dev
Fix msg91 params
2 parents 91f314b + 23eef4b commit 4bd60e9

12 files changed

+51
-25
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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.5.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.5.4-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)
@@ -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: "5.0.0"),
36+
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "5.0.1"),
3737
],
3838
```
3939

Sources/Appwrite/Client.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ open class Client {
2121
"x-sdk-name": "Swift",
2222
"x-sdk-platform": "server",
2323
"x-sdk-language": "swift",
24-
"x-sdk-version": "5.0.0",
24+
"x-sdk-version": "5.0.1",
2525
"x-appwrite-response-format": "1.5.0"
2626
]
2727

@@ -643,6 +643,8 @@ extension Client {
643643
return "tvos"
644644
#elseif os(macOS)
645645
return "macos"
646+
#elseif os(visionOS)
647+
return "visionos"
646648
#elseif os(Linux)
647649
return "linux"
648650
#elseif os(Windows)
@@ -666,6 +668,9 @@ extension Client {
666668
#elseif os(macOS)
667669
let info = deviceInfo.macOSInfo
668670
device = "(Macintosh; \(info!.model))"
671+
#elseif os(visionOS)
672+
let info = deviceInfo.iOSInfo
673+
device = "\(info!.modelIdentifier) visionOS/\(info!.systemVersion)"
669674
#elseif os(Linux)
670675
let info = deviceInfo.linuxInfo
671676
device = "(Linux; U; \(info!.id) \(info!.version))"

Sources/Appwrite/DeviceInfo/OSDeviceInfo.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
class OSDeviceInfo {
44

5-
#if os(iOS) || os(tvOS)
5+
#if os(iOS) || os(tvOS) || os(visionOS)
66
var iOSInfo: IOSDeviceInfo?
77
#elseif os(watchOS)
88
var watchOSInfo: WatchOSDeviceInfo?
@@ -15,7 +15,7 @@ class OSDeviceInfo {
1515
#endif
1616

1717
init() {
18-
#if os(iOS) || os(tvOS)
18+
#if os(iOS) || os(tvOS) || os(visionOS)
1919
self.iOSInfo = IOSDeviceInfo()
2020
#elseif os(watchOS)
2121
self.watchOSInfo = WatchOSDeviceInfo()

Sources/Appwrite/DeviceInfo/iOS/iOSDeviceInfo.swift renamed to Sources/Appwrite/DeviceInfo/iOS/IOSDeviceInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if os(iOS) || os(tvOS)
1+
#if os(iOS) || os(tvOS) || os(visionOS)
22
import Foundation
33
import UIKit
44

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

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

@@ -82,7 +82,7 @@ public extension UIDevice {
8282
case "iPad8,5", "iPad8,6", "iPad8,7", "iPad8,8": return "iPad Pro (12.9-inch) (3rd generation)"
8383
case "iPad8,11", "iPad8,12": return "iPad Pro (12.9-inch) (4th generation)"
8484
case "iPad13,8", "iPad13,9", "iPad13,10", "iPad13,11":return "iPad Pro (12.9-inch) (5th generation)"
85-
case "i386", "x86_64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))"
85+
case "i386", "x86_64", "arm64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))"
8686
default: return identifier
8787
#elseif os(tvOS)
8888
case "AppleTV1,1": return "Apple TV (1st generation)"
@@ -91,8 +91,12 @@ public extension UIDevice {
9191
case "AppleTV5,3": return "Apple TV (4th generation)"
9292
case "AppleTV6,2": return "Apple TV 4K (1st generation)"
9393
case "AppleTV11,1": return "Apple TV 4K (2nd generation)"
94-
case "i386", "x86_64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "tvOS"))"
95-
default: return identifier
94+
case "i386", "x86_64", "arm64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "tvOS"))"
95+
default: return identifier
96+
#elseif os(visionOS)
97+
case "RealityDevice14,1": return "Apple Vision Pro"
98+
case "i386", "x86_64", "arm64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "visionOS"))"
99+
default: return identifier
96100
#endif
97101
}
98102
}

Sources/Appwrite/ID.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1+
import Foundation
2+
13
public class ID {
4+
// Generate an hex ID based on timestamp
5+
// Recreated from https://www.php.net/manual/en/function.uniqid.php
6+
private static func hexTimestamp() -> String {
7+
let now = Date()
8+
let secs = Int(now.timeIntervalSince1970)
9+
let usec = Int((now.timeIntervalSince1970 - Double(secs)) * 1_000_000)
10+
let hexTimestamp = String(format: "%08x%05x", secs, usec)
11+
return hexTimestamp
12+
}
13+
214
public static func custom(_ id: String) -> String {
315
return id
416
}
517

6-
public static func unique() -> String {
7-
return "unique()"
18+
// Generate a unique ID with padding to have a longer ID
19+
public static func unique(padding: Int = 7) -> String {
20+
let baseId = Self.hexTimestamp()
21+
let randomPadding = (1...padding).map {
22+
_ in String(format: "%x", Int.random(in: 0..<16))
23+
}.joined()
24+
return baseId + randomPadding
825
}
9-
}
26+
}

Sources/Appwrite/PackageInfo/OSPackageInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
class OSPackageInfo {
44

55
public static func get() -> PackageInfo {
6-
#if os(iOS) || os(watchOS) || os(tvOS) || os(macOS)
6+
#if os(iOS) || os(watchOS) || os(tvOS) || os(macOS) || os(visionOS)
77
return PackageInfo.getApplePackage()
88
#elseif os(Linux)
99
return PackageInfo.getLinuxPackage()

Sources/Appwrite/Services/Messaging.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ open class Messaging: Service {
957957
///
958958
/// @param String providerId
959959
/// @param String name
960-
/// @param String from
960+
/// @param String templateId
961961
/// @param String senderId
962962
/// @param String authKey
963963
/// @param Bool enabled
@@ -967,7 +967,7 @@ open class Messaging: Service {
967967
open func createMsg91Provider(
968968
providerId: String,
969969
name: String,
970-
from: String? = nil,
970+
templateId: String? = nil,
971971
senderId: String? = nil,
972972
authKey: String? = nil,
973973
enabled: Bool? = nil
@@ -977,7 +977,7 @@ open class Messaging: Service {
977977
let apiParams: [String: Any?] = [
978978
"providerId": providerId,
979979
"name": name,
980-
"from": from,
980+
"templateId": templateId,
981981
"senderId": senderId,
982982
"authKey": authKey,
983983
"enabled": enabled
@@ -1008,29 +1008,29 @@ open class Messaging: Service {
10081008
/// @param String providerId
10091009
/// @param String name
10101010
/// @param Bool enabled
1011+
/// @param String templateId
10111012
/// @param String senderId
10121013
/// @param String authKey
1013-
/// @param String from
10141014
/// @throws Exception
10151015
/// @return array
10161016
///
10171017
open func updateMsg91Provider(
10181018
providerId: String,
10191019
name: String? = nil,
10201020
enabled: Bool? = nil,
1021+
templateId: String? = nil,
10211022
senderId: String? = nil,
1022-
authKey: String? = nil,
1023-
from: String? = nil
1023+
authKey: String? = nil
10241024
) async throws -> AppwriteModels.Provider {
10251025
let apiPath: String = "/messaging/providers/msg91/{providerId}"
10261026
.replacingOccurrences(of: "{providerId}", with: providerId)
10271027

10281028
let apiParams: [String: Any?] = [
10291029
"name": name,
10301030
"enabled": enabled,
1031+
"templateId": templateId,
10311032
"senderId": senderId,
1032-
"authKey": authKey,
1033-
"from": from
1033+
"authKey": authKey
10341034
]
10351035

10361036
let apiHeaders: [String: String] = [

docs/examples/messaging/create-msg91provider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let messaging = Messaging(client)
1010
let provider = try await messaging.createMsg91Provider(
1111
providerId: "<PROVIDER_ID>",
1212
name: "<NAME>",
13-
from: "+12065550100", // optional
13+
templateId: "<TEMPLATE_ID>", // optional
1414
senderId: "<SENDER_ID>", // optional
1515
authKey: "<AUTH_KEY>", // optional
1616
enabled: false // optional

docs/examples/messaging/update-msg91provider.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ let provider = try await messaging.updateMsg91Provider(
1111
providerId: "<PROVIDER_ID>",
1212
name: "<NAME>", // optional
1313
enabled: false, // optional
14+
templateId: "<TEMPLATE_ID>", // optional
1415
senderId: "<SENDER_ID>", // optional
15-
authKey: "<AUTH_KEY>", // optional
16-
from: "<FROM>" // optional
16+
authKey: "<AUTH_KEY>" // optional
1717
)
1818

0 commit comments

Comments
 (0)