Skip to content

Commit

Permalink
feat(felixible aggregation): Add documentation for expression evaluat…
Browse files Browse the repository at this point in the history
…ion endpoint
  • Loading branch information
vincent-pochet committed Oct 24, 2024
1 parent a4b443d commit 4e22196
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions billable_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ type BillableMetric struct {
PlansCount int `json:"plans_count,omitempty"`
}

type BillableMetricEveluateExpressionEvent struct {
Code string `json:"code,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
Properties map[string]interface{} `json:"properties,omitempty"`
}

type BillableMetricEvaluateExpressionInput struct {
Expression string `json:"expression"`
Event BillableMetricEveluateExpressionEvent `json:"event"`
}

type BillableMetricEvaluateExpressionResultValue struct {
Value string `json:"value,omitempty"`
}

type BillableMetricEvaluateExpressionResult struct {
ExpressionResult BillableMetricEvaluateExpressionResultValue `json:"expression_result,omitempty"`
}

func (c *Client) BillableMetric() *BillableMetricRequest {
return &BillableMetricRequest{
client: c,
Expand Down Expand Up @@ -200,3 +219,23 @@ func (bmr *BillableMetricRequest) Delete(ctx context.Context, billableMetricCode

return billableMetricResult.BillableMetric, nil
}

func (bmr *BillableMetricRequest) EvaluateExpression(ctx context.Context, evaluateExpressingInput *BillableMetricEvaluateExpressionInput) (*BillableMetricEvaluateExpressionResultValue, *Error) {
clientRequest := &ClientRequest{
Path: "billable_metrics/evaluate_expression",
Result: &BillableMetricEvaluateExpressionResult{},
Body: evaluateExpressingInput,
}

result, err := bmr.client.Post(ctx, clientRequest)
if err != nil {
return nil, err
}

evaluateExpressionResult, ok := result.(*BillableMetricEvaluateExpressionResult)
if !ok {
return nil, &ErrorTypeAssert
}

return &evaluateExpressionResult.ExpressionResult, nil
}

0 comments on commit 4e22196

Please sign in to comment.