func sendRequest(apiKey, path, payload string, method rest.Method) ([]byte, error) {
	request := sendgrid.GetRequest(apiKey, path, "https://api.sendgrid.com")
	request.Method = method
	if payload != "" {
		request.Body = []byte(payload)
	}

	response, err := sendgrid.API(request)
	if err != nil {
		return nil, err
	}

	switch response.StatusCode {
	case 200:
		break
	case 201:
		break
	case 202:
		break
	case 204:
		break
	default:
		errRes := &ErrorResponse{}
		err := json.Unmarshal([]byte(response.Body), errRes)
		if err != nil {
			return nil, err
		}

		errRes.ErrorCode = response.StatusCode

		if len(errRes.Errors) <= 0 {
			return nil, errors.New("an unknown API error has occured")
		}

		return nil, errRes.Errors[0]
	}

	return []byte(response.Body), nil
}
// sendRequest will send the request to the API.
sendRequest will send the request to the API.
// sendRequest will send the request to the API .
func sendRequest(apiKey, path, payload string, method rest.Method) ([]byte, error) {
	request := sendgrid.GetRequest(apiKey, path, "https://api.sendgrid.com")
	request.Method = method
	if payload != "" {
		request.Body = []byte(payload)
	}
	response, err := sendgrid.API(request)
	if err != nil {
		return nil, err
	}
	switch response.StatusCode {
	case 200:
		break
	case 201:
		break
	case 202:
		break
	case 204:
		break
	default:
		errRes := &ErrorResponse{}
		err := json.Unmarshal([]byte(response.Body), errRes)
		if err != nil {
			return nil, err
		}
		errRes.ErrorCode = response.StatusCode
		if len(errRes.Errors) <= 0 {
			return nil, errors.New("an unknown API error has occured")
		}
		return nil, errRes.Errors[0]
	}
	return []byte(response.Body), nil
}
func sendRequest ( apiKey , path , payload string , method rest . Method ) ( [ ] byte , error ) { request := sendgrid . GetRequest ( apiKey , path , " " ) request . Method = method if payload != " " { request . Body = [ ] byte ( payload ) } response , err := sendgrid . API ( request ) if err != nil { return nil , err } switch response . StatusCode { case 200 : break case 201 : break case 202 : break case 204 : break default : errRes := & ErrorResponse { } err := json . Unmarshal ( [ ] byte ( response . Body ) , errRes ) if err != nil { return nil , err } errRes . ErrorCode = response . StatusCode if len ( errRes . Errors ) <= 0 { return nil , errors . New ( " " ) } return nil , errRes . Errors [ 0 ] } return [ ] byte ( response . Body ) , nil }
sendRequest will send the request to the API.
sendRequest will send the request to the API .