Exemple #1
0
// makeRequest shim performs a generic request, checking for a positive outcome.
// See simplehttp.MakeRequest for more details.
func makeRequest(r *simplehttp.HTTPRequest, kind string, p simplehttp.Payload) (*simplehttp.HTTPResponse, error) {
	r.AddHeader("User-Agent", MailgunGoUserAgent)
	rsp, err := r.MakeRequest(kind, p)
	if (err == nil) && notGood(rsp.Code, expected) {
		return rsp, newError(r.URL, expected, rsp.Code)
	}
	return rsp, err
}
Exemple #2
0
// makeDeleteRequest shim performs a DELETE request, checking for a positive outcome.
// See simplehttp.MakeDeleteRequest for more details.
func makeDeleteRequest(r *simplehttp.HTTPRequest) (*simplehttp.HTTPResponse, error) {
	r.AddHeader("User-Agent", MailgunGoUserAgent)
	rsp, err := r.MakeDeleteRequest()
	if (err == nil) && notGood(rsp.Code, expected) {
		return rsp, newError(r.URL, expected, rsp.Code)
	}
	return rsp, err
}
Exemple #3
0
// putResponseFromJSON shim performs a PUT request, checking for a positive outcome.
// See simplehttp.PutResponseFromJSON for more details.
func putResponseFromJSON(r *simplehttp.HTTPRequest, p simplehttp.Payload, v interface{}) error {
	r.AddHeader("User-Agent", MailgunGoUserAgent)
	response, err := r.MakePutRequest(p)
	if err != nil {
		return err
	}
	if notGood(response.Code, expected) {
		return newError(r.URL, expected, response.Code)
	}
	return response.ParseFromJSON(v)
}