func (cli *OpsGenieHeartbeatClient) Send(req heartbeat.SendHeartbeatRequest) (*heartbeat.SendHeartbeatResponse, error) {
	req.ApiKey = cli.apiKey
	// validate the mandatory field: apiKey
	if req.ApiKey == "" {
		return nil, errors.New("Api Key is a mandatory field and can not be empty")
	}
	// send the payload in a POST request
	var resp *goreq.Response
	var err error
	for i := 0; i < cli.retries; i++ {
		resp, err = cli.buildRequest("POST", SEND_HEARTBEAT_URL, req).Do()
		if err == nil {
			break
		}
		time.Sleep(TIME_SLEEP_BETWEEN_REQUESTS)
	}
	if err != nil {
		return nil, errors.New("Can not send the heart beat, unable to send the request")
	}
	// check for the returning http status, 4xx: client errors, 5xx: server errors
	statusCode := resp.StatusCode
	if statusCode >= 400 && statusCode < 500 {
		return nil, errors.New(fmt.Sprintf("Client error %d occured", statusCode))
	}
	if statusCode >= 500 {
		return nil, errors.New(fmt.Sprintf("Server error %d occured", statusCode))
	}
	// try to parse the returning JSON into the response
	var sendHeartbeatResp heartbeat.SendHeartbeatResponse
	if err = resp.Body.FromJsonTo(&sendHeartbeatResp); err != nil {
		return nil, errors.New("Server response can not be parsed")
	}
	// parsed successfuly with no errors
	return &sendHeartbeatResp, nil
}
// HeartbeatAction sends an Heartbeat signal to OpsGenie.
func HeartbeatAction(c *gcli.Context) {
	cli, err := NewHeartbeatClient(c)
	if err != nil {
		os.Exit(1)
	}

	req := hb.SendHeartbeatRequest{}
	if val, success := getVal("name", c); success {
		req.Name = val
	}

	printVerboseMessage("Heartbeat request prepared from flags, sending request to OpsGenie..")

	response, err := cli.Send(req)
	if err != nil {
		fmt.Printf("%s\n", err.Error())
		os.Exit(1)
	}
	printVerboseMessage("Send heartbeat successfully")
	fmt.Printf("heartbeat=%d\n", response.Heartbeat)
}
// Send method sends an Heartbeat Signal to OpsGenie.
func (cli *OpsGenieHeartbeatClient) Send(req heartbeat.SendHeartbeatRequest) (*heartbeat.SendHeartbeatResponse, error) {
	req.APIKey = cli.apiKey
	resp, err := cli.sendRequest(cli.buildPostRequest(sendHeartbeatURL, req))

	if resp == nil {
		return nil, err
	}
	defer resp.Body.Close()

	var sendHeartbeatResp heartbeat.SendHeartbeatResponse
	if err = resp.Body.FromJsonTo(&sendHeartbeatResp); err != nil {
		message := "Server response can not be parsed, " + err.Error()
		logging.Logger().Warn(message)
		return nil, errors.New(message)
	}

	return &sendHeartbeatResp, nil
}