// DoRequest performs a HTTP request to the Authy API
351370
func (authy *Authy) DoRequest(method string, path string, params url.Values) (*http.Response, error) {
	apiURL := authy.buildURL(path)

	// Set api_key to all requests.
	params.Set("api_key", authy.APIKey)

	var bodyReader io.Reader
	switch method {
	case "POST":
		{
			encodedParams := params.Encode()
			bodyReader = strings.NewReader(encodedParams)
		}
	case "GET":
		{
			apiURL += "?" + params.Encode()
		}
	}

	request, err := http.NewRequest(method, apiURL, bodyReader)
	if method == "POST" {
		request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	}

	if err != nil {
		Logger.Println("Error creating HTTP request:", err)
		return nil, err
	}
	response, err := authy.Client.Do(request)

	return response, err
}
190192
func (c *Client) Do(m encoding.Marshaler, opt ...RequestOpt) (res mesos.Response, err error) {
	return c.Send(client.RequestSingleton(m), client.ResponseClassAuto, opt...)
}
684678
func (c *traceClient) Do(r *http.Request) (*http.Response, error) {
	InjectTrace(r)
	return c.Client.Do(r)
}
1039164
func (c *Client) Do(r *http.Request, v interface{}) error {
	var res *http.Response
	var err error
	if c.Client == nil {
		res, err = defaultHttpClient.Do(r)
	} else {
		res, err = c.Client.Do(r)
	}
	if err != nil {
		return err
	}
	defer res.Body.Close()
	if res.StatusCode >= 400 {
		if c.ErrorParser != nil {
			return c.ErrorParser(res)
		}
		return DefaultErrorParser(res)
	}

	resBody, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return err
	}
	if v == nil || res.StatusCode == http.StatusNoContent {
		return nil
	} else {
		return json.Unmarshal(resBody, v)
	}
}
815628
func (c *Client) DoRequest(r *request) (*http.Response, error) {
	req, err := r.toHTTP()
	if err != nil {
		return nil, err
	}
	for key, value := range r.header {
		req.Header.Add(key, value)
	}
	req.SetBasicAuth(c.config.Username, c.config.Password)
	req.Header.Add("User-Agent", "gogo-bosh")
	resp, err := c.config.HttpClient.Do(req)
	if err != nil {
		if strings.Contains(err.Error(), "oauth2: cannot fetch token") {
			c.refreshClient()
			resp, err = c.config.HttpClient.Do(req)
		}
	}
	return resp, err
}
1185692
func (c *Client) do(action string, params *url.Values, v *Response) error {
	// https://api.linode.com/?api_key={key}&api_action=test.echo&foo=bar
	if params == nil {
		params = &url.Values{}
	}
	params.Add("api_key", c.ApiKey)
	params.Add("api_action", action)
	return c.request(params, v)
}
759477
func (c *Client) doRequest(payload interface{}, responseData interface{}) error {
	body, err := json.Marshal(payload)
	if err != nil {
		return err
	}

	req, err := http.NewRequest(http.MethodPost, c.BaseURL, bytes.NewReader(body))
	if err != nil {
		return err
	}

	req.Close = true
	req.Header.Set("content-type", "application/json")

	resp, err := c.HTTPClient.Do(req)
	if err != nil {
		return err
	}

	if err = checkResponse(resp); err != nil {
		return err
	}

	respMsg, err := decodeResponseMsg(resp)
	if err != nil {
		return err
	}

	if respMsg.Status != success {
		return respMsg
	}

	if responseData != nil {
		err = json.Unmarshal(respMsg.ResponseData, responseData)
		if err != nil {
			return fmt.Errorf("%v: unmarshaling %T error: %v: %s",
				respMsg, responseData, err, string(respMsg.ResponseData))
		}
	}

	return nil
}
1211120
func do(req *http.Request, resType interface{}, returnHeaders bool) error {
	client := http.DefaultClient

	// Send request
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	// Only 500 errors will not respond a readable result
	if resp.StatusCode >= http.StatusInternalServerError {
		return ErrHTTPPushover
	}

	// Decode the JSON response
	if err := json.NewDecoder(resp.Body).Decode(&resType); err != nil {
		return err
	}

	// Check if the unmarshaled data is a response
	r, ok := resType.(*Response)
	if !ok {
		return nil
	}

	// Check response status
	if r.Status != 1 {
		return r.Errors
	}

	// The headers are only returned when posting a new notification
	if returnHeaders {
		// Get app limits from headers
		appLimits, err := newLimit(resp.Header)
		if err != nil {
			return err
		}
		r.Limit = appLimits
	}

	return nil
}
1306398
func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
	httpResp, err := c.client.Do(req)
	if err != nil {
		return nil, err
	}

	err = CheckResponse(httpResp)
	if err != nil {
		// Even though there was an error, we still return the response
		// in case the caller wants to inspect it further
		return newResponse(httpResp, nil), err
	}

	if v != nil {
		// Open a NewDecoder and defer closing the reader only if there is a provided interface to decode to
		defer httpResp.Body.Close()
		err = json.NewDecoder(httpResp.Body).Decode(v)
	}

	resp := newResponse(httpResp, v)
	return resp, err
}
397387
func (d RequestDoerFunc) Do(req *http.Request) (*http.Response, error) {
	return d(req)
}
225312
func (c *Client) DoAPIRequestWithAuth(remote string, req *http.Request) (*http.Response, error) {
	operation := getReqOperation(req)
	apiEndpoint := c.Endpoints.Endpoint(operation, remote)
	access := c.Endpoints.AccessFor(apiEndpoint.Url)
	return c.DoWithAuth(remote, access, req)
}
891133
func (r *Request) Do() (*Response, error) {
	if r.dispatched {
		return nil, errors.New("gentleman: Request was already dispatched")
	}

	r.dispatched = true
	ctx := NewDispatcher(r).Dispatch()

	return buildResponse(ctx)
}
611329
func (r *Request) Do() bool {
	if r.do != nil {
		return *r.do
	}

	r.do = new(bool)

	if o := r.Req.IsEdns0(); o != nil {
		*r.do = o.Do()
		return *r.do
	}
	*r.do = false
	return false
}
1036071
func (rt *DefaultRequestDoer) Do(ctx context.Context, r *http.Request,
	v interface{}) (*http.Response, error) {

	resp, err := rt.Client.Do(r)
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()

	err = checkResponseCode(resp)
	if err != nil {
		return resp, err
	}

	if v != nil {
		dec := json.NewDecoder(resp.Body)
		err = dec.Decode(v)
		if err != nil {
			return nil, err
		}
	}

	return resp, nil
}
368154
func (ac *AppClient) doReq(url string, req *omaha.Request) (*omaha.AppResponse, error) {
	if len(req.Apps) != 1 {
		panic(fmt.Errorf("unexpected number of apps: %d", len(req.Apps)))
	}
	appID := req.Apps[0].ID
	resp, err := ac.apiClient.Omaha(url, req)
	if err != nil {
		return nil, err
	}

	appResp := resp.GetApp(appID)
	if appResp == nil {
		return nil, &omahaError{
			Err:  fmt.Errorf("app %s missing from response", appID),
			Code: ExitCodeOmahaResponseInvalid,
		}
	}

	if appResp.Status != omaha.AppOK {
		return nil, appResp.Status
	}

	return appResp, nil
}
803256
func (f doFunc) Do(ctx context.Context, req *http.Request) (*http.Response, error) {
	return f(ctx, req)
}
391093
func (r *Request) Do(method string) *Response {
	r.URL.RawQuery = r.Query.Encode()
	r.Method = method

	cacher := r.Cacher
	cacheBehavior := r.cacherBehavior()
	if cacheBehavior != useCache {
		cacher = noOpCacher
	}

	cached, cachedErr := cacher.Get(r.Request)
	if cachedErr == nil {
		if cached.IsFresh() {
			return cached.Decode(r)
		} else {
			cached.SetupRequest(r.Request)
		}
	}

	httpres, err := r.Client.Do(r.Request)
	if err != nil {
		return ResponseError(err)
	}

	if cachedErr == nil && cacheBehavior == useCache && httpres.StatusCode == 304 {
		cacher.UpdateCache(r.Request, httpres)
		return cached.Decode(r)
	}

	mtype, err := mediaType(httpres)
	if err != nil {
		httpres.Body.Close()
		return ResponseError(err)
	}

	res := &Response{
		MediaType:  mtype,
		BodyClosed: false,
		Response:   httpres,
		Cacher:     cacher,
		isApiError: UseApiError(httpres.StatusCode),
	}

	if !res.AnyError() {
		if cacheBehavior == resetCache {
			r.Cacher.Reset(r.Request)
		} else if cacheBehavior == clearCache {
			r.Cacher.Clear(r.Request)
		} else {
			cacher.Set(r.Request, res)
		}
	}

	return res
}