-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclient.go
67 lines (52 loc) · 1.58 KB
/
client.go
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
64
65
66
67
package usage
import (
"context"
"fmt"
livepeer "github.com/livepeer/go-api-client"
)
type Client struct {
opts ClientOptions
lp *livepeer.Client
bigquery BigQuery
}
type ClientOptions struct {
Livepeer livepeer.ClientOptions
BigQueryOptions
}
func NewClient(opts ClientOptions) (*Client, error) {
lp := livepeer.NewAPIClient(opts.Livepeer)
bqOpts := opts.BigQueryOptions
bigquery, err := NewBigQuery(bqOpts)
if err != nil {
return nil, fmt.Errorf("error creating bigquery client: %w", err)
}
return &Client{opts, lp, bigquery}, nil
}
func (c *Client) QuerySummary(ctx context.Context, userID string, creatorID string, spec QuerySpec) (*UsageSummaryRow, error) {
summary, err := c.bigquery.QueryUsageSummary(ctx, userID, creatorID, spec)
if err != nil {
return nil, err
}
return summary, nil
}
func (c *Client) QuerySummaryWithTimestep(ctx context.Context, userID string, creatorID string, spec QuerySpec) (*[]UsageSummaryRow, error) {
summary, err := c.bigquery.QueryUsageSummaryWithTimestep(ctx, userID, creatorID, spec)
if err != nil {
return nil, err
}
return summary, nil
}
func (c *Client) QueryTotalSummary(ctx context.Context, spec FromToQuerySpec) (*[]TotalUsageSummaryRow, error) {
summary, err := c.bigquery.QueryTotalUsageSummary(ctx, spec)
if err != nil {
return nil, err
}
return summary, nil
}
func (c *Client) QueryActiveUsageSummary(ctx context.Context, spec FromToQuerySpec) (*[]ActiveUsersSummaryRow, error) {
summary, err := c.bigquery.QueryActiveUsersUsageSummary(ctx, spec)
if err != nil {
return nil, err
}
return summary, nil
}