完善任务接口逻辑以及Eran事件上报接入
This commit is contained in:
45
internal/pkg/earn/earn.go
Normal file
45
internal/pkg/earn/earn.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package earn
|
||||
|
||||
import (
|
||||
ea "github.com/earn-alliance/earnalliance-go"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ClientId string
|
||||
ClientSecret string
|
||||
GameId string
|
||||
Dsn string `json:",optional"`
|
||||
FlushCooldown time.Duration `json:",optional"`
|
||||
FlushInterval time.Duration `json:",optional"`
|
||||
BatchSize int `json:",optional"`
|
||||
}
|
||||
|
||||
func (c Config) BuildEarnClient() *ea.Client {
|
||||
clientBuilder := ea.NewClientBuilder().
|
||||
WithClientID(c.ClientId).
|
||||
WithClientSecret(c.ClientSecret).
|
||||
WithGameID(c.GameId)
|
||||
|
||||
if c.Dsn != "" {
|
||||
clientBuilder = clientBuilder.WithDSN(c.Dsn)
|
||||
}
|
||||
|
||||
if c.FlushCooldown > 0 {
|
||||
clientBuilder = clientBuilder.WithFlushCooldown(c.FlushCooldown)
|
||||
}
|
||||
|
||||
if c.FlushInterval > 0 {
|
||||
clientBuilder = clientBuilder.WithFlushInterval(c.FlushInterval)
|
||||
}
|
||||
|
||||
if c.BatchSize > 0 {
|
||||
clientBuilder = clientBuilder.WithBatchSize(c.BatchSize)
|
||||
}
|
||||
|
||||
return clientBuilder.Build()
|
||||
}
|
||||
|
||||
const (
|
||||
EVENT_BIND_ROLE = "BIND_ROLE"
|
||||
)
|
||||
33
internal/pkg/earn/earn_test.go
Normal file
33
internal/pkg/earn/earn_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package earn
|
||||
|
||||
import (
|
||||
ea "github.com/earn-alliance/earnalliance-go"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestEarn(t *testing.T) {
|
||||
clientID := "4d6269e3-8aac-4550-acf9-dc891caf20a8"
|
||||
clientSecret := "GJpQ4TmX4p2VMY7U3XtExZQKYfibMv24"
|
||||
gameID := "c0deda99-bb15-47a2-a3be-f1fe2983cde2"
|
||||
c := Config{
|
||||
ClientId: clientID,
|
||||
ClientSecret: clientSecret,
|
||||
GameId: gameID,
|
||||
FlushCooldown: time.Second,
|
||||
}
|
||||
e := c.BuildEarnClient()
|
||||
userId := "8006586979"
|
||||
e.SetIdentifiers(userId, &ea.Identifiers{
|
||||
Email: ea.IdentifierFrom("test-mail@earn.com"),
|
||||
EpicGamesID: ea.IdentifierFrom("78657657"),
|
||||
//WalletAddress: ea.IdentifierFrom("0x0769d094"),
|
||||
})
|
||||
e.StartGame(userId)
|
||||
e.Track(userId, "TEST_EVENT", ea.PointerFrom(100), map[string]any{"level": 88})
|
||||
time.Sleep(time.Second * 2)
|
||||
err := e.Flush()
|
||||
require.Nil(t, err)
|
||||
e.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user