28ce79eff1
* feat(ooapi): add toplevel client and simplify API This diff should simplify using ooapi from other packages by adding more abstraction that wraps the existing code. Part of https://github.com/ooni/probe/issues/1355. * fix(ooapi): use correct comment for cloners See https://github.com/ooni/probe-cli/pull/248#discussion_r590663843 * fix(ooapi): make sure the documentation is current See https://github.com/ooni/probe-cli/pull/248#discussion_r590665773 * fix(ooapi): automate copying APIs See https://github.com/ooni/probe-cli/pull/248#discussion_r590665837 * feat(ooapi): add unit tests for clientcall.go See https://github.com/ooni/probe-cli/pull/248#discussion_r590666297 * fix(ooapi): rewrite integration tests to use toplevel API See https://github.com/ooni/probe-cli/pull/248#discussion_r590665084
277 lines
6.6 KiB
Go
277 lines
6.6 KiB
Go
// Code generated by go generate; DO NOT EDIT.
|
|
// 2021-03-10 13:17:35.43791782 +0100 CET m=+0.000136842
|
|
|
|
package ooapi
|
|
|
|
//go:generate go run ./internal/generator -file responses.go
|
|
|
|
import (
|
|
"io"
|
|
"io/ioutil"
|
|
"net/http"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/ooapi/apimodel"
|
|
)
|
|
|
|
func (api *simpleCheckReportIDAPI) newResponse(resp *http.Response, err error) (*apimodel.CheckReportIDResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.CheckReportIDResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleCheckInAPI) newResponse(resp *http.Response, err error) (*apimodel.CheckInResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.CheckInResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleLoginAPI) newResponse(resp *http.Response, err error) (*apimodel.LoginResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.LoginResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleMeasurementMetaAPI) newResponse(resp *http.Response, err error) (*apimodel.MeasurementMetaResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.MeasurementMetaResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleRegisterAPI) newResponse(resp *http.Response, err error) (*apimodel.RegisterResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.RegisterResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleTestHelpersAPI) newResponse(resp *http.Response, err error) (apimodel.TestHelpersResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := apimodel.TestHelpersResponse{}
|
|
if err := api.jsonCodec().Decode(data, &out); err != nil {
|
|
return nil, err
|
|
}
|
|
if out == nil {
|
|
return nil, ErrJSONLiteralNull
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simplePsiphonConfigAPI) newResponse(resp *http.Response, err error) (apimodel.PsiphonConfigResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := apimodel.PsiphonConfigResponse{}
|
|
if err := api.jsonCodec().Decode(data, &out); err != nil {
|
|
return nil, err
|
|
}
|
|
if out == nil {
|
|
return nil, ErrJSONLiteralNull
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleTorTargetsAPI) newResponse(resp *http.Response, err error) (apimodel.TorTargetsResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := apimodel.TorTargetsResponse{}
|
|
if err := api.jsonCodec().Decode(data, &out); err != nil {
|
|
return nil, err
|
|
}
|
|
if out == nil {
|
|
return nil, ErrJSONLiteralNull
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleURLsAPI) newResponse(resp *http.Response, err error) (*apimodel.URLsResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.URLsResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleOpenReportAPI) newResponse(resp *http.Response, err error) (*apimodel.OpenReportResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.OpenReportResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *simpleSubmitMeasurementAPI) newResponse(resp *http.Response, err error) (*apimodel.SubmitMeasurementResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.SubmitMeasurementResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|