Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(routingv8): add billing tag to calculate matrix request #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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][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()
}

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