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

com.synedge.oss.client.SynedgeClientBuilder.groovy Maven / Gradle / Ivy

Go to download

This client allows you to easily connect to the Synedge API with any language running on the JDK

The newest version!
package com.synedge.oss.client

import groovy.transform.CompileStatic

/**
 * The Synedge client builder is the easiest way to get the Synedge client
 * It requires both username and password
 * @author Paul van Assen
 *
 */
@CompileStatic
class SynedgeClientBuilder {
    private String username
    private String password
    private String endpoint = SynedgeClient.DEFAULT_ENDPOINT
    
    /**
     * Creates the builder
     * @return An instance of the builder
     */
    static SynedgeClientBuilder create() {
        return new SynedgeClientBuilder()
    }
    private SynedgeClientBuilder() {
    }

    /**
     * Sets the username for the client
     * @param username Username to use for logging in
     * @return The builder for chaining
     */
    SynedgeClientBuilder withUsername(String username) {
        this.username = username
        this
    }
    /**
     * Sets the password for the client
     * @param password Password to use for logging in
     * @return The builder for chaining
     */
    SynedgeClientBuilder withPassword(String password) {
        this.password = password
        this
    }

    /**
     * Overrides the default endpoint
     * @param endpoint The new endpoint to use
     * @return The builder for chaining
     */
    SynedgeClientBuilder toEndpoint(String endpoint) {
        this.endpoint = endpoint
        this
    }

        /**
     * Builds the actual client. May throw IllegalArgumentException if required information is missing
     * @return The client, if all conditions are met
     * @throws IllegalArgumentException Exception if any information is missing
     */
    SynedgeClient build() throws IllegalArgumentException {
        if (!username?.trim()) {
            throw new IllegalArgumentException('Username must be supplied')
        }
        if (!password?.trim()) {
            throw new IllegalArgumentException('Password must be supplied')
        }
        new JerseySynedgeClient(username, password, endpoint);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy