Files
Michael Simard 1ade3b39ff Initial implementation of Fantasy Hockey watchOS app
Implemented complete TCA architecture for iOS and watchOS targets:
- Authentication flow (Sign in with Apple + Yahoo OAuth)
- OAuth token management with iCloud Key-Value Storage
- Yahoo Fantasy Sports API client with async/await
- Watch Connectivity for iPhone ↔ Watch data sync
- Complete UI for both iPhone and Watch platforms

Core features:
- Matchup score display
- Category breakdown with win/loss/tie indicators
- Roster status tracking
- Manual refresh functionality
- Persistent data caching on Watch

Technical stack:
- The Composable Architecture for state management
- Swift Concurrency (async/await, actors)
- WatchConnectivity framework
- Sign in with Apple
- OAuth 2.0 authentication flow

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-07 00:40:31 -06:00

90 lines
3.0 KiB
Swift

//
// YahooAPIClient.swift
// FantasyWatch
//
// Created by Claude Code
//
import Foundation
final class YahooAPIClient {
private let networkService: NetworkService
private let oauthManager: OAuthManager
private let baseURL = "https://fantasysports.yahooapis.com/fantasy/v2"
init(
networkService: NetworkService = DefaultNetworkService(),
oauthManager: OAuthManager
) {
self.networkService = networkService
self.oauthManager = oauthManager
}
func getUserTeams() async throws -> [Team] {
let token = try await oauthManager.validToken()
let data = try await networkService.request(
YahooEndpoint.userTeams,
baseURL: baseURL,
bearerToken: token
)
// NOTE: Yahoo API returns XML by default, even with format=json parameter
// For POC, we will need to parse the actual XML response
// This is a placeholder that will need proper XML parsing implementation
// based on the actual Yahoo API response structure
// For now, return mock data structure
// TODO: Implement proper XML parsing once we have real API responses
return try parseTeamsFromXML(data)
}
func getMatchup(teamKey: String) async throws -> Matchup {
let token = try await oauthManager.validToken()
let data = try await networkService.request(
YahooEndpoint.matchup(teamKey: teamKey),
baseURL: baseURL,
bearerToken: token
)
return try parseMatchupFromXML(data)
}
func getRoster(teamKey: String) async throws -> RosterStatus {
let token = try await oauthManager.validToken()
let data = try await networkService.request(
YahooEndpoint.roster(teamKey: teamKey),
baseURL: baseURL,
bearerToken: token
)
return try parseRosterFromXML(data)
}
// MARK: - XML Parsing Helpers
private func parseTeamsFromXML(_ data: Data) throws -> [Team] {
// TODO: Implement proper XML parsing
// This is a placeholder for POC
// The actual implementation will parse the Yahoo XML response structure
throw NetworkError.decodingError(
NSError(domain: "YahooAPI", code: -1, userInfo: [NSLocalizedDescriptionKey: "XML parsing not yet implemented"])
)
}
private func parseMatchupFromXML(_ data: Data) throws -> Matchup {
// TODO: Implement proper XML parsing
// This is a placeholder for POC
throw NetworkError.decodingError(
NSError(domain: "YahooAPI", code: -1, userInfo: [NSLocalizedDescriptionKey: "XML parsing not yet implemented"])
)
}
private func parseRosterFromXML(_ data: Data) throws -> RosterStatus {
// TODO: Implement proper XML parsing
// This is a placeholder for POC
throw NetworkError.decodingError(
NSError(domain: "YahooAPI", code: -1, userInfo: [NSLocalizedDescriptionKey: "XML parsing not yet implemented"])
)
}
}