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

com.minlessika.membership.integration.RestUser Maven / Gradle / Ivy

Go to download

It's a library to help developers to integration membership services to another project.

There is a newer version: 0.3.1
Show newest version
package com.minlessika.membership.integration;

import com.google.common.collect.ImmutableMap;
import com.minlessika.http.client.RestClient;
import java.util.Locale;
import java.util.UUID;
import javax.json.JsonObject;

public final class RestUser implements User {

    private final JsonObject json;

    private final RestClient client;

    public RestUser(final RestClient client, final JsonObject json) {
        this.json = json;
        this.client = client;
    }

    public RestUser(final RestClient client, final UUID uid) {
        this(
            client,
            client.get(
                "/api/user",
                ImmutableMap.of("id", uid)
            ).asJsonObject()
        );
    }

    @Override
    public UUID uid() {
        return UUID.fromString(this.json.getString("guid"));
    }

    @Override
    public String name() {
        return this.json.getString("name");
    }

    @Override
    public String email() {
        return this.json.getString("email");
    }

    @Override
    public String photo() {
        return this.json.getString("photo", "");
    }

    @Override
    public Locale locale() {
        return Locale.forLanguageTag(
            this.json.getString("preferred_language")
        );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy