Files
ngrok-api-go/abuse_reports/client.go
T
2026-05-08 14:41:45 +00:00

74 lines
2.0 KiB
Go

// Code generated for API Clients. DO NOT EDIT.
package abuse_reports
import (
"bytes"
"context"
"fmt"
"net/url"
"text/template"
"github.com/ngrok/ngrok-api-go/v9"
"github.com/ngrok/ngrok-api-go/v9/internal/api"
)
// Abuse Reports allow you to submit take-down requests for URLs hosted by
// ngrok that violate ngrok's terms of service.
type Client struct {
apiClient *api.Client
}
func NewClient(cfg *ngrok.ClientConfig) *Client {
return &Client{apiClient: api.NewClient(cfg)}
}
// Creates a new abuse report which will be reviewed by our system and abuse
// response team. This API is only available to authorized accounts. Contact
// abuse@ngrok.com to request access
//
// https://ngrok.com/docs/api-reference/abusereports/create
func (c *Client) Create(ctx context.Context, arg *ngrok.AbuseReportCreate) (*ngrok.AbuseReport, error) {
var res ngrok.AbuseReport
var path bytes.Buffer
if err := template.Must(template.New("create_path").Parse("/abuse_reports")).Execute(&path, arg); err != nil {
return nil, fmt.Errorf("error building path for create: %w", err)
}
var (
apiURL = &url.URL{Path: path.String()}
bodyArg interface{}
)
apiURL.Path = path.String()
bodyArg = arg
if err := c.apiClient.Do(ctx, "POST", apiURL, bodyArg, &res); err != nil {
return nil, err
}
return &res, nil
}
// Get the detailed status of abuse report by ID.
//
// https://ngrok.com/docs/api-reference/abusereports/get
func (c *Client) Get(ctx context.Context, id string) (*ngrok.AbuseReport, error) {
arg := &ngrok.Item{ID: id}
var res ngrok.AbuseReport
var path bytes.Buffer
if err := template.Must(template.New("get_path").Parse("/abuse_reports/{{ .ID }}")).Execute(&path, arg); err != nil {
return nil, fmt.Errorf("error building path for get: %w", err)
}
arg.ID = ""
var (
apiURL = &url.URL{Path: path.String()}
bodyArg interface{}
)
apiURL.Path = path.String()
if err := c.apiClient.Do(ctx, "GET", apiURL, bodyArg, &res); err != nil {
return nil, err
}
return &res, nil
}