Skip to content

mbernson/UntappdKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UntappdKit

A client for the Untappd API, written in Swift.

It was created during the Q42 hackathon w00tcamp for the Uncheckd app. Check it out!

Features

  • User authentication to Untappd using ASWebAuthenticationSession
  • Uses modern Swift concurrency (async/await)
  • Response validation with error handling, including typed errors
  • Request/response logging

Examples

Authentication

A helper class UntappdAuthenticationSession lets the user log in using their Untappd account.

A custom URL scheme must be defined by your app in order to receive the access token.

import Foundation
import UntappdKit

func signIn() async throws {
    let presentationAnchor = await MainActor.run { UIWindow() }
    let authProvider = await UntappdAuthenticationSession(
        clientID: "...",
        clientSecret: "...",
        redirectURL: URL(string: "myapp://authenticate")!,
        urlScheme: "myapp",
        presentationAnchor: presentationAnchor
    )
    let token = try await authProvider.authenticate()
    print("Received access token: \(token.accessToken)")
    // Store token in the Keychain
}

Fetching user beers

The UntappdClient is the main class for accessing the Untappd API.

The offset and limit, combined with the response.pagination property may be used to fetch multiple pages of responses.

func fetchUserBeers() async throws {
    let untappdClient = UntappdClient()
    // Optionally set a delegate here to provide the user's access token to Untappd:
    // untappdClient.delegate = self
    let response: UserBeersResponse = try await untappdClient.userBeers(username: "Fubaruba", offset: 0, limit: 50)
    print("Bram has \(response.totalCount) total beers checked in")
    for beerItem in response.beers.items {
        print("\(beerItem.beer.beerName) from \(beerItem.brewery.breweryName)")
        print("has \(beerItem.beer.beerAbv)% ABV")
    }
}

API calls that are implemented

Basics

  • Authentication

Feeds

  • Activity Feed
  • User Activity Feed
  • Venue Activity Feed
  • Beer Activity Feed
  • Brewery Activity Feed
  • Notifications

Info / Search

  • User Info
  • User Wish List
  • User Friends
  • User Badges
  • User Beers
  • Brewery Info
  • Beer Info
  • Venue Info
  • Beer Search
  • Brewery Search

Actions

  • Checkin
  • Toast / Un-toast
  • Pending Friends
  • Add Friend
  • Remove Friend
  • Accept Friend
  • Reject Friend
  • Add Comment
  • Remove Comment
  • Add to Wish List
  • Remove from Wish List

See the Untappd API docs for more info about the API calls.

Contributing

Pull requests are welcome, especially for implementing more of the API. I used QuickType to quickly reverse-engineer the codable models.

Version history

  • 28-11-2024: Initial open source release.
  • 22-11-2024: Initial version for the w00tcamp project Uncheckd

License

MIT licensed, see LICENSE.md.

About

A client for the Untappd API, written in Swift

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages