com.contentstack.sdk.Config Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java Show documentation
Show all versions of java Show documentation
Java SDK for Contentstack Content Delivery API
package com.contentstack.sdk;
/**
* MIT License
*
* Copyright (c) 2012 - 2019 Contentstack
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
public class Config {
protected String URLSCHEMA = "https://";
protected String URL = "cdn.contentstack.io";
protected String VERSION = "v3";
protected String environment = null;
protected ContentstackRegion region = ContentstackRegion.US;
public enum ContentstackRegion { US, EU }
public ContentstackRegion getRegion() { return this.region; }
/**
* Sets region allow you to set your region for the Contentstack server.
* @param region type {@link ContentstackRegion}
* @return ContentstackRegion
*
*
* Note:
* Default region sets to us
*
*
Example :
*
* config.setRegion(ContentstackRegion.US);
*
*/
public ContentstackRegion setRegion(ContentstackRegion region) {
this.region = region;
return this.region;
}
/**
* Config constructor
*
*
Example :
*
* Config config = new Config();
*
*/
public Config(){}
/**
* Sets host name of the Contentstack server.
*
* @param hostName
* host name.
*
*
* Note: Default hostname sets to cdn.contentstack.io
* and default protocol is HTTPS.
*
Example :
*
* config.setHost("cdn.contentstack.io");
*
*/
public void setHost(String hostName){
if(hostName != null && !hostName.isEmpty()) {
URL = hostName;
}
}
/**
*
* @return URL String
*
Example :
*
* String url = config.getHost();
*
*/
public String getHost(){
return URL;
}
/**
* Get version of the Contentstack server.
* @return VERSION String
*
Example :
*
* String version = config.getVersion();
*
*/
public String getVersion(){
return VERSION;
}
/**
* Changes the Contentstack version to be used in the final URL.
*
* @param version version string.
*
*
Example :
*
* config.setVersion("v3");
*
*/
private void setVersion(String version){
if(version != null && !version.isEmpty()) {
VERSION = version;
}
}
/**
* set environment.
*
* @param environment uid/name
*
*
Example :
*
* config.setEnvironment("stag", false);
*
*/
protected void setEnvironment(String environment){
if(environment != null && !environment.isEmpty()) {
this.environment = environment;
}
}
/**
* Get environment.
* @return param environment string
*
Example :
*
* String environment = config.getEnvironment();
*
*/
public String getEnvironment(){
return environment;
}
}