-
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.
- Loading branch information
1 parent
cac9053
commit 917c0fc
Showing
1 changed file
with
34 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -6,10 +6,43 @@ | |
# SwiftGravatar | ||
A Swift library for Gravatar Profile data access. | ||
|
||
# Setup | ||
# How to Use | ||
|
||
Add the SwiftGravatar package to your project or via Package.swift using the address: | ||
|
||
https://github.com/RobertoMachorro/SwiftGravatar | ||
|
||
<img width="832" alt="image" src="https://github.com/RobertoMachorro/SwiftGravatar/assets/7190436/ba170546-30f6-482b-8c0d-eb4d055e8eaa"> | ||
|
||
Fetching the profile from the server can be done many ways, the easiest is to use the convenience function *GravatarProfile.getProfile*: | ||
|
||
```swift | ||
import SwiftGravatar | ||
|
||
if let profile = try await GravatarProfile.getProfile(using: "[email protected]"), let entry = profile.entry.first { | ||
print(entry.preferredUsername) | ||
print(entry.profileUrl) | ||
|
||
print(entry.thumbnailUrl) | ||
print(entry.photos?.first?.value) | ||
} else { | ||
print("We have a problem...") | ||
} | ||
``` | ||
|
||
Code can also be retrieved by other methods and then decoded: | ||
|
||
```swift | ||
guard let url = URL(string: "https://en.gravatar.com/632d2f3abe7be4db174da5cb2760f0ae.json") else { | ||
return XCTFail("Unable to parse Gravatar URL") | ||
} | ||
let (data, _) = try await URLSession.shared.data(from: url) | ||
let profile = try JSONDecoder().decode(GravatarProfile.self, from: data) | ||
``` | ||
|
||
An easy converter from e-mail to Gravatar URL can be accessed as follows: | ||
|
||
```swift | ||
let myemailaddress = GravatarProfile.getProfileAddress(using: "[email protected]") | ||
// "https://en.gravatar.com/0bc83cb571cd1c50ba6f3e8a78ef1346.json" | ||
``` |