Skip to content

Commit

Permalink
feat(routingv8): add billing tag to calculate matrix request
Browse files Browse the repository at this point in the history
  • Loading branch information
blaberg committed Oct 9, 2024
1 parent c96b258 commit 8f20635
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions routingv8/calculatematrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import (
"fmt"
"net/http"
"net/url"
"regexp"
)

const billingTagPattern = "^(?![-])[A-Za-z0-9_-]{4,16}(?<![_-])"

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()
}

Expand All @@ -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)

Check failure on line 37 in routingv8/calculatematrix.go

View workflow job for this annotation

GitHub Actions / make

SA1000: error parsing regexp: invalid or unsupported Perl syntax: `(?!` (staticcheck)
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
Expand Down
2 changes: 2 additions & 0 deletions routingv8/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8f20635

Please sign in to comment.