com.minlessika.membership.integration.RestCurrency 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.UUID;
import javax.json.JsonObject;
public final class RestCurrency implements Currency {
private final RestClient client;
private final JsonObject json;
public RestCurrency(final RestClient client, final JsonObject json) {
this.client = client;
this.json = json;
}
@Override
public UUID uid() {
return UUID.fromString(this.json.getString("guid"));
}
@Override
public String code() {
return this.json.getString("code");
}
@Override
public String name() {
return this.json.getString("name");
}
@Override
public String symbol() {
return this.json.getString("symbol");
}
@Override
public boolean after() {
return this.json.getBoolean("after");
}
@Override
public int precision() {
return this.json.getInt("precision");
}
@Override
public double convert(final double amount, final Currency currency) {
return this.client.get(
"/api/currency/convert",
ImmutableMap.of(
"source", this.uid(),
"target", currency.uid(),
"amount", amount
)
).asJsonObject().getJsonNumber("amount").doubleValue();
}
@Override
public String toString(final double amount) {
return this.client.get(
"/api/currency/format",
ImmutableMap.of(
"id", this.uid(),
"amount", amount
)
).asJsonObject().getString("amount");
}
}