File: webhooks.go

package info (click to toggle)
golang-github-meilisearch-meilisearch-go 0.33.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 956 kB
  • sloc: makefile: 9
file content (105 lines) | stat: -rw-r--r-- 3,230 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package meilisearch

import (
	"context"
	"fmt"
	"net/http"
)

func (m *meilisearch) AddWebhook(params *AddWebhookRequest) (*Webhook, error) {
	return m.AddWebhookWithContext(context.Background(), params)
}

func (m *meilisearch) AddWebhookWithContext(ctx context.Context, params *AddWebhookRequest) (*Webhook, error) {
	resp := new(Webhook)
	req := &internalRequest{
		endpoint:            "/webhooks",
		method:              http.MethodPost,
		withRequest:         params,
		contentType:         contentTypeJSON,
		withResponse:        resp,
		acceptedStatusCodes: []int{http.StatusCreated, http.StatusOK},
		functionName:        "AddWebhook",
	}
	if err := m.client.executeRequest(ctx, req); err != nil {
		return nil, err
	}
	return resp, nil
}

func (m *meilisearch) ListWebhooks() (*WebhookResults, error) {
	return m.ListWebhooksWithContext(context.Background())
}

func (m *meilisearch) ListWebhooksWithContext(ctx context.Context) (*WebhookResults, error) {
	resp := new(WebhookResults)
	req := &internalRequest{
		endpoint:            "/webhooks",
		method:              http.MethodGet,
		withRequest:         nil,
		withResponse:        resp,
		acceptedStatusCodes: []int{http.StatusOK},
		functionName:        "ListWebhooks",
	}
	if err := m.client.executeRequest(ctx, req); err != nil {
		return nil, err
	}
	return resp, nil
}

func (m *meilisearch) GetWebhook(uuid string) (*Webhook, error) {
	return m.GetWebhookWithContext(context.Background(), uuid)
}

func (m *meilisearch) GetWebhookWithContext(ctx context.Context, uuid string) (*Webhook, error) {
	resp := new(Webhook)
	req := &internalRequest{
		endpoint:            fmt.Sprintf("/webhooks/%s", uuid),
		method:              http.MethodGet,
		withRequest:         nil,
		withResponse:        resp,
		acceptedStatusCodes: []int{http.StatusOK},
		functionName:        "GetWebhook",
	}
	if err := m.client.executeRequest(ctx, req); err != nil {
		return nil, err
	}
	return resp, nil
}

func (m *meilisearch) UpdateWebhook(uuid string, params *UpdateWebhookRequest) (*Webhook, error) {
	return m.UpdateWebhookWithContext(context.Background(), uuid, params)
}

func (m *meilisearch) UpdateWebhookWithContext(ctx context.Context, uuid string, params *UpdateWebhookRequest) (*Webhook, error) {
	resp := new(Webhook)
	req := &internalRequest{
		endpoint:            fmt.Sprintf("/webhooks/%s", uuid),
		method:              http.MethodPatch,
		withRequest:         params,
		contentType:         contentTypeJSON,
		withResponse:        resp,
		acceptedStatusCodes: []int{http.StatusOK},
		functionName:        "UpdateWebhook",
	}
	if err := m.client.executeRequest(ctx, req); err != nil {
		return nil, err
	}
	return resp, nil
}

func (m *meilisearch) DeleteWebhook(uuid string) error {
	return m.DeleteWebhookWithContext(context.Background(), uuid)
}

func (m *meilisearch) DeleteWebhookWithContext(ctx context.Context, uuid string) error {
	req := &internalRequest{
		endpoint:            fmt.Sprintf("/webhooks/%s", uuid),
		method:              http.MethodDelete,
		withRequest:         nil,
		withResponse:        nil,
		acceptedStatusCodes: []int{http.StatusNoContent},
		functionName:        "DeleteWebhook",
	}
	return m.client.executeRequest(ctx, req)
}