-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhooks_api.go
More file actions
59 lines (51 loc) · 1.97 KB
/
webhooks_api.go
File metadata and controls
59 lines (51 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package inouesdk
import (
"context"
"encoding/json"
"fmt"
)
// WebhooksAPI provides access to the webhook endpoints.
type WebhooksAPI struct {
client *InoueClient
}
// ---------------------------------------------------------------------------
// Response types
// ---------------------------------------------------------------------------
// WebhookIngestResult represents the result of a webhook ingestion.
type WebhookIngestResult struct {
Received bool `json:"received"`
EventID string `json:"event_id"`
Details map[string]interface{} `json:"details"`
}
// WebhookHealthResponse represents webhook system health.
type WebhookHealthResponse struct {
Status string `json:"status"`
Providers map[string]interface{} `json:"providers"`
}
// ---------------------------------------------------------------------------
// Methods
// ---------------------------------------------------------------------------
// IngestMock sends a mock webhook event for testing.
func (a *WebhooksAPI) IngestMock(ctx context.Context, payload map[string]interface{}) (*WebhookIngestResult, error) {
var apiResp ApiResponse
if err := a.client.request(ctx, "POST", "/v1/webhooks/ingest/mock", payload, &apiResp, nil); err != nil {
return nil, fmt.Errorf("ingest mock webhook: %w", err)
}
var result WebhookIngestResult
if err := json.Unmarshal(apiResp.Data, &result); err != nil {
return nil, fmt.Errorf("ingest mock webhook decode: %w", err)
}
return &result, nil
}
// Health returns the webhook system health.
func (a *WebhooksAPI) Health(ctx context.Context) (*WebhookHealthResponse, error) {
var apiResp ApiResponse
if err := a.client.request(ctx, "GET", "/v1/webhooks/health", nil, &apiResp, nil); err != nil {
return nil, fmt.Errorf("webhook health: %w", err)
}
var result WebhookHealthResponse
if err := json.Unmarshal(apiResp.Data, &result); err != nil {
return nil, fmt.Errorf("webhook health decode: %w", err)
}
return &result, nil
}