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

co.omise.Endpoint Maven / Gradle / Ivy

There is a newer version: 5.1.0
Show newest version
package co.omise;

import co.omise.resources.Resource;
import com.google.common.collect.ImmutableList;
import okhttp3.CertificatePinner;
import okhttp3.HttpUrl;

/**
 * Endpoints encapsulates information about a particular Omise API endpoint.
 * Currently there exists 2 endpoints, the API and the VAULT.
 * 

* This class encapsulates the following information for each endpoint: *

    *
  • Host and network scheme (defaults to HTTPS.)
  • *
  • The certificate hash to pin against.
  • *
  • Wether to use the public key or the secret key.
  • *
* * @see Resource */ public abstract class Endpoint { public static final Endpoint VAULT = new Endpoint() { @Override public String host() { return "vault.omise.co"; } @Override public String authenticationKey(Config config) { return config.publicKey(); } }; public static final Endpoint API = new Endpoint() { @Override public String host() { return "api.omise.co"; } @Override public String authenticationKey(Config config) { return config.secretKey(); } }; public static ImmutableList all() { return ImmutableList.of( Endpoint.API, Endpoint.VAULT ); } /** * The scheme to use, defaults to HTTPS. * * @return A {@link String} containing the network scheme to use. */ public String scheme() { return "https"; } /** * The host name to connect to. * * @return A {@link String} containing the host name to connect to. */ public abstract String host(); /** * The certificate hash to use with OkHttp's {@link CertificatePinner}. * The default implementation returns a certificate hash for {@code *.omise.co} domains. * * @return A {@link String} containing the cert hash to pin against or {@code null} to * pin no certificate. */ public String certificateHash() { return "sha256/maqNsxEnwszR+xCmoGUiV636PvSM5zvBIBuupBn9AB8="; } /** * The authentication key to use. The key should be taken from the given {@link Config} object. * Either {@link Config#publicKey()} or {@link Config#secretKey()} should be returned. * * @param config A {@link Config} instance. * @return A {@link String} containing the authentication key. */ public abstract String authenticationKey(Config config); public HttpUrl.Builder buildUrl() { return new HttpUrl.Builder() .scheme(scheme()) .host(host()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy