|
| 1 | +# API Documentation |
| 2 | + |
| 3 | +This document provides an overview of the packages and APIs available in the Go implementation of Export_Trakt_4_Letterboxd. |
| 4 | + |
| 5 | +## Package Structure |
| 6 | + |
| 7 | +The application is organized into the following packages: |
| 8 | + |
| 9 | +``` |
| 10 | +/cmd |
| 11 | + /export_trakt - Main application entry point |
| 12 | +/pkg |
| 13 | + /api - Trakt.tv API client |
| 14 | + /config - Configuration loading and validation |
| 15 | + /export - Letterboxd export functionality |
| 16 | + /i18n - Internationalization support |
| 17 | + /logger - Logging system |
| 18 | +``` |
| 19 | + |
| 20 | +## Config Package |
| 21 | + |
| 22 | +The `config` package handles loading, parsing, and validating application configuration from TOML files. |
| 23 | + |
| 24 | +### Types |
| 25 | + |
| 26 | +#### `Config` |
| 27 | + |
| 28 | +The main configuration structure that contains all configuration options. |
| 29 | + |
| 30 | +```go |
| 31 | +type Config struct { |
| 32 | + Trakt TraktConfig `toml:"trakt"` |
| 33 | + Letterboxd LetterboxdConfig `toml:"letterboxd"` |
| 34 | + Export ExportConfig `toml:"export"` |
| 35 | + Logging LoggingConfig `toml:"logging"` |
| 36 | + I18n I18nConfig `toml:"i18n"` |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +### Functions |
| 41 | + |
| 42 | +#### `LoadConfig` |
| 43 | + |
| 44 | +```go |
| 45 | +func LoadConfig(path string) (*Config, error) |
| 46 | +``` |
| 47 | + |
| 48 | +Loads and parses a TOML configuration file from the specified path. |
| 49 | + |
| 50 | +#### `Validate` |
| 51 | + |
| 52 | +```go |
| 53 | +func (c *Config) Validate() error |
| 54 | +``` |
| 55 | + |
| 56 | +Validates that the configuration meets all requirements. |
| 57 | + |
| 58 | +## Logger Package |
| 59 | + |
| 60 | +The `logger` package provides a flexible logging system with support for different output targets and log levels. |
| 61 | + |
| 62 | +### Interfaces |
| 63 | + |
| 64 | +#### `Logger` |
| 65 | + |
| 66 | +```go |
| 67 | +type Logger interface { |
| 68 | + Info(messageID string, data ...map[string]interface{}) |
| 69 | + Infof(messageID string, data map[string]interface{}) |
| 70 | + Error(messageID string, data ...map[string]interface{}) |
| 71 | + Errorf(messageID string, data map[string]interface{}) |
| 72 | + Warn(messageID string, data ...map[string]interface{}) |
| 73 | + Warnf(messageID string, data map[string]interface{}) |
| 74 | + Debug(messageID string, data ...map[string]interface{}) |
| 75 | + Debugf(messageID string, data map[string]interface{}) |
| 76 | + SetLogLevel(level string) |
| 77 | + SetLogFile(path string) error |
| 78 | + SetTranslator(t Translator) |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +#### `Translator` |
| 83 | + |
| 84 | +```go |
| 85 | +type Translator interface { |
| 86 | + Translate(messageID string, templateData map[string]interface{}) string |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +### Functions |
| 91 | + |
| 92 | +#### `NewLogger` |
| 93 | + |
| 94 | +```go |
| 95 | +func NewLogger() Logger |
| 96 | +``` |
| 97 | + |
| 98 | +Creates a new logger instance with default settings. |
| 99 | + |
| 100 | +## API Package |
| 101 | + |
| 102 | +The `api` package handles communication with the Trakt.tv API. |
| 103 | + |
| 104 | +### Types |
| 105 | + |
| 106 | +#### `Client` |
| 107 | + |
| 108 | +The main client for interacting with the Trakt.tv API. |
| 109 | + |
| 110 | +```go |
| 111 | +type Client struct { |
| 112 | + // private fields |
| 113 | +} |
| 114 | +``` |
| 115 | + |
| 116 | +#### `Movie` |
| 117 | + |
| 118 | +```go |
| 119 | +type Movie struct { |
| 120 | + Movie MovieInfo `json:"movie"` |
| 121 | + LastWatchedAt string `json:"last_watched_at,omitempty"` |
| 122 | + Rating float64 `json:"rating,omitempty"` |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +### Functions |
| 127 | + |
| 128 | +#### `NewClient` |
| 129 | + |
| 130 | +```go |
| 131 | +func NewClient(cfg *config.Config, log logger.Logger) *Client |
| 132 | +``` |
| 133 | + |
| 134 | +Creates a new Trakt API client. |
| 135 | + |
| 136 | +#### `GetWatchedMovies` |
| 137 | + |
| 138 | +```go |
| 139 | +func (c *Client) GetWatchedMovies() ([]Movie, error) |
| 140 | +``` |
| 141 | + |
| 142 | +Retrieves the list of watched movies from Trakt.tv. |
| 143 | + |
| 144 | +## Export Package |
| 145 | + |
| 146 | +The `export` package provides functionality for exporting data to Letterboxd format. |
| 147 | + |
| 148 | +### Types |
| 149 | + |
| 150 | +#### `LetterboxdExporter` |
| 151 | + |
| 152 | +```go |
| 153 | +type LetterboxdExporter struct { |
| 154 | + // private fields |
| 155 | +} |
| 156 | +``` |
| 157 | + |
| 158 | +### Functions |
| 159 | + |
| 160 | +#### `NewLetterboxdExporter` |
| 161 | + |
| 162 | +```go |
| 163 | +func NewLetterboxdExporter(cfg *config.Config, log logger.Logger) *LetterboxdExporter |
| 164 | +``` |
| 165 | + |
| 166 | +Creates a new Letterboxd exporter. |
| 167 | + |
| 168 | +#### `ExportMovies` |
| 169 | + |
| 170 | +```go |
| 171 | +func (e *LetterboxdExporter) ExportMovies(movies []api.Movie) error |
| 172 | +``` |
| 173 | + |
| 174 | +Exports a list of movies to Letterboxd CSV format. |
| 175 | + |
| 176 | +## i18n Package |
| 177 | + |
| 178 | +The `i18n` package handles internationalization and localization. |
| 179 | + |
| 180 | +### Types |
| 181 | + |
| 182 | +#### `Translator` |
| 183 | + |
| 184 | +```go |
| 185 | +type Translator struct { |
| 186 | + // private fields |
| 187 | +} |
| 188 | +``` |
| 189 | + |
| 190 | +### Functions |
| 191 | + |
| 192 | +#### `NewTranslator` |
| 193 | + |
| 194 | +```go |
| 195 | +func NewTranslator(cfg *config.I18nConfig, log logger.Logger) (*Translator, error) |
| 196 | +``` |
| 197 | + |
| 198 | +Creates a new translator instance. |
| 199 | + |
| 200 | +#### `Translate` |
| 201 | + |
| 202 | +```go |
| 203 | +func (t *Translator) Translate(messageID string, templateData map[string]interface{}) string |
| 204 | +``` |
| 205 | + |
| 206 | +Returns the translated message for the given message ID. |
| 207 | + |
| 208 | +#### `SetLanguage` |
| 209 | + |
| 210 | +```go |
| 211 | +func (t *Translator) SetLanguage(lang string) |
| 212 | +``` |
| 213 | + |
| 214 | +Changes the current language for the translator. |
| 215 | + |
| 216 | +## Example Usage |
| 217 | + |
| 218 | +### Loading Configuration |
| 219 | + |
| 220 | +```go |
| 221 | +cfg, err := config.LoadConfig("config/config.toml") |
| 222 | +if err != nil { |
| 223 | + log.Fatalf("Failed to load configuration: %v", err) |
| 224 | +} |
| 225 | +``` |
| 226 | + |
| 227 | +### Setting Up Logging |
| 228 | + |
| 229 | +```go |
| 230 | +log := logger.NewLogger() |
| 231 | +log.SetLogLevel(cfg.Logging.Level) |
| 232 | +if cfg.Logging.File != "" { |
| 233 | + if err := log.SetLogFile(cfg.Logging.File); err != nil { |
| 234 | + log.Errorf("Failed to set log file: %v", err) |
| 235 | + } |
| 236 | +} |
| 237 | +``` |
| 238 | + |
| 239 | +### Using the API Client |
| 240 | + |
| 241 | +```go |
| 242 | +client := api.NewClient(cfg, log) |
| 243 | +movies, err := client.GetWatchedMovies() |
| 244 | +if err != nil { |
| 245 | + log.Errorf("Failed to get watched movies: %v", err) |
| 246 | + return |
| 247 | +} |
| 248 | +``` |
| 249 | + |
| 250 | +### Exporting Data |
| 251 | + |
| 252 | +```go |
| 253 | +exporter := export.NewLetterboxdExporter(cfg, log) |
| 254 | +if err := exporter.ExportMovies(movies); err != nil { |
| 255 | + log.Errorf("Failed to export movies: %v", err) |
| 256 | + return |
| 257 | +} |
| 258 | +``` |
| 259 | + |
| 260 | +### Internationalization |
| 261 | + |
| 262 | +```go |
| 263 | +translator, err := i18n.NewTranslator(&cfg.I18n, log) |
| 264 | +if err != nil { |
| 265 | + log.Errorf("Failed to initialize translator: %v", err) |
| 266 | + return |
| 267 | +} |
| 268 | + |
| 269 | +// Set translator for logger |
| 270 | +log.SetTranslator(translator) |
| 271 | + |
| 272 | +// Log with translation |
| 273 | +log.Info("app.starting", map[string]interface{}{"version": "1.0.0"}) |
| 274 | + |
| 275 | +// Get translated message |
| 276 | +message := translator.Translate("app.welcome", nil) |
| 277 | +fmt.Println(message) |
| 278 | +``` |
0 commit comments