func (c *Client) Report(r Report) error {
	if ip := net.ParseIP(r.IP); ip == nil {
		return errors.New("invalid Report.IPAddress: invalid IP")
	}

	v := url.Values{
		"key": {c.APIKey},
		"ip":  {r.IP},
	}
	if r.Comment != "" {
		v.Set("comment", r.Comment)
	}

	// Join category IDs with commas
	// Like "10,12,15"
	var buf bytes.Buffer
	for i, cat := range r.Categories {
		buf.WriteString(strconv.Itoa(int(cat)))
		// Don't write comma after the last category
		if i < len(r.Categories)-1 {
			buf.WriteByte(',')
		}
	}
	v.Set("categories", buf.String())

	req, err := http.NewRequest(http.MethodPost, baseURL+"report/json", strings.NewReader(v.Encode()))
	if err != nil {
		return err
	}
	req.Header.Set("User-Agent", DefaultUserAgent)
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Set("Accept", "application/json")

	resp, err := c.http.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	if resp.StatusCode >= 400 && resp.StatusCode < 600 {
		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return err
		}
		return RequestError{resp.Status, body}
	}

	var ok struct {
		IP      string `json:"ip"`
		Success bool   `json:"success"`
	}
	err = json.NewDecoder(resp.Body).Decode(&ok)
	if err != nil {
		return err
	}
	if !ok.Success {
		return errors.New("API reports 'success'=false")
	}
	return nil
}
// Report submits a report to AbuseIPDB.
Report submits a report to AbuseIPDB.
// Report submits a report to AbuseIPDB .
func (c *Client) Report(r Report) error {
	if ip := net.ParseIP(r.IP); ip == nil {
		return errors.New("invalid Report.IPAddress: invalid IP")
	}
	v := url.Values{
		"key": {c.APIKey},
		"ip":  {r.IP},
	}
	if r.Comment != "" {
		v.Set("comment", r.Comment)
	}
	var buf bytes.Buffer
	for i, cat := range r.Categories {
		buf.WriteString(strconv.Itoa(int(cat)))
		if i < len(r.Categories)-1 {
			buf.WriteByte(',')
		}
	}
	v.Set("categories", buf.String())
	req, err := http.NewRequest(http.MethodPost, baseURL+"report/json", strings.NewReader(v.Encode()))
	if err != nil {
		return err
	}
	req.Header.Set("User-Agent", DefaultUserAgent)
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Set("Accept", "application/json")
	resp, err := c.http.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode >= 400 && resp.StatusCode < 600 {
		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return err
		}
		return RequestError{resp.Status, body}
	}
	var ok struct {
		IP      string `json:"ip"`
		Success bool   `json:"success"`
	}
	err = json.NewDecoder(resp.Body).Decode(&ok)
	if err != nil {
		return err
	}
	if !ok.Success {
		return errors.New("API reports 'success'=false")
	}
	return nil
}
func ( c * Client ) Report ( r Report ) error { if ip := net . ParseIP ( r . IP ) ; ip == nil { return errors . New ( " " ) } v := url . Values { " " : { c . APIKey } , " " : { r . IP } , } if r . Comment != " " { v . Set ( " " , r . Comment ) } var buf bytes . Buffer for i , cat := range r . Categories { buf . WriteString ( strconv . Itoa ( int ( cat ) ) ) if i < len ( r . Categories ) - 1 { buf . WriteByte ( ',' ) } } v . Set ( " " , buf . String ( ) ) req , err := http . NewRequest ( http . MethodPost , baseURL + " " , strings . NewReader ( v . Encode ( ) ) ) if err != nil { return err } req . Header . Set ( " " , DefaultUserAgent ) req . Header . Set ( " " , " " ) req . Header . Set ( " " , " " ) resp , err := c . http . Do ( req ) if err != nil { return err } defer resp . Body . Close ( ) if resp . StatusCode >= 400 && resp . StatusCode < 600 { body , err := ioutil . ReadAll ( resp . Body ) if err != nil { return err } return RequestError { resp . Status , body } } var ok struct { IP string `json:"ip"` Success bool `json:"success"` } err = json . NewDecoder ( resp . Body ) . Decode ( & ok ) if err != nil { return err } if ! ok . Success { return errors . New ( " " ) } return nil }
Report submits a report to AbuseIPDB.
Report submits a report to AbuseIPDB .
// Join category IDs with commas // Like "10,12,15" // Don't write comma after the last category