All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.statsig.StatsigUser Maven / Gradle / Ivy

There is a newer version: 0.28.0
Show newest version
package com.statsig;

import com.google.gson.Gson;

import java.util.Map;

public class StatsigUser implements AutoCloseable {
    private int ref;

    // Just to make test easier
    public StatsigUser(String userId, String email) {
        this.ref = StatsigJNI.statsigUserCreate(userId, null, email, null,
                null, null, null,
                null, null, null);
    }

    public StatsigUser(
            String userId,
            Map customIds,
            String email,
            String ip,
            String userAgent,
            String country,
            String locale,
            String appVersion,
            Map custom,
            Map privateAttributes
    ) {
        Gson gson = new Gson();

        String customIdsJson = customIds != null ? gson.toJson(customIds) : null;
        String customJson = custom != null ? gson.toJson(custom) : null;
        String privateAttributesJson = privateAttributes != null ? gson.toJson(privateAttributes) : null;


        // Pass all arguments to the JNI binding
        this.ref = StatsigJNI.statsigUserCreate(
                userId,
                customIdsJson,
                email,
                ip,
                userAgent,
                country,
                locale,
                appVersion,
                customJson,
                privateAttributesJson
        );
    }

    @Override
    public void close() {
        if (ref != 0) {
            StatsigJNI.statsigUserRelease(this.ref);
            this.ref = 0;
        }
    }

    int getRef() {
        return ref;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy