NewReportingClient creates a new Reporting API client
(packageName string, timeout time.Duration)
| 22 | |
| 23 | // NewReportingClient creates a new Reporting API client |
| 24 | func NewReportingClient(packageName string, timeout time.Duration) (*ReportingClient, error) { |
| 25 | ctx := context.Background() |
| 26 | timeout = cli.ResolveTimeout(timeout) |
| 27 | |
| 28 | // Get credentials |
| 29 | creds, err := config.GetCredentials() |
| 30 | if err != nil { |
| 31 | return nil, err |
| 32 | } |
| 33 | |
| 34 | // Create JWT config with reporting scope |
| 35 | jwtConfig, err := google.JWTConfigFromJSON(creds, playdeveloperreporting.PlaydeveloperreportingScope) |
| 36 | if err != nil { |
| 37 | return nil, fmt.Errorf("failed to parse credentials: %w", err) |
| 38 | } |
| 39 | |
| 40 | // Create HTTP client |
| 41 | httpClient := jwtConfig.Client(ctx) |
| 42 | |
| 43 | // Add debug transport if enabled |
| 44 | if config.IsDebug() { |
| 45 | httpClient.Transport = &debugTransport{base: httpClient.Transport} |
| 46 | } |
| 47 | |
| 48 | // Create service |
| 49 | service, err := playdeveloperreporting.NewService(ctx, option.WithHTTPClient(httpClient)) |
| 50 | if err != nil { |
| 51 | return nil, fmt.Errorf("failed to create Reporting API client: %w", err) |
| 52 | } |
| 53 | |
| 54 | return &ReportingClient{ |
| 55 | service: service, |
| 56 | packageName: packageName, |
| 57 | timeout: timeout, |
| 58 | }, nil |
| 59 | } |
| 60 | |
| 61 | // Context returns a context with timeout |
| 62 | func (c *ReportingClient) Context() (context.Context, context.CancelFunc) { |
no test coverage detected