From 325239f605b79bdd071eab3236e61c74158e5a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Bl=C3=A5berg=20Kristoffersson?= Date: Wed, 9 Oct 2024 10:47:23 +0200 Subject: [PATCH] feat(routingv8): add billing tag to calculate matrix request For more information see: https://www.here.com/docs/bundle/cost-management-developer-guide/page/topics/tutorial-billing-tags.html --- routingv8/calculatematrix.go | 15 +++++++++++++++ routingv8/request.go | 2 ++ 2 files changed, 17 insertions(+) diff --git a/routingv8/calculatematrix.go b/routingv8/calculatematrix.go index fcf4783..f0651e3 100644 --- a/routingv8/calculatematrix.go +++ b/routingv8/calculatematrix.go @@ -6,11 +6,17 @@ import ( "fmt" "net/http" "net/url" + "regexp" ) +const billingTagPattern = "^[A-Za-z0-9][A-Za-z0-9_-]{2,14}[A-Za-z0-9]$" + func (c *CalculateMatrixRequest) QueryString() string { values := make(url.Values) values.Add("async", c.Async.String()) + if c.BillingTag != "" { + values.Add("billingTag", c.BillingTag) + } return values.Encode() } @@ -27,6 +33,15 @@ func (s *MatrixService) CalculateMatrix( err = fmt.Errorf("calculate matrix: %v", err) } }() + if req.BillingTag != "" { + matched, err := regexp.MatchString(billingTagPattern, req.BillingTag) + if err != nil { + return nil, err + } + if !matched { + return nil, fmt.Errorf("invalid billing tag") + } + } u, err := s.URL.Parse("matrix") if err != nil { return nil, err diff --git a/routingv8/request.go b/routingv8/request.go index ebecabb..7b48a2f 100644 --- a/routingv8/request.go +++ b/routingv8/request.go @@ -42,6 +42,8 @@ type CalculateMatrixRequest struct { // Async flag requires the Client to poll the calculation results and finally requesting to download // the calculation results. Async Async + // The billing tag provides a way to track your platform usage across components which track usage and costs. + BillingTag string // Body to pass to request to Here Maps API Body *CalculateMatrixBody }