|
| 1 | +/* |
| 2 | + * Copyright 2014 Stackify |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.stackify.api.common; |
| 17 | + |
| 18 | +import com.stackify.api.EnvironmentDetail; |
| 19 | +import com.google.common.base.Objects; |
| 20 | + |
| 21 | +/** |
| 22 | + * ApiConfiguration |
| 23 | + * @author Eric Martin |
| 24 | + */ |
| 25 | +public class ApiConfiguration { |
| 26 | + |
| 27 | + /** |
| 28 | + * Default API URL |
| 29 | + */ |
| 30 | + private static final String DEFAULT_API_URL = "https://api.stackify.com"; |
| 31 | + |
| 32 | + /** |
| 33 | + * API URL |
| 34 | + */ |
| 35 | + private final String apiUrl; |
| 36 | + |
| 37 | + /** |
| 38 | + * API Key |
| 39 | + */ |
| 40 | + private final String apiKey; |
| 41 | + |
| 42 | + /** |
| 43 | + * Application name |
| 44 | + */ |
| 45 | + private final String application; |
| 46 | + |
| 47 | + /** |
| 48 | + * Environment |
| 49 | + */ |
| 50 | + private final String environment; |
| 51 | + |
| 52 | + /** |
| 53 | + * Environment details |
| 54 | + */ |
| 55 | + private final EnvironmentDetail envDetail; |
| 56 | + |
| 57 | + /** |
| 58 | + * @return the apiUrl |
| 59 | + */ |
| 60 | + public String getApiUrl() { |
| 61 | + return apiUrl != null ? apiUrl : DEFAULT_API_URL; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @return the apiKey |
| 66 | + */ |
| 67 | + public String getApiKey() { |
| 68 | + return apiKey; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @return the application |
| 73 | + */ |
| 74 | + public String getApplication() { |
| 75 | + return application; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * @return the environment |
| 80 | + */ |
| 81 | + public String getEnvironment() { |
| 82 | + return environment; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * @return the envDetail |
| 87 | + */ |
| 88 | + public EnvironmentDetail getEnvDetail() { |
| 89 | + return envDetail; |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * @param builder The Builder object that contains all of the values for initialization |
| 94 | + */ |
| 95 | + private ApiConfiguration(final Builder builder) { |
| 96 | + this.apiUrl = builder.apiUrl; |
| 97 | + this.apiKey = builder.apiKey; |
| 98 | + this.application = builder.application; |
| 99 | + this.environment = builder.environment; |
| 100 | + this.envDetail = builder.envDetail; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * @return A new instance of the Builder |
| 105 | + */ |
| 106 | + public static Builder newBuilder() { |
| 107 | + return new Builder(); |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * ApiConfiguration.Builder separates the construction of a ApiConfiguration from its representation |
| 112 | + */ |
| 113 | + public static class Builder { |
| 114 | + |
| 115 | + /** |
| 116 | + * The builder's apiUrl |
| 117 | + */ |
| 118 | + private String apiUrl; |
| 119 | + |
| 120 | + /** |
| 121 | + * The builder's apiKey |
| 122 | + */ |
| 123 | + private String apiKey; |
| 124 | + |
| 125 | + /** |
| 126 | + * The builder's application |
| 127 | + */ |
| 128 | + private String application; |
| 129 | + |
| 130 | + /** |
| 131 | + * The builder's environment |
| 132 | + */ |
| 133 | + private String environment; |
| 134 | + |
| 135 | + /** |
| 136 | + * The builder's envDetail |
| 137 | + */ |
| 138 | + private EnvironmentDetail envDetail; |
| 139 | + |
| 140 | + /** |
| 141 | + * Sets the builder's apiUrl |
| 142 | + * @param apiUrl The apiUrl to be set |
| 143 | + * @return Reference to the current object |
| 144 | + */ |
| 145 | + public Builder apiUrl(final String apiUrl) { |
| 146 | + this.apiUrl = apiUrl; |
| 147 | + return this; |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * Sets the builder's apiKey |
| 152 | + * @param apiKey The apiKey to be set |
| 153 | + * @return Reference to the current object |
| 154 | + */ |
| 155 | + public Builder apiKey(final String apiKey) { |
| 156 | + this.apiKey = apiKey; |
| 157 | + return this; |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * Sets the builder's application |
| 162 | + * @param application The application to be set |
| 163 | + * @return Reference to the current object |
| 164 | + */ |
| 165 | + public Builder application(final String application) { |
| 166 | + this.application = application; |
| 167 | + return this; |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * Sets the builder's environment |
| 172 | + * @param environment The environment to be set |
| 173 | + * @return Reference to the current object |
| 174 | + */ |
| 175 | + public Builder environment(final String environment) { |
| 176 | + this.environment = environment; |
| 177 | + return this; |
| 178 | + } |
| 179 | + |
| 180 | + /** |
| 181 | + * Sets the builder's envDetail |
| 182 | + * @param envDetail The envDetail to be set |
| 183 | + * @return Reference to the current object |
| 184 | + */ |
| 185 | + public Builder envDetail(final EnvironmentDetail envDetail) { |
| 186 | + this.envDetail = envDetail; |
| 187 | + return this; |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * @return A new object constructed from this builder |
| 192 | + */ |
| 193 | + public ApiConfiguration build() { |
| 194 | + return new ApiConfiguration(this); |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * @see java.lang.Object#toString() |
| 200 | + * @return A string representation of the object |
| 201 | + */ |
| 202 | + @Override |
| 203 | + public String toString() { |
| 204 | + return Objects.toStringHelper(this) |
| 205 | + .omitNullValues() |
| 206 | + .add("apiUrl", apiUrl) |
| 207 | + .add("apiKey", apiKey) |
| 208 | + .add("application", application) |
| 209 | + .add("environment", environment) |
| 210 | + .add("envDetail", envDetail) |
| 211 | + .toString(); |
| 212 | + } |
| 213 | +} |
0 commit comments