forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_subscription_command.go
53 lines (41 loc) · 1.16 KB
/
create_subscription_command.go
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
package ravendb
import (
"encoding/json"
"net/http"
)
var (
_ RavenCommand = &CreateSubscriptionCommand{}
)
// CreateSubscriptionCommand represents "create subscription" command
type CreateSubscriptionCommand struct {
RavenCommandBase
conventions *DocumentConventions
options *SubscriptionCreationOptions
id string
Result *CreateSubscriptionResult
}
func newCreateSubscriptionCommand(conventions *DocumentConventions, options *SubscriptionCreationOptions, id string) *CreateSubscriptionCommand {
return &CreateSubscriptionCommand{
RavenCommandBase: NewRavenCommandBase(),
conventions: conventions,
options: options,
id: id,
}
}
func (c *CreateSubscriptionCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
uri := node.URL + "/databases/" + node.Database + "/subscriptions"
if c.id != "" {
uri += "?id=" + c.id
}
d, err := json.Marshal(c.options)
if err != nil {
return nil, err
}
return newHttpPut(uri, d)
}
func (c *CreateSubscriptionCommand) SetResponse(response []byte, fromCache bool) error {
if len(response) == 0 {
return throwInvalidResponse()
}
return jsonUnmarshal(response, &c.Result)
}