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

com.minlessika.membership.integration.RestOrganization 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;
import org.cactoos.scalar.Sticky;
import org.cactoos.scalar.Unchecked;

public final class RestOrganization implements Organization {

    private final UUID uid;

    private final Unchecked response;

    private final RestClient client;

    public RestOrganization(final UUID uid, final RestClient client) {
        this.uid = uid;
        this.client = client;
        this.response = new Unchecked<>(
            new Sticky<>(
                () -> this.client.get(
                    "/api/organization",
                    ImmutableMap.of("uid", this.uid)
                ).asJsonObject()
            )
        );
    }

    @Override
    public UUID uid() {
        return this.uid;
    }

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

    @Override
    public Currency currency() {
        return new RestCurrency(
            this.client,
            this.client.get(
                "/api/currency",
                ImmutableMap.of("id", this.response.value().getString("currencyGuid"))
            ).asJsonObject()
        );
    }

    @Override
    public boolean hasApplicationInstalled(final String module) {
        return this.client.get(
            "/api/organization/application/has",
            ImmutableMap.of(
                "org", this.uid,
                "id", this.uid,
                "module", module
            )
        ).asJsonObject().getBoolean("value");
    }

    @Override
    public boolean applicationIsAvailable(final String module) {
        return this.client.get(
            "/api/organization/application/is-available",
            ImmutableMap.of(
                "org", this.uid,
                "id", this.uid,
                "module", module
            )
        ).asJsonObject().getBoolean("value");
    }

    @Override
    public void startApplicationInstallation(final String module) {
        this.client.post(
            "/api/organization/application/subscribe",
            ImmutableMap.of("org", this.uid),
            String.format("module=%s&organization=%s", module, this.uid)
        );
    }

    @Override
    public void finalizeApplicationInstallation(final String module) {
        this.client.post(
            "/api/organization/application/installation/finalize",
            ImmutableMap.of("org", this.uid),
            String.format("module=%s&organization=%s", module, this.uid)
        );
    }

    @Override
    public boolean hasCharacteristic(final String code) {
        return this.client.get(
            "/api/organization/characteristic/has",
            ImmutableMap.of(
                "org", this.uid,
                "code", code
            )
        ).asJsonObject().getBoolean("value");
    }

    @Override
    public String logo() {
        return this.response.value().getString("photo");
    }

    @Override
    public String phone1() {
        return this.response.value().getString("phone1");
    }

    @Override
    public String phone2() {
        return this.response.value().getString("phone2", "");
    }

    @Override
    public String headquarter() {
        return this.response.value().getString("headquarter");
    }

    @Override
    public String addressLine1() {
        return this.response.value().getString("addressLine1");
    }

    @Override
    public String addressLine2() {
        return this.response.value().getString("addressLine2", "");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy