-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added push method (#27) - Introduced push method to the main interface - Added simple Playground example (#34) Other: - Another (quick) README update (#30) - Removed do/catch blocks from the Grabber Closes #27 Closes #34 Fixes #30 Squashed commits: commit b2b6dbe commit 7196555
- Loading branch information
Showing
8 changed files
with
176 additions
and
82 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 |
---|---|---|
@@ -0,0 +1,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") | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
Guides/Examples/Fridge basics.playground/contents.xcplayground
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='ios' buildActiveScheme='true' executeOnSourceChanges='true' importAppTypes='true'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |
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
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