Skip to content

Commit e7e2a2e

Browse files
authored
Merge pull request #5 from appwrite/dev
Appwrite 1.2.0 support
2 parents 57f125b + 3e45908 commit e7e2a2e

File tree

240 files changed

+5135
-8390
lines changed

Some content is hidden

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

240 files changed

+5135
-8390
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-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-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-swift/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-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.1.0"),
36+
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "1.2.0"),
3737
],
3838
```
3939

Sources/Appwrite/Client.swift

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

@@ -267,7 +267,7 @@ open class Client {
267267
headers: [String: String] = [:],
268268
params: [String: Any?] = [:],
269269
sink: ((ByteBuffer) -> Void)? = nil,
270-
converter: (([String: Any]) -> T)? = nil
270+
converter: ((Any) -> T)? = nil
271271
) async throws -> T {
272272
let validParams = params.filter { $0.value != nil }
273273

@@ -308,7 +308,7 @@ open class Client {
308308
private func execute<T>(
309309
_ request: HTTPClientRequest,
310310
withSink bufferSink: ((ByteBuffer) -> Void)? = nil,
311-
converter: (([String: Any]) -> T)? = nil
311+
converter: ((Any) -> T)? = nil
312312
) async throws -> T {
313313
func complete(with response: HTTPClientResponse) async throws -> T {
314314
switch response.status.code {
@@ -373,7 +373,7 @@ open class Client {
373373
params: inout [String: Any?],
374374
paramName: String,
375375
idParamName: String? = nil,
376-
converter: (([String: Any]) -> T)? = nil,
376+
converter: ((Any) -> T)? = nil,
377377
onProgress: ((UploadProgress) -> Void)? = nil
378378
) async throws -> T {
379379
let input = params[paramName] as! InputFile
@@ -411,7 +411,7 @@ open class Client {
411411
path: path + "/" + (params[idParamName!] as! String),
412412
headers: headers,
413413
params: [:],
414-
converter: { return $0 }
414+
converter: { return $0 as! [String: Any] }
415415
)
416416
let chunksUploaded = map["chunksUploaded"] as! Int
417417
offset = min(size, (chunksUploaded * Client.chunkSize))
@@ -432,7 +432,7 @@ open class Client {
432432
path: path,
433433
headers: headers,
434434
params: params,
435-
converter: { return $0 }
435+
converter: { return $0 as! [String: Any] }
436436
)
437437

438438
offset += Client.chunkSize
@@ -461,7 +461,28 @@ open class Client {
461461
_ request: inout HTTPClientRequest,
462462
with params: [String: Any?] = [:]
463463
) throws {
464-
let json = try JSONSerialization.data(withJSONObject: params, options: [])
464+
var encodedParams = [String:Any]()
465+
466+
for (key, param) in params {
467+
if param is String
468+
|| param is Int
469+
|| param is Float
470+
|| param is Bool
471+
|| param is [String]
472+
|| param is [Int]
473+
|| param is [Float]
474+
|| param is [Bool]
475+
|| param is [String: Any]
476+
|| param is [Int: Any]
477+
|| param is [Float: Any]
478+
|| param is [Bool: Any] {
479+
encodedParams[key] = param
480+
} else {
481+
encodedParams[key] = try! (param as! Encodable).toJson()
482+
}
483+
}
484+
485+
let json = try JSONSerialization.data(withJSONObject: encodedParams, options: [])
465486

466487
request.body = .bytes(json)
467488
}

0 commit comments

Comments
 (0)