Skip to content

Fix msg91 params #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2024
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![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.5.0-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.5.4-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)
Expand Down Expand Up @@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies:

```swift
dependencies: [
.package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "5.0.0"),
.package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "5.0.1"),
],
```

Expand Down
7 changes: 6 additions & 1 deletion Sources/Appwrite/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open class Client {
"x-sdk-name": "Swift",
"x-sdk-platform": "server",
"x-sdk-language": "swift",
"x-sdk-version": "5.0.0",
"x-sdk-version": "5.0.1",
"x-appwrite-response-format": "1.5.0"
]

Expand Down Expand Up @@ -643,6 +643,8 @@ extension Client {
return "tvos"
#elseif os(macOS)
return "macos"
#elseif os(visionOS)
return "visionos"
#elseif os(Linux)
return "linux"
#elseif os(Windows)
Expand All @@ -666,6 +668,9 @@ extension Client {
#elseif os(macOS)
let info = deviceInfo.macOSInfo
device = "(Macintosh; \(info!.model))"
#elseif os(visionOS)
let info = deviceInfo.iOSInfo
device = "\(info!.modelIdentifier) visionOS/\(info!.systemVersion)"
#elseif os(Linux)
let info = deviceInfo.linuxInfo
device = "(Linux; U; \(info!.id) \(info!.version))"
Expand Down
4 changes: 2 additions & 2 deletions Sources/Appwrite/DeviceInfo/OSDeviceInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

class OSDeviceInfo {

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
var iOSInfo: IOSDeviceInfo?
#elseif os(watchOS)
var watchOSInfo: WatchOSDeviceInfo?
Expand All @@ -15,7 +15,7 @@ class OSDeviceInfo {
#endif

init() {
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
self.iOSInfo = IOSDeviceInfo()
#elseif os(watchOS)
self.watchOSInfo = WatchOSDeviceInfo()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
import Foundation
import UIKit

Expand Down
12 changes: 8 additions & 4 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)
#if os(iOS) || os(tvOS) || os(visionOS)
import Foundation
import UIKit

Expand Down Expand Up @@ -82,7 +82,7 @@ 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 "i386", "x86_64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))"
case "i386", "x86_64", "arm64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))"
default: return identifier
#elseif os(tvOS)
case "AppleTV1,1": return "Apple TV (1st generation)"
Expand All @@ -91,8 +91,12 @@ public extension UIDevice {
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
case "i386", "x86_64", "arm64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "tvOS"))"
default: return identifier
#elseif os(visionOS)
case "RealityDevice14,1": return "Apple Vision Pro"
case "i386", "x86_64", "arm64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "visionOS"))"
default: return identifier
#endif
}
}
Expand Down
23 changes: 20 additions & 3 deletions Sources/Appwrite/ID.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import Foundation

public class ID {
// Generate an hex ID based on timestamp
// Recreated from https://www.php.net/manual/en/function.uniqid.php
private static func hexTimestamp() -> String {
let now = Date()
let secs = Int(now.timeIntervalSince1970)
let usec = Int((now.timeIntervalSince1970 - Double(secs)) * 1_000_000)
let hexTimestamp = String(format: "%08x%05x", secs, usec)
return hexTimestamp
}

public static func custom(_ id: String) -> String {
return id
}

public static func unique() -> String {
return "unique()"
// Generate a unique ID with padding to have a longer ID
public static func unique(padding: Int = 7) -> String {
let baseId = Self.hexTimestamp()
let randomPadding = (1...padding).map {
_ in String(format: "%x", Int.random(in: 0..<16))
}.joined()
return baseId + randomPadding
}
}
}
2 changes: 1 addition & 1 deletion Sources/Appwrite/PackageInfo/OSPackageInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
class OSPackageInfo {

public static func get() -> PackageInfo {
#if os(iOS) || os(watchOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(watchOS) || os(tvOS) || os(macOS) || os(visionOS)
return PackageInfo.getApplePackage()
#elseif os(Linux)
return PackageInfo.getLinuxPackage()
Expand Down
16 changes: 8 additions & 8 deletions Sources/Appwrite/Services/Messaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ open class Messaging: Service {
///
/// @param String providerId
/// @param String name
/// @param String from
/// @param String templateId
/// @param String senderId
/// @param String authKey
/// @param Bool enabled
Expand All @@ -967,7 +967,7 @@ open class Messaging: Service {
open func createMsg91Provider(
providerId: String,
name: String,
from: String? = nil,
templateId: String? = nil,
senderId: String? = nil,
authKey: String? = nil,
enabled: Bool? = nil
Expand All @@ -977,7 +977,7 @@ open class Messaging: Service {
let apiParams: [String: Any?] = [
"providerId": providerId,
"name": name,
"from": from,
"templateId": templateId,
"senderId": senderId,
"authKey": authKey,
"enabled": enabled
Expand Down Expand Up @@ -1008,29 +1008,29 @@ open class Messaging: Service {
/// @param String providerId
/// @param String name
/// @param Bool enabled
/// @param String templateId
/// @param String senderId
/// @param String authKey
/// @param String from
/// @throws Exception
/// @return array
///
open func updateMsg91Provider(
providerId: String,
name: String? = nil,
enabled: Bool? = nil,
templateId: String? = nil,
senderId: String? = nil,
authKey: String? = nil,
from: String? = nil
authKey: String? = nil
) async throws -> AppwriteModels.Provider {
let apiPath: String = "/messaging/providers/msg91/{providerId}"
.replacingOccurrences(of: "{providerId}", with: providerId)

let apiParams: [String: Any?] = [
"name": name,
"enabled": enabled,
"templateId": templateId,
"senderId": senderId,
"authKey": authKey,
"from": from
"authKey": authKey
]

let apiHeaders: [String: String] = [
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/messaging/create-msg91provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let messaging = Messaging(client)
let provider = try await messaging.createMsg91Provider(
providerId: "<PROVIDER_ID>",
name: "<NAME>",
from: "+12065550100", // optional
templateId: "<TEMPLATE_ID>", // optional
senderId: "<SENDER_ID>", // optional
authKey: "<AUTH_KEY>", // optional
enabled: false // optional
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/messaging/update-msg91provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ let provider = try await messaging.updateMsg91Provider(
providerId: "<PROVIDER_ID>",
name: "<NAME>", // optional
enabled: false, // optional
templateId: "<TEMPLATE_ID>", // optional
senderId: "<SENDER_ID>", // optional
authKey: "<AUTH_KEY>", // optional
from: "<FROM>" // optional
authKey: "<AUTH_KEY>" // optional
)