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

com.minlessika.membership.integration.RestCurrency 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.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");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy