notfall/vendor/github.com/sms77io/go-client/sms77api/analytics.go
kekskurse c9ab16b493
Some checks failed
continuous-integration/drone/push Build is failing
SMS
2022-01-16 13:30:48 +01:00

59 lines
1.5 KiB
Go

package sms77api
import (
"context"
"encoding/json"
)
type AnalyticsParams struct {
End string `json:"end,omitempty"`
GroupBy AnalyticsGroupBy `json:"group_by,omitempty"`
Label string `json:"label,omitempty"`
Start string `json:"start,omitempty"`
Subaccounts string `json:"subaccounts,omitempty"`
}
type Analytics struct {
Account *string `json:"account"`
Country *string `json:"country"`
Date *string `json:"date"`
Label *string `json:"label"`
Direct int `json:"direct"`
Economy int `json:"economy"`
Hlr int `json:"hlr"`
Inbound int `json:"inbound"`
Mnp int `json:"mnp"`
Voice int `json:"voice"`
UsageEur float64 `json:"usage_eur"`
}
type AnalyticsResource resource
type AnalyticsGroupBy string
const (
AnalyticsGroupByCountry AnalyticsGroupBy = "country"
AnalyticsGroupByDate AnalyticsGroupBy = "date"
AnalyticsGroupByLabel AnalyticsGroupBy = "label"
AnalyticsGroupBySubaccount AnalyticsGroupBy = "subaccount"
)
func (api *AnalyticsResource) Get(p *AnalyticsParams) (o []Analytics, err error) {
return api.GetContext(context.Background(), p)
}
func (api *AnalyticsResource) GetContext(ctx context.Context, p *AnalyticsParams) (o []Analytics, err error) {
res, err := api.client.request(ctx, "analytics", "GET", p)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(res), &o)
if nil != err {
return nil, err
}
return o, nil
}