Skip to content

Commit 14c0c86

Browse files
committed
client: added methods for connecting and disconnecting signals
1 parent 3f8a6a8 commit 14c0c86

File tree

5 files changed

+197
-5
lines changed

5 files changed

+197
-5
lines changed

client.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022-2024 Searis AS
1+
// Copyright 2022-2025 Searis AS
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -24,7 +24,8 @@ import (
2424
)
2525

2626
const (
27-
apiVersion = "1.1"
27+
apiVersion = "1.1"
28+
apiVersionExperimental = "1.2alpha1"
2829

2930
paramCalculations jsonrpc.ParamName = "calculations"
3031
paramData jsonrpc.ParamName = "data"
@@ -149,6 +150,10 @@ type AdminNamespace struct {
149150
h jsonrpc.Handler
150151
}
151152

153+
func (ns AdminNamespace) Handler() jsonrpc.Handler {
154+
return ns.h
155+
}
156+
152157
// SelectSignals returns a new request for querying signals and related
153158
// resources.
154159
func (ns AdminNamespace) SelectSignals(integration string, q fields.ResourceQuery) SelectSignalsRequest {
@@ -206,6 +211,10 @@ type ClarifyNamespace struct {
206211
h jsonrpc.Handler
207212
}
208213

214+
func (ns ClarifyNamespace) Handler() jsonrpc.Handler {
215+
return ns.h
216+
}
217+
209218
// SelectItems returns a request for querying items.
210219
func (ns ClarifyNamespace) SelectItems(q fields.ResourceQuery) SelectItemsRequest {
211220
return methodSelectItems.NewRequest(ns.h,
@@ -332,6 +341,6 @@ type EvaluateRequest struct {
332341
type EvaluateResult = views.Selection[views.DataFrame, views.DataFrameInclude]
333342

334343
var methodEvaluate = request.RelationalMethod[EvaluateResult]{
335-
APIVersion: "1.2alpha1",
344+
APIVersion: apiVersionExperimental,
336345
Method: "clarify.evaluate",
337346
}

credentials.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022-2023 Searis AS
1+
// Copyright 2022-2025 Searis AS
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -143,7 +143,7 @@ func (creds Credentials) Client(ctx context.Context) *Client {
143143
h = invalidRPCHandler{err: err}
144144
}
145145

146-
return &Client{ns: IntegrationNamespace{integration: creds.Integration, h: h}}
146+
return NewClient(creds.Integration, h)
147147
}
148148

149149
// HTTPHandler returns a low-level RPC handler that communicates over HTTP using

examples/connect_signals/main.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"os"
7+
8+
"github.com/clarify/clarify-go"
9+
"github.com/clarify/clarify-go/fields"
10+
clarifyx "github.com/clarify/clarify-go/x"
11+
)
12+
13+
func main() {
14+
creds, err := clarify.CredentialsFromFile("clarify-credentials.json")
15+
if err != nil {
16+
panic(err)
17+
}
18+
19+
ctx := context.Background()
20+
client := creds.Client(ctx)
21+
22+
integration := "c2mo5rac8v1dtfnta5e0"
23+
item := "cuga77bpn4pb81evdgj0"
24+
signal := "cl1d4kobi2aq0ttkc4b0"
25+
26+
q := fields.Query().Limit(1).Where(
27+
fields.CompareField("id", fields.In(signal)),
28+
).Total(true)
29+
30+
xclient := clarifyx.Upgrade(client)
31+
32+
result, err := xclient.Admin().ConnectSignals(integration, item, q).Do(ctx)
33+
if err != nil {
34+
panic(err)
35+
}
36+
37+
enc := json.NewEncoder(os.Stdout)
38+
enc.SetIndent("", " ")
39+
enc.Encode(result)
40+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"os"
7+
8+
"github.com/clarify/clarify-go"
9+
"github.com/clarify/clarify-go/fields"
10+
clarifyx "github.com/clarify/clarify-go/x"
11+
)
12+
13+
func main() {
14+
creds, err := clarify.CredentialsFromFile("clarify-credentials.json")
15+
if err != nil {
16+
panic(err)
17+
}
18+
19+
ctx := context.Background()
20+
client := creds.Client(ctx)
21+
22+
integration := "c2mo5rac8v1dtfnta5e0"
23+
signal := "cl1d4kobi2aq0ttkc4b0"
24+
25+
q := fields.Query().Limit(1).Where(
26+
fields.CompareField("id", fields.In(signal)),
27+
).Total(true)
28+
29+
xclient := clarifyx.Upgrade(client)
30+
31+
result, err := xclient.Admin().DisconnectSignals(integration, q).Do(ctx)
32+
if err != nil {
33+
panic(err)
34+
}
35+
36+
enc := json.NewEncoder(os.Stdout)
37+
enc.SetIndent("", " ")
38+
enc.Encode(result)
39+
}

x/clarifyx.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright 2022-2025 Searis AS
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package clarifyx
16+
17+
import (
18+
"github.com/clarify/clarify-go"
19+
"github.com/clarify/clarify-go/fields"
20+
"github.com/clarify/clarify-go/internal/request"
21+
"github.com/clarify/clarify-go/jsonrpc"
22+
"github.com/clarify/clarify-go/views"
23+
)
24+
25+
const (
26+
apiVersion = "1.1"
27+
apiVersionExperimental = "1.2alpha1"
28+
29+
paramFormat jsonrpc.ParamName = "format"
30+
paramIntegration jsonrpc.ParamName = "integration"
31+
paramItem jsonrpc.ParamName = "item"
32+
paramQuery jsonrpc.ParamName = "query"
33+
)
34+
35+
type Client struct {
36+
clarify.Client
37+
}
38+
39+
func Upgrade(c *clarify.Client) Client {
40+
return Client{Client: *c}
41+
}
42+
43+
func (c Client) Admin() AdminNamespace {
44+
return AdminNamespace{AdminNamespace: c.Client.Admin()}
45+
}
46+
47+
type AdminNamespace struct {
48+
clarify.AdminNamespace
49+
}
50+
51+
// ConnectSignals returns a new request for publishing signals as items.
52+
func (ns AdminNamespace) ConnectSignals(integration, item string, q fields.ResourceQuery) ConnectSignalsRequest {
53+
return methodConnectSignals.NewRequest(ns.Handler(),
54+
paramIntegration.Value(integration),
55+
paramItem.Value(item),
56+
paramQuery.Value(q),
57+
paramFormat.Value(views.SelectionFormat{
58+
DataAsArray: true,
59+
GroupIncludedByType: true,
60+
}),
61+
)
62+
}
63+
64+
type (
65+
// ConnectSignalsRequest describe an initialized admin.publishSignal RPC
66+
// request with access to a request handler.
67+
ConnectSignalsRequest = request.Request[ConnectSignalsResult]
68+
69+
// ConnectSignalsResult describe the result format for a
70+
// ConnectSignalsRequest.
71+
ConnectSignalsResult = views.Selection[[]views.Signal, views.SignalInclude]
72+
)
73+
74+
var methodConnectSignals = request.Method[ConnectSignalsResult]{
75+
APIVersion: apiVersionExperimental,
76+
Method: "admin.connectSignals",
77+
}
78+
79+
// DisconnectSignals returns a new request for publishing signals as items.
80+
func (ns AdminNamespace) DisconnectSignals(integration string, q fields.ResourceQuery) DisconnectSignalsRequest {
81+
return methodDisconnectSignals.NewRequest(ns.Handler(),
82+
paramIntegration.Value(integration),
83+
paramQuery.Value(q),
84+
paramFormat.Value(views.SelectionFormat{
85+
DataAsArray: true,
86+
GroupIncludedByType: true,
87+
}),
88+
)
89+
}
90+
91+
type (
92+
// DisconnectSignalsRequest describe an initialized admin.publishSignal RPC
93+
// request with access to a request handler.
94+
DisconnectSignalsRequest = request.Request[DisconnectSignalsResult]
95+
96+
// DisconnectSignalsResult describe the result format for a
97+
// DisconnectSignalsRequest.
98+
DisconnectSignalsResult = views.Selection[[]views.Signal, views.SignalInclude]
99+
)
100+
101+
var methodDisconnectSignals = request.Method[DisconnectSignalsResult]{
102+
APIVersion: apiVersionExperimental,
103+
Method: "admin.disconnectSignals",
104+
}

0 commit comments

Comments
 (0)