ooni-probe-cli/internal/engine/probeservices/checkreportid.go
Simone Basso 7b7df2c6af
refactor(httpx): improve and modernize (1/n) (#647)
This PR starts to implement the refactoring described at https://github.com/ooni/probe/issues/1951. I originally wrote more patches than the ones in this PR, but overall they were not readable. Since I want to squash and merge, here's a reasonable subset of the original patches that will still be readable and understandable in the future.
2022-01-05 12:48:32 +01:00

30 lines
685 B
Go

package probeservices
import (
"context"
"net/url"
"github.com/ooni/probe-cli/v3/internal/engine/httpx"
)
type checkReportIDResponse struct {
Found bool `json:"found"`
}
// CheckReportID checks whether the given ReportID exists.
func (c Client) CheckReportID(ctx context.Context, reportID string) (bool, error) {
query := url.Values{}
query.Add("report_id", reportID)
var response checkReportIDResponse
err := (&httpx.APIClient{
BaseURL: c.BaseURL,
HTTPClient: c.HTTPClient,
Logger: c.Logger,
UserAgent: c.UserAgent,
}).GetJSONWithQuery(ctx, "/api/_/check_report_id", query, &response)
if err != nil {
return false, err
}
return response.Found, nil
}