Skip to content

Commit e17e637

Browse files
Merge pull request #20 from appwrite/dev
updated to support 1.0.0-RC1
2 parents 42e094f + 6db12ba commit e17e637

Some content is hidden

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

42 files changed

+725
-718
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Redistribution and use in source and binary forms, with or without modification,
99

1010
3. Neither the name Appwrite nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
1111

12-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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-apple.svg?color=green&style=flat-square)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-apple.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-0.15.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.0.0-RC1-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 0.15.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-apple/releases).**
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-apple/releases).**
1111

1212
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Apple SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
1313

@@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies:
3131

3232
```swift
3333
dependencies: [
34-
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "0.6.0"),
34+
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "1.0.0-RC1"),
3535
],
3636
```
3737

Sources/Appwrite/Client.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ open class Client {
2020

2121
open var headers: [String: String] = [
2222
"content-type": "",
23-
"x-sdk-version": "appwrite:swiftclient:0.6.0",
24-
"X-Appwrite-Response-Format": "0.15.0"
23+
"x-sdk-name": "Apple",
24+
"x-sdk-platform": "client",
25+
"x-sdk-language": "swiftclient",
26+
"x-sdk-version": "1.0.0-RC1",
27+
"X-Appwrite-Response-Format": "1.0.0-RC1"
2528
]
2629

2730
open var config: [String: String] = [:]
@@ -387,15 +390,19 @@ open class Client {
387390

388391
if idParamName != nil && params[idParamName!] as! String != "unique()" {
389392
// Make a request to check if a file already exists
390-
let map = try! await call(
391-
method: "GET",
392-
path: path + "/" + (params[idParamName!] as! String),
393-
headers: headers,
394-
params: [:],
395-
converter: { return $0 }
396-
)
397-
let chunksUploaded = map["chunksUploaded"] as! Int
398-
offset = min(size, (chunksUploaded * Client.chunkSize))
393+
do {
394+
let map = try await call(
395+
method: "GET",
396+
path: path + "/" + (params[idParamName!] as! String),
397+
headers: headers,
398+
params: [:],
399+
converter: { return $0 }
400+
)
401+
let chunksUploaded = map["chunksUploaded"] as! Int
402+
offset = min(size, (chunksUploaded * Client.chunkSize))
403+
} catch {
404+
// File does not exist yet, swallow exception
405+
}
399406
}
400407

401408
while offset < size {

Sources/Appwrite/ID.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class ID {
2+
public static func custom(_ id: String) -> String {
3+
return id
4+
}
5+
6+
public static func unique() -> String {
7+
return "unique()"
8+
}
9+
}
File renamed without changes.

Sources/Appwrite/Models/Query.swift

Lines changed: 0 additions & 48 deletions
This file was deleted.

Sources/Appwrite/OAuth/WebAuthComponent.swift

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class WebAuthComponent {
2323
///
2424
/// Authenticate Session with OAuth2
2525
///
26-
/// Launches a chrome custom tab from the given activity and directs to the given url,
26+
/// Launches a browser window from your app and directs to the given url,
2727
/// suspending until the user returns to the app, at which point the given [onComplete] callback
2828
/// will run, passing the callback url from the intent used to launch the [CallbackActivity],
2929
/// or an [IllegalStateException] in the case the user closed the window or returned to the
@@ -62,12 +62,37 @@ public class WebAuthComponent {
6262
var domain = cookieParts["domain"]!
6363
domain.remove(at: domain.startIndex)
6464

65-
let cookie = HTTPClient.Cookie(
66-
name: cookieParts["key"]!,
67-
value: cookieParts["secret"]!
68-
)
69-
let cookieJson = try! cookie.toJson()
70-
UserDefaults.standard.set(cookieJson, forKey: "\(domain)-cookies")
65+
let key: String = cookieParts["key"]!
66+
let secret: String = cookieParts["secret"]!
67+
let path: String? = cookieParts["path"]
68+
let expires: String? = cookieParts["expires"]
69+
let maxAge: String? = cookieParts["maxAge"]
70+
let sameSite: String? = cookieParts["sameSite"]
71+
let httpOnly: Bool? = cookieParts.keys.contains("httpOnly")
72+
let secure: Bool? = cookieParts.keys.contains("secure")
73+
74+
var cookie = "\(key)=\(secret)"
75+
76+
if let path = path {
77+
cookie += "; path=\(path)"
78+
}
79+
if let expires = expires {
80+
cookie += "; expires=\(expires)"
81+
}
82+
if let maxAge = maxAge {
83+
cookie += "; max-age=\(maxAge)"
84+
}
85+
if let sameSite = sameSite {
86+
cookie += "; sameSite=\(sameSite)"
87+
}
88+
if let httpOnly = httpOnly, httpOnly {
89+
cookie += "; httpOnly"
90+
}
91+
if let secure = secure, secure {
92+
cookie += "; secure"
93+
}
94+
95+
UserDefaults.standard.set([cookie], forKey: "\(domain)-cookies")
7196

7297
WebAuthComponent.onCallback(
7398
scheme: components.scheme!,

Sources/Appwrite/Permission.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class Permission {
2+
public static func read(_ role: String) -> String {
3+
return "read(\"\(role)\")"
4+
}
5+
6+
public static func write(_ role: String) -> String {
7+
return "write(\"\(role)\")"
8+
}
9+
10+
public static func create(_ role: String) -> String {
11+
return "create(\"\(role)\")"
12+
}
13+
14+
public static func update(_ role: String) -> String {
15+
return "update(\"\(role)\")"
16+
}
17+
18+
public static func delete(_ role: String) -> String {
19+
return "delete(\"\(role)\")"
20+
}
21+
}

Sources/Appwrite/Query.swift

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
public class Query {
2+
3+
public static func equal(_ attribute: String, value: Any) -> String {
4+
buildQueryWhere(attribute, is: "equal", to: value)
5+
}
6+
7+
public static func notEqual(_ attribute: String, value: Any) -> String {
8+
buildQueryWhere(attribute, is: "notEqual", to: value)
9+
}
10+
11+
public static func lessThan(_ attribute: String, value: Any) -> String {
12+
buildQueryWhere(attribute, is: "lessThan", to: value)
13+
}
14+
15+
public static func lessThanEqual(attribute: String, value: Any) -> String {
16+
buildQueryWhere(attribute, is: "lessThanEqual", to: value)
17+
}
18+
19+
public static func greaterThan(_ attribute: String, value: Any) -> String {
20+
buildQueryWhere(attribute, is: "greaterThan", to: value)
21+
}
22+
23+
public static func greaterThanEqual(_ attribute: String, value: Any) -> String {
24+
buildQueryWhere(attribute, is: "greaterThanEqual", to: value)
25+
}
26+
27+
public static func search(_ attribute: String, value: String) -> String {
28+
buildQueryWhere(attribute, is: "search", to: value)
29+
}
30+
31+
public static func orderAsc(_ attribute: String) -> String {
32+
"orderAsc(\"\(attribute)\")"
33+
}
34+
35+
public static func orderDesc(_ attribute: String) -> String {
36+
"orderDesc(\"\(attribute)\")"
37+
}
38+
39+
public static func cursorBefore(_ id: String) -> String {
40+
"cursorBefore(\"\(id)\")"
41+
}
42+
43+
public static func cursorAfter(_ id: String) -> String {
44+
"cursorAfter(\"\(id)\")"
45+
}
46+
47+
public static func limit(_ limit: Int) -> String {
48+
"limit(\(limit))"
49+
}
50+
51+
public static func offset(_ offset: Int) -> String {
52+
"offset(\(offset))"
53+
}
54+
55+
public static func buildQueryWhere(_ attribute: String, is method: String, to value: Any) -> String {
56+
switch value {
57+
case let value as Array<Any>:
58+
return "\(method)(\"\(attribute)\", [\(value.map { parseValues($0) }.joined(separator: ",") )])"
59+
default:
60+
return "\(method)(\"\(attribute)\", [\(parseValues(value))])"
61+
}
62+
}
63+
64+
private static func parseValues(_ value: Any) -> String {
65+
switch value {
66+
case let value as String:
67+
return "\"\(value)\""
68+
default:
69+
return "\(value)"
70+
}
71+
}
72+
}

Sources/Appwrite/Role.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public class Role {
2+
public static func any() -> String {
3+
return "any"
4+
}
5+
6+
public static func user(_ id: String) -> String {
7+
return "user:\(id)"
8+
}
9+
10+
public static func users() -> String {
11+
return "users"
12+
}
13+
14+
public static func guests() -> String {
15+
return "guests"
16+
}
17+
18+
public static func team(_ id: String, _ role: String = "") -> String {
19+
if(role.isEmpty) {
20+
return "team:\(id)"
21+
}
22+
return "team:\(id)/\(role)"
23+
}
24+
25+
public static func status(_ status: String) -> String {
26+
return "status:\(status)"
27+
}
28+
}

0 commit comments

Comments
 (0)