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

com.minlessika.membership.integration.RestContact 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 RestContact implements Contact {

    private final Unchecked response;

    private final Organization organization;

    public RestContact(final RestClient client, final Organization organization, final JsonObject json) {
        this.response = new Unchecked<>(
            new Sticky<>(
                () -> json
            )
        );
        this.organization = organization;
    }

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

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

    @Override
    public String name() {
        try {
            return this.response.value().getString("name");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String photo() {
        try {
            return this.response.value().getString("photo");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Organization company() {
        return this.organization;
    }

    @Override
    public String addressLine1() {
        try {
            return this.response.value().getString("addressLine1");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String addressLine2() {
        try {
            return this.response.value().getString("addressLine2");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String city() {
        try {
            return this.response.value().getString("city");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String stateOrProvince() {
        try {
            return this.response.value().getString("stateOrProvince");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String email() {
        try {
            return this.response.value().getString("email");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String phone1() {
        try {
            return this.response.value().getString("phone1");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public ContactNature nature() {
        try {
            final boolean isCompany = this.response.value().getBoolean("is_company");
            if (isCompany) {
                return ContactNature.SOCIETY;
            } else {
                return ContactNature.PERSON;
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String phone2() {
        try {
            return this.response.value().getString("phone2");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String whatsApp() {
        try {
            return this.response.value().getString("whatsApp", "");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy