-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
254d0aa
commit 2a55342
Showing
7 changed files
with
15 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# Appwrite Apple SDK | ||
|
||
![Cocoapods](https://img.shields.io/cocoapods/v/Appwrite.svg?color=green&style=flat-square) | ||
![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-apple.svg?color=green&style=flat-square) | ||
![License](https://img.shields.io/github/license/appwrite/sdk-for-apple.svg?style=flat-square) | ||
![Version](https://img.shields.io/badge/api%20version-0.11.0-blue.svg?style=flat-square) | ||
|
@@ -20,25 +19,19 @@ Appwrite is an open-source backend as a service server that abstract and simplif | |
|
||
The Appwrite Swift SDK is available via multiple package managers, including Swift Package Manager. In order to use the Appwrite Swift SDK from Xcode, select File > Swift Packages > **Add Package Dependency** | ||
|
||
>>IMAGE<< | ||
In the dialog that appears, enter the Appwrite Swift SDK [package URL]([email protected]:appwrite/sdk-for-apple.git) and click **Next**. | ||
|
||
Once the repository information is loaded, add your version rules and click **Next** again. | ||
|
||
>>IMAGE<< | ||
On the final screen, make sure you see `Appwrite` as a product selected for your target: | ||
|
||
>>IMAGE<< | ||
### Swift Package Manager | ||
|
||
Add the package to your `Package.swift` dependencies: | ||
|
||
```swift | ||
dependencies: [ | ||
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "0.1.0"), | ||
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "0.1.1"), | ||
], | ||
``` | ||
|
||
|
@@ -54,12 +47,6 @@ Then add it to your target: | |
), | ||
``` | ||
|
||
### Cocoapods | ||
|
||
```ruby | ||
pod '', git: '[email protected]:appwrite/sdk-for-apple.git', tag: '0.1.0' | ||
``` | ||
|
||
|
||
## Contribution | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
Sources/Appwrite/Extensions/HTTPClientRequest+Cookies.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
import AsyncHTTPClient | ||
import Foundation | ||
import NIO | ||
import NIOHTTP1 | ||
|
||
extension HTTPClient.Request { | ||
public mutating func addDomainCookies() { | ||
let cookieJson = UserDefaults.standard.string(forKey: "\(url.host!)-cookies") | ||
headers.addDomainCookies(for: url.host!) | ||
} | ||
} | ||
|
||
extension HTTPHeaders { | ||
public mutating func addDomainCookies(for domain: String) { | ||
let cookieJson = UserDefaults.standard.string(forKey: "\(domain)-cookies") | ||
let cookies: [HTTPClient.Cookie?]? = try? cookieJson?.fromJson(to: [HTTPClient.Cookie].self) | ||
?? [(try? cookieJson?.fromJson(to: HTTPClient.Cookie.self))] | ||
|
||
if let authCookie = cookies?.first(where: { $0?.name.starts(with: "a_session_") == true } ) { | ||
headers.add(name: "cookie", value: "\(authCookie!.name)=\(authCookie!.value)") | ||
add(name: "cookie", value: "\(authCookie!.name)=\(authCookie!.value)") | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,222 +1,5 @@ | ||
import XCTest | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
import Appwrite | ||
import AsyncHTTPClient | ||
import NIO | ||
|
||
class Tests: XCTestCase { | ||
|
||
override func setUp() { | ||
super.setUp() | ||
self.writeToFile(string: "Test Started") | ||
} | ||
|
||
override func tearDown() { | ||
super.tearDown() | ||
} | ||
|
||
func test() throws { | ||
let group = DispatchGroup() | ||
|
||
let client = Client() | ||
.setEndpointRealtime("wss://demo.appwrite.io/v1") | ||
.setProject("console") | ||
.addHeader(key: "Origin", value: "http://localhost") | ||
.setSelfSigned() | ||
|
||
let foo = Foo(client) | ||
let bar = Bar(client) | ||
let general = General(client) | ||
let realtime = Realtime(client) | ||
var realtimeResponse = "Realtime failed!" | ||
|
||
realtime.subscribe(channels: ["tests"]) { message in | ||
realtimeResponse = message.payload!["response"] as! String | ||
} | ||
|
||
// Foo Tests | ||
group.enter() | ||
foo.get(x: "string", y: 123, z: ["string in array"]) { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let mock): self.writeToFile(string: mock.result) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
group.enter() | ||
foo.post(x: "string", y: 123, z: ["string in array"]) { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let mock): self.writeToFile(string: mock.result) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
group.enter() | ||
foo.put(x: "string", y: 123, z: ["string in array"]) { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let mock): self.writeToFile(string: mock.result) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
group.enter() | ||
foo.patch(x: "string", y: 123, z: ["string in array"]) { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let mock): self.writeToFile(string: mock.result) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
group.enter() | ||
foo.delete(x: "string", y: 123, z: ["string in array"]) { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let mock): self.writeToFile(string: mock.result) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
|
||
// Bar Tests | ||
group.enter() | ||
bar.get(xrequired: "string", xdefault: 123, z: ["string in array"]) { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let mock): self.writeToFile(string: mock.result) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
group.enter() | ||
bar.post(xrequired: "string", xdefault: 123, z: ["string in array"]) { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let mock): self.writeToFile(string: mock.result) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
group.enter() | ||
bar.put(xrequired: "string", xdefault: 123, z: ["string in array"]) { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let mock): self.writeToFile(string: mock.result) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
group.enter() | ||
bar.patch(xrequired: "string", xdefault: 123, z: ["string in array"]) { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let mock): self.writeToFile(string: mock.result) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
group.enter() | ||
bar.delete(xrequired: "string", xdefault: 123, z: ["string in array"]) { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let mock): self.writeToFile(string: mock.result) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
|
||
// General Tests | ||
group.enter() | ||
general.redirect() { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let mock): self.writeToFile(string: (mock as! [String: Any])["result"] as! String) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
group.enter() | ||
|
||
let url = URL(fileURLWithPath: "\(FileManager.default.currentDirectoryPath)/../../resources/file.png") | ||
let buffer = ByteBuffer(data: try! Data(contentsOf: url)) | ||
let file = File(name: "file.png", buffer: buffer) | ||
general.upload(x: "string", y: 123, z: ["string in array"], file: file) { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let mock): self.writeToFile(string: mock.result) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
|
||
group.enter() | ||
general.error400() { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let error): self.writeToFile(string: error.message) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
group.enter() | ||
general.error500() { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let error): self.writeToFile(string: error.message) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
group.enter() | ||
general.error502() { result in | ||
switch result { | ||
case .failure(let error): self.writeToFile(string: error.message) | ||
case .success(let error): self.writeToFile(string: (error as! Error).message) | ||
} | ||
group.leave() | ||
} | ||
group.wait() | ||
|
||
self.writeToFile(string: realtimeResponse) | ||
} | ||
|
||
private func writeToFile(string: String) { | ||
let url = URL(fileURLWithPath: "\(FileManager.default.currentDirectoryPath)/../../../result.txt") | ||
try! string.appendLine(to: url) | ||
} | ||
} | ||
|
||
struct Response: Decodable { | ||
let result: String? | ||
let message: String? | ||
} | ||
|
||
extension String { | ||
func appendLine(to url: URL) throws { | ||
try self.appending("\n").append(to: url) | ||
} | ||
|
||
func append(to url: URL) throws { | ||
let data = self.data(using: .utf8) | ||
try data?.append(to: url) | ||
} | ||
} | ||
|
||
extension Data { | ||
func append(to url: URL) throws { | ||
if let fileHandle = try? FileHandle(forWritingTo: url) { | ||
defer { | ||
fileHandle.closeFile() | ||
} | ||
fileHandle.seekToEndOfFile() | ||
fileHandle.write(self) | ||
} else { | ||
try write(to: url) | ||
} | ||
} | ||
} |