Skip to content

Commit

Permalink
Completed How to Use in README.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoMachorro committed Jul 22, 2023
1 parent cac9053 commit 917c0fc
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```

0 comments on commit 917c0fc

Please sign in to comment.