Documentation
¶
Overview ¶
Package moonsense is the official Moonsense SDK for the Go programming language.
Getting started ¶
The best way to get started working with the SDK is to use `go get` to add the SDK to your Go dependencies explicitly.
go get github.com/moonsense/go-sdk
Once you have installed the SDK, you will need an API secret key. Navigate to your App in the Moonsense Console and create a token. You will need to save the generated secret key to a secure place.
https://console.moonsense.cloud/dashboard
We recommend exporting the API secret key as an environment variable:
export MOONSENSE_SECRET_TOKEN=...
You can then very easily list sessions and access the granular data:
package main
import (
"fmt"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
)
func main() {
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
client := moonsense.NewClient(sdkConfig)
paginatedSession, err := client.ListSessions(config.ListSessionConfig{})
for {
if err != nil {
fmt.Println("Error getting session list")
fmt.Println(err)
break
}
for _, session := range paginatedSession.Sessions {
fmt.Printf("SessionId: %s, %s - %s\n", session.SessionId, session.Metadata.Platform.String(), session.CreatedAt.AsTime())
}
if paginatedSession.HasMore() {
paginatedSession, err = paginatedSession.NextPage()
} else {
break
}
}
}
Example (AddJourneyFeedback) ¶
package main
import (
"fmt"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
"google.golang.org/protobuf/types/known/timestamppb"
journeysProto "github.com/moonsense/go-sdk/moonsense/models/pb/v2/journeys"
)
func main() {
// Create an SDKConfig with your secret token
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
// Create a Moonsense Client with the SDKConfig
client := moonsense.NewClient(sdkConfig)
err := client.AddJourneyFeedback("journeyId", &journeysProto.JourneyFeedback{
FraudFeedback: &journeysProto.FraudFeedback{
IsFraud: true,
ReportedAt: timestamppb.Now(),
FraudReason: "It was fraud because...",
},
})
if err != nil {
fmt.Println("Error adding journey feedback")
fmt.Println(err)
return
}
}
Example (DescribeJourney) ¶
package main
import (
"fmt"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
)
func main() {
// Create an SDKConfig with your secret token
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
// Create a Moonsense Client with the SDKConfig
client := moonsense.NewClient(sdkConfig)
// Fetch the journey information for the specified journeyID
journey, err := client.DescribeJourney("journeyID")
if err != nil {
fmt.Println("Error fetching journey")
fmt.Println(err)
return
}
fmt.Println(journey)
}
Example (DescribeSession) ¶
package main
import (
"fmt"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
)
func main() {
// Create an SDKConfig with your secret token
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
// Create a Moonsense Client with the SDKConfig
client := moonsense.NewClient(sdkConfig)
// Fetch the session information for the specified sessionID
session, err := client.DescribeSession("sessionID", false)
if err != nil {
fmt.Println("Error fetching session")
fmt.Println(err)
return
}
fmt.Println(session)
}
Example (GetJourneyFeedback) ¶
package main
import (
"fmt"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
)
func main() {
// Create an SDKConfig with your secret token
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
// Create a Moonsense Client with the SDKConfig
client := moonsense.NewClient(sdkConfig)
// Fetch the journey information for the specified journeyID
feedback, err := client.GetJourneyFeedback("journeyID")
if err != nil {
fmt.Println("Error fetching journey feedback")
fmt.Println(err)
return
}
fmt.Println(feedback)
}
Example (ListJourneys) ¶
package main
import (
"fmt"
"time"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
commonProto "github.com/moonsense/go-sdk/moonsense/models/pb/v2/common"
)
func main() {
// Create an SDKConfig with your secret token
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
// Create a Moonsense Client with the SDKConfig
client := moonsense.NewClient(sdkConfig)
// Configure the journey list criteria.
//
// For this example, we want to retrieve 50 journeys per page that were created either with the
// Android or iOS SDKs and were created during the month of January, 2023.
journeyListConfig := config.ListJourneyConfig{
JourneysPerPage: 50,
Platforms: []commonProto.DevicePlatform{commonProto.DevicePlatform_ANDROID, commonProto.DevicePlatform_iOS},
Since: time.Date(2023, time.January, 1, 0, 0, 0, 0, time.Local),
Until: time.Date(2023, time.January, 31, 23, 59, 59, 999, time.Local),
}
// Fetch the first page of journeys with the specified configuration.
paginatedJourneys, err := client.ListJourneys(journeyListConfig)
for {
if err != nil {
fmt.Println("Error fetching journey list")
fmt.Println(err)
break
}
// Iterate over the returned journeys, printing out the journey information
for _, journey := range paginatedJourneys.Journeys {
fmt.Println(journey)
}
// After iterating across the first page of journeys, check to see if there are more available for this
// criteria, and if so, fetch the next page of journeys.
if paginatedJourneys.HasMore() {
paginatedJourneys, err = paginatedJourneys.NextPage()
} else {
break
}
}
}
Example (ListRegions) ¶
package main
import (
"fmt"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
)
func main() {
// Create an SDKConfig with your secret token
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
// Create a Moonsense Client with the SDKConfig
client := moonsense.NewClient(sdkConfig)
// Fetch the regions and print them
regions, err := client.ListRegions()
if err != nil {
fmt.Println("Error fetching region list")
fmt.Println(err)
return
}
fmt.Println(regions)
}
Example (ListSessionFeatures) ¶
package main
import (
"fmt"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
)
func main() {
// Create an SDKConfig with your secret token
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
// Create a Moonsense Client with the SDKConfig
client := moonsense.NewClient(sdkConfig)
// Fetch the Features for the specified session
featuresList, err := client.ListSessionFeatures("some session id", nil)
if err != nil {
fmt.Println("Error fetching session features")
fmt.Println(err)
return
}
fmt.Println(featuresList)
}
Example (ListSessionSignals) ¶
package main
import (
"fmt"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
)
func main() {
// Create an SDKConfig with your secret token
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
// Create a Moonsense Client with the SDKConfig
client := moonsense.NewClient(sdkConfig)
// Fetch the Signals for the specified session
signalsList, err := client.ListSessionSignals("some session id", nil)
if err != nil {
fmt.Println("Error fetching session signals")
fmt.Println(err)
return
}
fmt.Println(signalsList)
}
Example (ListSessions) ¶
package main
import (
"fmt"
"time"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
commonProto "github.com/moonsense/go-sdk/moonsense/models/pb/v2/common"
)
func main() {
// Create an SDKConfig with your secret token
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
// Create a Moonsense Client with the SDKConfig
client := moonsense.NewClient(sdkConfig)
// Configure the session list criteria.
//
// For this example, we want to retrieve 50 sessions per page that were created either with the
// Android or iOS SDKs with a label of "suspect_session" and were created during the month of January, 2023.
sessionListConfig := config.ListSessionConfig{
SessionsPerPage: 50,
Labels: []string{"suspect_session"},
Platforms: []commonProto.DevicePlatform{commonProto.DevicePlatform_ANDROID, commonProto.DevicePlatform_iOS},
Since: time.Date(2023, time.January, 1, 0, 0, 0, 0, time.Local),
Until: time.Date(2023, time.January, 31, 23, 59, 59, 999, time.Local),
}
// Fetch the first page of sessions with the specified configuration.
paginatedSessions, err := client.ListSessions(sessionListConfig)
for {
if err != nil {
fmt.Println("Error fetching session list")
fmt.Println(err)
break
}
// Iterate over the returned sessions, printing out a subset of information
for _, session := range paginatedSessions.Sessions {
fmt.Printf("SessionId: %s, %s - %s\n", session.SessionId, session.Metadata.Platform.String(), session.CreatedAt.AsTime())
}
// After iterating across the first page of sessions, check to see if there are more available for this
// criteria, and if so, fetch the next page of sessions.
if paginatedSessions.HasMore() {
paginatedSessions, err = paginatedSessions.NextPage()
} else {
break
}
}
}
Example (ReadSession) ¶
package main
import (
"fmt"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
)
func main() {
// Create an SDKConfig with your secret token
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
// Create a Moonsense Client with the SDKConfig
client := moonsense.NewClient(sdkConfig)
// Read the sealed bundles for the specified session
sealedBundles, err := client.ReadSession("some session id", nil)
if err != nil {
fmt.Println("Error fetching sealed bundles for session")
fmt.Println(err)
}
fmt.Println(sealedBundles)
}
Example (UpdateSessionLabels) ¶
package main
import (
"fmt"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
)
func main() {
// Create an SDKConfig with your secret token
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
// Create a Moonsense Client with the SDKConfig
client := moonsense.NewClient(sdkConfig)
sessionId := "some session id"
// Fetch the session information for the specified sessionID
session, err := client.DescribeSession(sessionId, false)
if err != nil {
fmt.Println("Error fetching session")
fmt.Println(err)
return
}
// Examine the current labels
if len(session.Labels) > 0 {
fmt.Println(session.Labels)
}
// UpdateSessionLabels() replaces the current labels with the provided set of labels
newLabels := []string{"data_validation_success", "pointer_feature_generator_validation"}
err = client.UpdateSessionLabels(sessionId, newLabels)
if err != nil {
fmt.Println("Error updating session labels")
fmt.Println(err)
return
}
fmt.Println("Labels updated successfully")
}
Example (WhoAmI) ¶
package main
import (
"fmt"
"github.com/moonsense/go-sdk/moonsense"
"github.com/moonsense/go-sdk/moonsense/config"
)
func main() {
// Create an SDKConfig with your secret token
sdkConfig := config.SDKConfig{
SecretToken: "<YOUR SECRET_TOKEN>",
}
// Create a Moonsense Client with the SDKConfig
client := moonsense.NewClient(sdkConfig)
response, err := client.WhoAmI()
if err != nil {
fmt.Println("Error fetching token information")
fmt.Println(err)
return
}
fmt.Println(response)
}
Index ¶
Examples ¶
- Package (AddJourneyFeedback)
- Package (DescribeJourney)
- Package (DescribeSession)
- Package (GetJourneyFeedback)
- Package (ListJourneys)
- Package (ListRegions)
- Package (ListSessionFeatures)
- Package (ListSessionSignals)
- Package (ListSessions)
- Package (ReadSession)
- Package (UpdateSessionLabels)
- Package (WhoAmI)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
// ListRegions retrieves the list of Data Plane regions in the Moonsense Cloud.
//
// These regions are used for data ingest and storage. Data is encrypted while at-rest
// and in-transit. Granular data never leaves a region.
//
// See: https://api.moonsense.cloud/v2/regions
ListRegions() ([]*controlPlaneProto.DataPlaneRegion, *api.ApiErrorResponse)
// ListJourneys lists the journeys for the current project.
ListJourneys(listJourneyConfig config.ListJourneyConfig) (*models.PaginatedJourneyList, *api.ApiErrorResponse)
// DescribeJourney returns the details of a journey with the specified journeyId. The journey
// response includes the list of sessions associated with the journey.
DescribeJourney(journeyId string) (*dataPlaneProto.JourneyDetailResponse, *api.ApiErrorResponse)
// GetJourneyFeedback returns the feedback associated with a journey with the specified journeyId.
GetJourneyFeedback(journeyId string) (*journeyFeedbackProto.JourneyFeedback, *api.ApiErrorResponse)
// AddJourneyFeedback sets the feedback associated with a journey with the specified journeyId.
// Feedback is additive. If the feedback type already exists, it will be overwritten. If the
// feedback type does not exist, it will be added.
AddJourneyFeedback(journeyId string, feedback *journeyFeedbackProto.JourneyFeedback) *api.ApiErrorResponse
// ListSessions lists the sessions for the current project
ListSessions(listSessionConfig config.ListSessionConfig) (*models.PaginatedSessionList, *api.ApiErrorResponse)
// DescribeSession returns the details of a session with the specified sessionId. If minimal is set to true
// only total values are returned for counters.
DescribeSession(sessionId string, minimal bool) (*dataPlaneSDKProto.Session, *api.ApiErrorResponse)
// ListSessionFeatures returns the features for the specified sessionId. If region is not provided, the
// appropriate region will be looked up by calling DescribeSession first.
ListSessionFeatures(sessionId string, region *string) (*dataPlaneProto.SessionFeaturesResponse, *api.ApiErrorResponse)
// ListSessionSignals returns the signals for the specified sessionId. If region is not provided, the
// appropriate region will be looked up by calling DescribeSession first.
ListSessionSignals(sessionId string, region *string) (*dataPlaneProto.SignalsResponse, *api.ApiErrorResponse)
// ReadSession reads all data points for the specified Session that were collected so far. If region is not
// provided, the appropriate region will be looked up by calling DescribeSession first.
ReadSession(sessionId string, region *string) ([]*bundle.SealedBundle, *api.ApiErrorResponse)
// UpdateSessionLabels replaces the existing session labels with the provided labels for the specified sessionId.
UpdateSessionLabels(sessionId string, labels []string) *api.ApiErrorResponse
// WhoAmI describes the authentication token used to connect to the API
WhoAmI() (*commonProto.TokenSelfResponse, *api.ApiErrorResponse)
}
The Client interface defines the interface for interacting with the Moonsense Cloud.