package com.auth0.net;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.codec.binary.Base64;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("WeakerAccess")
class Telemetry {
    static final String HEADER_NAME = "Auth0-Client";

    private static final String NAME_KEY = "name";
    private static final String VERSION_KEY = "version";
    private static final String CORE_KEY = "core";
    private static final String ENV_KEY = "env";
    private static final String JAVA_KEY = "java";

    private final String name;
    private final String version;
    private final String core;
    private final Map<String, String> env;
    private final String value;

    Telemetry(String name, String version) {
        this(name, version, null);
    }

    Telemetry(String name, String version, String core) {
        this.name = name;
        this.version = version;
        this.core = core;

        Map<String, Object> values = new HashMap<>();
        if (name != null) {
            values.put(NAME_KEY, name);
        }
        if (version != null) {
            values.put(VERSION_KEY, version);
        }

        HashMap<String, String> tmpEnv = new HashMap<>();
        tmpEnv.put(JAVA_KEY, Runtime.class.getPackage().getSpecificationVersion());
        if (core != null) {
            tmpEnv.put(CORE_KEY, core);
        }
        this.env = Collections.unmodifiableMap(tmpEnv);
        values.put(ENV_KEY, env);

        String tmpValue;
        try {
            String json = new ObjectMapper().writeValueAsString(values);
            tmpValue = Base64.encodeBase64URLSafeString(json.getBytes());
        } catch (JsonProcessingException e) {
            tmpValue = null;
            e.printStackTrace();
        }
        value = tmpValue;
    }

    public String getName() {
        return name;
    }

    public String getVersion() {
        return version;
    }

    //Visible for testing
    String getLibraryVersion() {
        return core;
    }

    //Visible for testing
    Map<String, String> getEnvironment() {
        return env;
    }

    public String getValue() {
        return value;
    }
}

package com.auth0.net;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.codec.binary.Base64;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("WeakerAccess")
public class Telemetry {
    static final String HEADER_NAME = "Auth0-Client";

    private static final String NAME_KEY = "name";
    private static final String VERSION_KEY = "version";
    private static final String CORE_KEY = "core";
    private static final String ENV_KEY = "env";
    private static final String JAVA_KEY = "java";

    private final String name;
    private final String version;
    private final String core;
    private final Map<String, String> env;
    private final String value;

    public Telemetry(String name, String version) {
        this(name, version, null);
    }

    public Telemetry(String name, String version, String core) {
        this.name = name;
        this.version = version;
        this.core = core;

        Map<String, Object> values = new HashMap<>();
        if (name != null) {
            values.put(NAME_KEY, name);
        }
        if (version != null) {
            values.put(VERSION_KEY, version);
        }

        HashMap<String, String> tmpEnv = new HashMap<>();
        tmpEnv.put(JAVA_KEY, Runtime.class.getPackage().getSpecificationVersion());
        if (core != null) {
            tmpEnv.put(CORE_KEY, core);
        }
        this.env = Collections.unmodifiableMap(tmpEnv);
        values.put(ENV_KEY, env);

        String tmpValue;
        try {
            String json = new ObjectMapper().writeValueAsString(values);
            tmpValue = Base64.encodeBase64URLSafeString(json.getBytes());
        } catch (JsonProcessingException e) {
            tmpValue = null;
            e.printStackTrace();
        }
        value = tmpValue;
    }

    public String getName() {
        return name;
    }

    public String getVersion() {
        return version;
    }

    //Visible for testing
    String getLibraryVersion() {
        return core;
    }

    //Visible for testing
    Map<String, String> getEnvironment() {
        return env;
    }

    public String getValue() {
        return value;
    }
}

make Telemetry a public class