-
Notifications
You must be signed in to change notification settings - Fork 26
/
pshb.go
86 lines (76 loc) · 2.39 KB
/
pshb.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
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
// Code generated by goagen v1.4.3, DO NOT EDIT.
//
// API "feedpushr": pshb Resource Client
//
// Command:
// $ goagen
// --design=github.com/ncarlier/feedpushr/v3/design
// --out=/home/nicolas/workspace/feedpushr/autogen
// --version=v1.4.3
package client
import (
"context"
"fmt"
"net/http"
"net/url"
"strconv"
)
// PubPshbPath computes a request path to the pub action of pshb.
func PubPshbPath() string {
return fmt.Sprintf("/v2/pshb")
}
// Publication endpoint for PSHB hubs
func (c *Client) PubPshb(ctx context.Context, path string) (*http.Response, error) {
req, err := c.NewPubPshbRequest(ctx, path)
if err != nil {
return nil, err
}
return c.Client.Do(ctx, req)
}
// NewPubPshbRequest create the request corresponding to the pub action endpoint of the pshb resource.
func (c *Client) NewPubPshbRequest(ctx context.Context, path string) (*http.Request, error) {
scheme := c.Scheme
if scheme == "" {
scheme = "http"
}
u := url.URL{Host: c.Host, Scheme: scheme, Path: path}
req, err := http.NewRequestWithContext(ctx, "POST", u.String(), nil)
if err != nil {
return nil, err
}
return req, nil
}
// SubPshbPath computes a request path to the sub action of pshb.
func SubPshbPath() string {
return fmt.Sprintf("/v2/pshb")
}
// Callback to validate the (un)subscription to the topic of a Hub
func (c *Client) SubPshb(ctx context.Context, path string, hubChallenge string, hubMode string, hubTopic string, hubLeaseSeconds *int) (*http.Response, error) {
req, err := c.NewSubPshbRequest(ctx, path, hubChallenge, hubMode, hubTopic, hubLeaseSeconds)
if err != nil {
return nil, err
}
return c.Client.Do(ctx, req)
}
// NewSubPshbRequest create the request corresponding to the sub action endpoint of the pshb resource.
func (c *Client) NewSubPshbRequest(ctx context.Context, path string, hubChallenge string, hubMode string, hubTopic string, hubLeaseSeconds *int) (*http.Request, error) {
scheme := c.Scheme
if scheme == "" {
scheme = "http"
}
u := url.URL{Host: c.Host, Scheme: scheme, Path: path}
values := u.Query()
values.Set("hub.challenge", hubChallenge)
values.Set("hub.mode", hubMode)
values.Set("hub.topic", hubTopic)
if hubLeaseSeconds != nil {
tmp32 := strconv.Itoa(*hubLeaseSeconds)
values.Set("hub.lease_seconds", tmp32)
}
u.RawQuery = values.Encode()
req, err := http.NewRequestWithContext(ctx, "GET", u.String(), nil)
if err != nil {
return nil, err
}
return req, nil
}