go-sdk

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2023 License: Apache-2.0

README

Moonsense SDK for Go

Go Reference Apache V2 License

Simple Go SDK for the Moonsense Cloud API.

Installation

Install the module using go get:

go get github.com/moonsense/go-sdk

Getting Started

Start by getting an API secret key by navigating to App in Console and creating 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
        }
    }

    // Fetch features for a specific session. Specifying the 
    // region the session is in will result in a faster lookup
    features, err := client.ListSessionFeatures("<session-id>", "asia-south1.gcp")
	if err != nil {
		fmt.Println("Error fetching session features")
		fmt.Println(err)
		return
	}

	fmt.Println(features)

    // Fetch signals for a specific session. Specifying the 
    // region the session is in will result in a faster lookup
    signals, err := client.ListSessionSignals("<session-id>", "asia-south1.gcp")
	if err != nil {
		fmt.Println("Error fetching session signals")
		fmt.Println(err)
		return
	}

	fmt.Println(signals)
}
Add Journey Feedback

Adding feedback to journeys provides a mechanism for tracking some special details against a given journey. For example, if a journey is determined to contain fraud, the journey can be flagged as fraudulent using Journey Feedback.

   err := client.AddJourneyFeedback(journeyId, &journeysProto.JourneyFeedback{
   	FraudFeedback: &journeysProto.FraudFeedback{
   		IsFraud:     true,
   		ReportedAt:  timestamppb.Now(),
   		FraudReason: "It was fraud because...",
   	},
   })

See example_test.go for further examples.

Terms Of Service

The Moonsense Go SDK is distributed under the Moonsense Terms Of Service.

Support

Feel free to raise an Issue around bugs, usage, concerns or feedback.

Directories

Path Synopsis
Package moonsense is the official Moonsense SDK for the Go programming language.
Package moonsense is the official Moonsense SDK for the Go programming language.
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL