NewClient creates a new API client
(packageName string, timeout time.Duration)
| 40 | |
| 41 | // NewClient creates a new API client |
| 42 | func NewClient(packageName string, timeout time.Duration) (*Client, error) { |
| 43 | ctx := context.Background() |
| 44 | timeout = cli.ResolveTimeout(timeout) |
| 45 | |
| 46 | // Get credentials |
| 47 | creds, err := config.GetCredentials() |
| 48 | if err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | |
| 52 | // Create JWT config |
| 53 | jwtConfig, err := google.JWTConfigFromJSON(creds, androidpublisher.AndroidpublisherScope) |
| 54 | if err != nil { |
| 55 | return nil, fmt.Errorf("failed to parse credentials: %w", err) |
| 56 | } |
| 57 | |
| 58 | // Create HTTP client |
| 59 | httpClient := jwtConfig.Client(ctx) |
| 60 | |
| 61 | // Add debug transport if enabled |
| 62 | if config.IsDebug() { |
| 63 | httpClient.Transport = &debugTransport{base: httpClient.Transport} |
| 64 | } |
| 65 | |
| 66 | // Create service |
| 67 | service, err := androidpublisher.NewService(ctx, option.WithHTTPClient(httpClient)) |
| 68 | if err != nil { |
| 69 | return nil, fmt.Errorf("failed to create API client: %w", err) |
| 70 | } |
| 71 | |
| 72 | return &Client{ |
| 73 | service: service, |
| 74 | packageName: packageName, |
| 75 | timeout: timeout, |
| 76 | debug: config.IsDebug(), |
| 77 | }, nil |
| 78 | } |
| 79 | |
| 80 | // GetService returns the underlying Android Publisher service |
| 81 | func (c *Client) GetService() *androidpublisher.Service { |
no test coverage detected