diff --git a/README.md b/README.md index 0fdb34f..8bac16b 100644 --- a/README.md +++ b/README.md @@ -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 image + +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: "myemailaddress@example.com"), 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: "myemailaddress@example.com") +// "https://en.gravatar.com/0bc83cb571cd1c50ba6f3e8a78ef1346.json" +```