com.minlessika.membership.integration.RestUser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of membership-integration Show documentation
Show all versions of membership-integration Show documentation
It's a library to help developers to integration membership services to another project.
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")
);
}
}