Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions examples/signals_annotate/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"context"
"encoding/json"
"os"

clarify "github.com/clarify/clarify-go"

"github.com/clarify/clarify-go/views"
clarifyx "github.com/clarify/clarify-go/x"
)

func main() {
// To select or publish signals, you must grant the integration access to
// the "admin" namespace in the Clarify admin panel.
creds, err := clarify.CredentialsFromFile("clarify-credentials.json")
if err != nil {
panic(err)
}

ctx := context.Background()
client := creds.Client(ctx)
xclient := clarifyx.Upgrade(client)

// For this example, the signals we want to select are created by the same
// integration that we are using to select them. Note that this isn't a
// requirement; for production cases, you may want this integration ID to be
// configured to be something else.
integrationID := creds.Integration
signalID := "cl1d4kobi2aq0ttkc4b0"

data := []views.SignalAnnotate{{
ID: signalID,
Annotations: map[string]string{
"obviously-this-blue-part-here": "is-the-land",
"i-ve-made-a-huge-mistake": "", // Empty values deletes the annotation
},
}}

result, err := xclient.Admin().Signals().Annotate(integrationID, data).Do(ctx)
if err != nil {
panic(err)
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
if err := enc.Encode(result); err != nil {
panic(err)
}
}
20 changes: 20 additions & 0 deletions views/signal_annotate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2025 Searis AS
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package views

type SignalAnnotate struct {
ID string `json:"id"`
Annotations map[string]string `json:"annotations"`
}
54 changes: 54 additions & 0 deletions x/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2025 Searis AS
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package clarifyx

import (
"github.com/clarify/clarify-go/internal/request"
"github.com/clarify/clarify-go/views"
)

type AdminSignals struct {
AdminNamespace
}

func (ns AdminNamespace) Signals() AdminSignals {
return AdminSignals{AdminNamespace: ns}
}

// Annotate returns a new request for publishing signals as items.
func (s AdminSignals) Annotate(integration string, data []views.SignalAnnotate) SignalsAnnotateRequest {
return methodSignalsAnnotate.NewRequest(s.Handler(),
paramIntegration.Value(integration),
paramData.Value(data),
paramFormat.Value(views.SelectionFormat{
DataAsArray: true,
GroupIncludedByType: true,
}),
)
}

type (
// SignalsAnnotateRequest describe an initialized admin.signals.annotate RPC
// request with access to a request handler.
SignalsAnnotateRequest = request.Request[SignalsAnnotateResult]

// SignalsAnnotateResult describe the result format for a SignalsAnnotateRequest.
SignalsAnnotateResult = views.Selection[[]views.Signal, views.SignalInclude]
)

var methodSignalsAnnotate = request.Method[SignalsAnnotateResult]{
APIVersion: apiVersionExperimental,
Method: "admin.signals.annotate",
}
1 change: 1 addition & 0 deletions x/clarifyx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (

paramFormat jsonrpc.ParamName = "format"
paramIntegration jsonrpc.ParamName = "integration"
paramData jsonrpc.ParamName = "data"
paramItem jsonrpc.ParamName = "item"
paramQuery jsonrpc.ParamName = "query"
)
Expand Down