Skip to content

Commit 744b65f

Browse files
authored
Merge pull request #25 from appwrite/dev
Appwrite 1.2.0 support
2 parents bd999ae + 2640184 commit 744b65f

File tree

125 files changed

+2577
-4055
lines changed

Some content is hidden

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

125 files changed

+2577
-4055
lines changed

LICENSE

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

88
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
99

10-
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.
10+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
1111

1212
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-1.0.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.2.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.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.2.x. 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: "1.1.0"),
34+
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "1.2.0"),
3535
],
3636
```
3737

Sources/Appwrite/Client.swift

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ open class Client {
2222
"content-type": "",
2323
"x-sdk-name": "Apple",
2424
"x-sdk-platform": "client",
25-
"x-sdk-language": "swiftclient",
26-
"x-sdk-version": "1.1.0",
25+
"x-sdk-language": "apple",
26+
"x-sdk-version": "1.2.0",
2727
"X-Appwrite-Response-Format": "1.0.0"
2828
]
2929

@@ -252,7 +252,7 @@ open class Client {
252252
headers: [String: String] = [:],
253253
params: [String: Any?] = [:],
254254
sink: ((ByteBuffer) -> Void)? = nil,
255-
converter: (([String: Any]) -> T)? = nil
255+
converter: ((Any) -> T)? = nil
256256
) async throws -> T {
257257
let validParams = params.filter { $0.value != nil }
258258

@@ -293,7 +293,7 @@ open class Client {
293293
private func execute<T>(
294294
_ request: HTTPClientRequest,
295295
withSink bufferSink: ((ByteBuffer) -> Void)? = nil,
296-
converter: (([String: Any]) -> T)? = nil
296+
converter: ((Any) -> T)? = nil
297297
) async throws -> T {
298298
func complete(with response: HTTPClientResponse) async throws -> T {
299299
switch response.status.code {
@@ -358,7 +358,7 @@ open class Client {
358358
params: inout [String: Any?],
359359
paramName: String,
360360
idParamName: String? = nil,
361-
converter: (([String: Any]) -> T)? = nil,
361+
converter: ((Any) -> T)? = nil,
362362
onProgress: ((UploadProgress) -> Void)? = nil
363363
) async throws -> T {
364364
let input = params[paramName] as! InputFile
@@ -396,7 +396,7 @@ open class Client {
396396
path: path + "/" + (params[idParamName!] as! String),
397397
headers: headers,
398398
params: [:],
399-
converter: { return $0 }
399+
converter: { return $0 as! [String: Any] }
400400
)
401401
let chunksUploaded = map["chunksUploaded"] as! Int
402402
offset = min(size, (chunksUploaded * Client.chunkSize))
@@ -417,7 +417,7 @@ open class Client {
417417
path: path,
418418
headers: headers,
419419
params: params,
420-
converter: { return $0 }
420+
converter: { return $0 as! [String: Any] }
421421
)
422422

423423
offset += Client.chunkSize
@@ -446,7 +446,28 @@ open class Client {
446446
_ request: inout HTTPClientRequest,
447447
with params: [String: Any?] = [:]
448448
) throws {
449-
let json = try JSONSerialization.data(withJSONObject: params, options: [])
449+
var encodedParams = [String:Any]()
450+
451+
for (key, param) in params {
452+
if param is String
453+
|| param is Int
454+
|| param is Float
455+
|| param is Bool
456+
|| param is [String]
457+
|| param is [Int]
458+
|| param is [Float]
459+
|| param is [Bool]
460+
|| param is [String: Any]
461+
|| param is [Int: Any]
462+
|| param is [Float: Any]
463+
|| param is [Bool: Any] {
464+
encodedParams[key] = param
465+
} else {
466+
encodedParams[key] = try! (param as! Encodable).toJson()
467+
}
468+
}
469+
470+
let json = try JSONSerialization.data(withJSONObject: encodedParams, options: [])
450471

451472
request.body = .bytes(json)
452473
}

0 commit comments

Comments
 (0)