Initial commit
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package rudder
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
const DefaultBaseURL = "https://api.rudder.build"
|
||||
|
||||
type Config struct {
|
||||
APIKey string
|
||||
ProjectID string
|
||||
BaseURL string
|
||||
Timeout time.Duration
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
Players *PlayersService
|
||||
Metrics *MetricsService
|
||||
Leaderboards *LeaderboardsService
|
||||
Wallet *WalletService
|
||||
Ugc *UgcService
|
||||
}
|
||||
|
||||
func New(config Config) (*Client, error) {
|
||||
if config.APIKey == "" {
|
||||
return nil, &APIError{Code: ErrorCodeInvalidOptions, Message: "APIKey is required"}
|
||||
}
|
||||
if config.ProjectID == "" {
|
||||
return nil, &APIError{Code: ErrorCodeInvalidOptions, Message: "ProjectID is required"}
|
||||
}
|
||||
|
||||
if config.BaseURL == "" {
|
||||
config.BaseURL = DefaultBaseURL
|
||||
}
|
||||
if config.Timeout == 0 {
|
||||
config.Timeout = 30 * time.Second
|
||||
}
|
||||
if config.HTTPClient == nil {
|
||||
config.HTTPClient = &http.Client{Timeout: config.Timeout}
|
||||
}
|
||||
|
||||
transport := &transport{
|
||||
baseURL: config.BaseURL,
|
||||
apiKey: config.APIKey,
|
||||
projectID: config.ProjectID,
|
||||
httpClient: config.HTTPClient,
|
||||
}
|
||||
|
||||
return &Client{
|
||||
Players: &PlayersService{transport: transport},
|
||||
Metrics: &MetricsService{transport: transport},
|
||||
Leaderboards: &LeaderboardsService{transport: transport},
|
||||
Wallet: &WalletService{transport: transport},
|
||||
Ugc: &UgcService{transport: transport},
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user