Skip to content

Commit 6a3e923

Browse files
committed
Update for 1.0.0
1 parent f2be462 commit 6a3e923

File tree

87 files changed

+428
-231
lines changed

Some content is hidden

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

87 files changed

+428
-231
lines changed

README.md

Lines changed: 96 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.0.0-RC1-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.0.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.0.0-RC1. 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.0.0. 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.0.0-RC1"),
36+
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "1.0.0"),
3737
],
3838
```
3939

@@ -50,6 +50,99 @@ Then add it to your target:
5050
```
5151

5252

53+
## Getting Started
54+
55+
### Init your SDK
56+
57+
Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page and your new API secret Key project API keys section.
58+
59+
```swift
60+
import Appwrite
61+
62+
func main() {
63+
let client = Client()
64+
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
65+
.setProject("5df5acd0d48c2") // Your project ID
66+
.setKey("919c2d184...a2ae413dad2") // Your secret API key
67+
.setSelfSigned() // Use only on dev mode with a self-signed SSL cert
68+
}
69+
```
70+
71+
### Make Your First Request
72+
73+
Once your SDK object is initialized, create any of the Appwrite service objects and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section.
74+
75+
```swift
76+
let users = Users(client)
77+
78+
do {
79+
let user = try await users.create(
80+
userId: ID.unique(),
81+
email: "[email protected]",
82+
password: "password"
83+
)
84+
print(String(describing: user.toMap()))
85+
} catch {
86+
print(error.localizedDescription)
87+
}
88+
```
89+
90+
### Full Example
91+
92+
```swift
93+
import Appwrite
94+
95+
func main() {
96+
let client = Client()
97+
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
98+
.setProject("5df5acd0d48c2") // Your project ID
99+
.setKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
100+
.setSelfSigned() // Use only on dev mode with a self-signed SSL cert
101+
102+
let users = Users(client)
103+
104+
do {
105+
let user = try await users.create(
106+
userId: ID.unique(),
107+
email: "[email protected]",
108+
password: "password"
109+
)
110+
print(String(describing: user.toMap()))
111+
} catch {
112+
print(error.localizedDescription)
113+
}
114+
}
115+
```
116+
117+
### Error Handling
118+
119+
When an error occurs, the Appwrite Swift SDK throws an `AppwriteError` object with `message` and `code` properties. You can handle any errors in a catch block and present the `message` or `localizedDescription` to the user or handle it yourself based on the provided error information. Below is an example.
120+
121+
```swift
122+
import Appwrite
123+
124+
func main() {
125+
let users = Users(client)
126+
127+
do {
128+
let users = try await users.list()
129+
print(String(describing: users.toMap()))
130+
} catch {
131+
print(error.localizedDescription)
132+
}
133+
}
134+
```
135+
136+
### Learn more
137+
138+
You can use the following resources to learn more and get help
139+
140+
- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-server)
141+
- 📜 [Appwrite Docs](https://appwrite.io/docs)
142+
- 💬 [Discord Community](https://appwrite.io/discord)
143+
- 🚂 [Appwrite Swift Playground](https://github.com/appwrite/playground-for-swift-server)
144+
145+
53146
## Contribution
54147

55148
This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request.

Sources/Appwrite/Client.swift

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

3030
open var config: [String: String] = [:]

Sources/Appwrite/Role.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ public class Role {
33
return "any"
44
}
55

6-
public static func user(_ id: String) -> String {
7-
return "user:\(id)"
6+
public static func user(_ id: String, _ status: String = "") -> String {
7+
if(status.isEmpty) {
8+
return "user:\(id)"
9+
}
10+
return "user:\(id)/\(status)"
811
}
912

10-
public static func users() -> String {
11-
return "users"
13+
public static func users(_ status: String = "") -> String {
14+
if(status.isEmpty) {
15+
return "users"
16+
}
17+
return "users/\(status)"
1218
}
1319

1420
public static func guests() -> String {
@@ -22,6 +28,10 @@ public class Role {
2228
return "team:\(id)/\(role)"
2329
}
2430

31+
public static func member(_ id: String) -> String {
32+
return "member:\(id)"
33+
}
34+
2535
public static func status(_ status: String) -> String {
2636
return "status:\(status)"
2737
}

Sources/Appwrite/Services/Account.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ open class Account: Service {
7575
}
7676

7777
///
78-
/// Get Account Logs
78+
/// List Account Logs
7979
///
8080
/// Get currently logged in user list of latest security activity logs. Each
8181
/// log returns user IP address, location and date and time of log.
@@ -84,7 +84,7 @@ open class Account: Service {
8484
/// @throws Exception
8585
/// @return array
8686
///
87-
open func getLogs(
87+
open func listLogs(
8888
queries: [String]? = nil
8989
) async throws -> AppwriteModels.LogList {
9090
let path: String = "/account/logs"
@@ -369,15 +369,15 @@ open class Account: Service {
369369
}
370370

371371
///
372-
/// Get Account Sessions
372+
/// List Account Sessions
373373
///
374374
/// Get currently logged in user list of active sessions across different
375375
/// devices.
376376
///
377377
/// @throws Exception
378378
/// @return array
379379
///
380-
open func getSessions(
380+
open func listSessions(
381381
) async throws -> AppwriteModels.SessionList {
382382
let path: String = "/account/sessions"
383383
let params: [String: Any?] = [:]
@@ -767,7 +767,7 @@ open class Account: Service {
767767
}
768768

769769
///
770-
/// Get Account Logs
770+
/// List Account Logs
771771
///
772772
/// Get currently logged in user list of latest security activity logs. Each
773773
/// log returns user IP address, location and date and time of log.
@@ -777,13 +777,13 @@ open class Account: Service {
777777
/// @return array
778778
///
779779
@available(*, deprecated, message: "Use the async overload instead")
780-
open func getLogs(
780+
open func listLogs(
781781
queries: [String]? = nil,
782782
completion: ((Result<AppwriteModels.LogList, AppwriteError>) -> Void)? = nil
783783
) {
784784
Task {
785785
do {
786-
let result = try await getLogs(
786+
let result = try await listLogs(
787787
queries: queries
788788
)
789789
completion?(.success(result))
@@ -1014,7 +1014,7 @@ open class Account: Service {
10141014
}
10151015

10161016
///
1017-
/// Get Account Sessions
1017+
/// List Account Sessions
10181018
///
10191019
/// Get currently logged in user list of active sessions across different
10201020
/// devices.
@@ -1023,12 +1023,12 @@ open class Account: Service {
10231023
/// @return array
10241024
///
10251025
@available(*, deprecated, message: "Use the async overload instead")
1026-
open func getSessions(
1026+
open func listSessions(
10271027
completion: ((Result<AppwriteModels.SessionList, AppwriteError>) -> Void)? = nil
10281028
) {
10291029
Task {
10301030
do {
1031-
let result = try await getSessions(
1031+
let result = try await listSessions(
10321032
)
10331033
completion?(.success(result))
10341034
} catch {

0 commit comments

Comments
 (0)