-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.go
More file actions
63 lines (54 loc) · 1.88 KB
/
api.go
File metadata and controls
63 lines (54 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// ABOUTME: Shared API layer for web and CLI access to core functions
package main
import (
"context"
"fmt"
"time"
)
// APIClient provides access to core SleeperPy functionality
type APIClient struct {
provider LeagueProvider
}
// NewAPIClient creates a new API client
func NewAPIClient() *APIClient {
return &APIClient{provider: appProvider}
}
// FetchUser fetches a Sleeper user by username
func (a *APIClient) FetchUser(ctx context.Context, username string) (map[string]interface{}, error) {
return a.provider.FetchUser(username)
}
// FetchUserLeagues fetches leagues for a user ID
func (a *APIClient) FetchUserLeagues(ctx context.Context, userID string) ([]map[string]interface{}, error) {
return a.provider.FetchUserLeagues(userID, time.Now().Year())
}
// FetchBorisChenTiers fetches Boris Chen tiers for a scoring format
func (a *APIClient) FetchBorisChenTiers(ctx context.Context, scoring string) (map[string][][]string, error) {
tiers := fetchBorisTiersImpl(scoring)
if tiers == nil {
return nil, fmt.Errorf("failed to fetch tiers for format: %s", scoring)
}
return tiers, nil
}
// FetchDynastyValues fetches KTC dynasty values
func (a *APIClient) FetchDynastyValues(ctx context.Context) (map[string]interface{}, string, error) {
rawValues, scrapeDate := fetchDynastyValues()
if rawValues == nil {
return nil, "", fmt.Errorf("failed to fetch dynasty values")
}
// Convert to map[string]interface{} for CLI
values := make(map[string]interface{})
for name, val := range rawValues {
values[name] = map[string]interface{}{
"name": val.Name,
"position": val.Position,
"value_1qb": val.Value1QB,
"value_2qb": val.Value2QB,
"scrape_date": val.ScrapeDate,
}
}
return values, scrapeDate, nil
}
// FetchPlayers fetches all NFL players from Sleeper API
func (a *APIClient) FetchPlayers(ctx context.Context) (map[string]interface{}, error) {
return fetchPlayers()
}