Skip to content

Commit e41497e

Browse files
committed
clarifyx: added method to annotate signals from admin namespace
1 parent 6221fac commit e41497e

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

examples/signals_annotate/main.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"os"
7+
8+
clarify "github.com/clarify/clarify-go"
9+
10+
"github.com/clarify/clarify-go/views"
11+
clarifyx "github.com/clarify/clarify-go/x"
12+
)
13+
14+
func main() {
15+
// To select or publish signals, you must grant the integration access to
16+
// the "admin" namespace in the Clarify admin panel.
17+
creds, err := clarify.CredentialsFromFile("clarify-credentials.json")
18+
if err != nil {
19+
panic(err)
20+
}
21+
22+
ctx := context.Background()
23+
client := creds.Client(ctx)
24+
xclient := clarifyx.Upgrade(client)
25+
26+
// For this example, the signals we want to select are created by the same
27+
// integration that we are using to select them. Note that this isn't a
28+
// requirement; for production cases, you may want this integration ID to be
29+
// configured to be something else.
30+
integrationID := creds.Integration
31+
signalID := "cl1d4kobi2aq0ttkc4b0"
32+
33+
data := []views.SignalAnnotate{{
34+
ID: signalID,
35+
Annotations: map[string]string{
36+
"obviously-this-blue-part-here": "is-the-land",
37+
"i-ve-made-a-huge-mistake": "", // Empty values deletes the annotation
38+
},
39+
}}
40+
41+
result, err := xclient.Admin().Signals().Annotate(integrationID, data).Do(ctx)
42+
if err != nil {
43+
panic(err)
44+
}
45+
enc := json.NewEncoder(os.Stdout)
46+
enc.SetIndent("", " ")
47+
if err := enc.Encode(result); err != nil {
48+
panic(err)
49+
}
50+
}

views/signal_annotate.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 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 views
16+
17+
type SignalAnnotate struct {
18+
ID string `json:"id"`
19+
Annotations map[string]string `json:"annotations"`
20+
}

x/admin.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 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/internal/request"
19+
"github.com/clarify/clarify-go/views"
20+
)
21+
22+
type AdminSignals struct {
23+
AdminNamespace
24+
}
25+
26+
func (ns AdminNamespace) Signals() AdminSignals {
27+
return AdminSignals{AdminNamespace: ns}
28+
}
29+
30+
// Annotate returns a new request for publishing signals as items.
31+
func (s AdminSignals) Annotate(integration string, data []views.SignalAnnotate) SignalsAnnotateRequest {
32+
return methodSignalsAnnotate.NewRequest(s.Handler(),
33+
paramIntegration.Value(integration),
34+
paramData.Value(data),
35+
paramFormat.Value(views.SelectionFormat{
36+
DataAsArray: true,
37+
GroupIncludedByType: true,
38+
}),
39+
)
40+
}
41+
42+
type (
43+
// SignalsAnnotateRequest describe an initialized admin.signals.annotate RPC
44+
// request with access to a request handler.
45+
SignalsAnnotateRequest = request.Request[SignalsAnnotateResult]
46+
47+
// SignalsAnnotateResult describe the result format for a SignalsAnnotateRequest.
48+
SignalsAnnotateResult = views.Selection[[]views.Signal, views.SignalInclude]
49+
)
50+
51+
var methodSignalsAnnotate = request.Method[SignalsAnnotateResult]{
52+
APIVersion: apiVersionExperimental,
53+
Method: "admin.signals.annotate",
54+
}

x/clarifyx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const (
2929

3030
paramFormat jsonrpc.ParamName = "format"
3131
paramIntegration jsonrpc.ParamName = "integration"
32+
paramData jsonrpc.ParamName = "data"
3233
paramItem jsonrpc.ParamName = "item"
3334
paramQuery jsonrpc.ParamName = "query"
3435
)

0 commit comments

Comments
 (0)