Example #1
0
// Head sends an HTTP Request with using the "HEAD" method and with
// an "Accept" header set to "*/*" and the authentication token
// set to the specified token value. The request is made by the
// specified client. The response is a straight net/http.Response
// The caller is responsible for closing the response body!
func Head(url string, authenticator common.Authenticator) (*http.Response, error) {
	r := requester.ExtractSendRequestFunction(authenticator)
	token, err := authenticator.GetToken()
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("HEAD", url, nil)
	if err != nil {
		return nil, err
	}

	req.Header.Set("Accept", "*/*")
	req.Header.Set("X-Auth-Token", token)

	resp, err := makeRequest(r, req)
	if err != nil {
		return nil, err
	}

	if resp.StatusCode != 201 && resp.StatusCode != 202 && resp.StatusCode != 200 && resp.StatusCode != 300 {
		err = HTTPStatus{StatusCode: resp.StatusCode, Message: "Error: status code != 200, 201, 202, or 300, actual status code '" + resp.Status + "'"}
	}

	return resp, err
}
Example #2
0
// PutJSON sends an Http Request with using the "PUT" method and with
// a "Content-Type" header with application/json and X-Auth-Token" header
// set to the specified token value. The inputValue is encoded to json
// and sent in the body of the request. The response json body is
// decoded into the outputValue. If the response does sends a
// non 200 status code then an error will be returned.
func PutJSON(url string, authenticator common.Authenticator, inputValue interface{}, outputValue interface{}) (err error) {
	r := requester.ExtractSendRequestFunction(authenticator)
	token, err := authenticator.GetToken()
	if err != nil {
		return err
	}

	return PutJSONWithTokenAndRequester(url, token, r, inputValue, outputValue)
}
Example #3
0
//GetJSON sends an Http Request with using the "GET" method and with
//an "Accept" header set to "application/json" and the authentication token
//set to the specified token value. The request is made by the
//specified client. The val interface should be a pointer to the
//structure that the json response should be decoded into.
func GetJSON(url string, authenticator common.Authenticator, val interface{}) (err error) {
	r := requester.ExtractSendRequestFunction(authenticator)
	token, err := authenticator.GetToken()
	if err != nil {
		return err
	}

	return GetJSONWithTokenAndRequester(url, token, r, val)
}
Example #4
0
// Delete sends an Http Request with using the "DELETE" method and with
// an "X-Auth-Token" header set to the specified token value. The request
// is made by the specified client.
func Delete(url string, authenticator common.Authenticator) (err error) {
	r := requester.ExtractSendRequestFunction(authenticator)
	token, err := authenticator.GetToken()
	if err != nil {
		return err
	}

	return DeleteWithTokenAndRequester(url, token, r)
}