-
Notifications
You must be signed in to change notification settings - Fork 0
/
Contents.swift
54 lines (44 loc) · 1.37 KB
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import UIKit
import Fridge
//MARK: Grab example
let todoEndpoint = URL(string: "https://jsonplaceholder.typicode.com/todos/")!
struct ToDo: Decodable {
var id: Int
var title: String
var completed: Bool
}
async {
print("--> Grabbing all TODO objects...")
do {
let results: [ToDo] = try await Fridge.grab🔮(from: todoEndpoint)
// print all the results
for item in results {
print("ID:\(item.id) - \(item.title)")
}
print("|\nSuccessfully grabbed \(results.count) ToDO objects\n-----")
} catch {
print("Grab failed.")
}
}
//MARK: - Push example
struct Comment: Codable, CustomDebugStringConvertible {
let postId: Int
let id: Int
let name: String
let email: String
let body: String
var debugDescription: String {
return "[Comment] (ID:\(id)) \(name) - \(email). Body: \(body)"
}
}
async {
print("--> Posting new comment...")
do {
let newComment = Comment(postId: 12, id: 100, name: "New comment", email: "[email protected]", body: "Body of the new comment")
let response: Comment = try await Fridge.push📡(newComment, to: "https://jsonplaceholder.typicode.com/comments/")
print("New comment successfuly pushed.\nReturned (response) object:")
print(response)
} catch {
print("Push failed")
}
}