// Copyright 2010 Square, Inc.
package retrofit.http;

import java.util.Properties;

/**
 * Server information. Applications may extend this class and return different URLs over time.
 * Callers should always consult the Server instance for the latest values rather than caching URLs.
 *
 * @author Bob Lee (bob@squareup.com)
 */
public class Server {

  private final String apiUrl;
  private final String webUrl;
  private final boolean ignoreSslWarnings;

  protected Server(String apiUrl, String webUrl, boolean ignoreSslWarnings) {
    this.apiUrl = apiUrl;
    this.webUrl = webUrl;
    this.ignoreSslWarnings = ignoreSslWarnings;
  }

  /**
   * Gets the base API url. Includes a trailing '/'.
   */
  public String apiUrl() {
    return apiUrl;
  }

  /**
   * Gets the base URL for Square's web site. Includes a trailing '/'.
   */
  public String webUrl() {
    return webUrl;
  }

  public String getType() {
    return "production";
  }

  /**
   * Returns true if we should ignore SSL warnings. Returns false by default.
   * Ignored for development servers.
   */
  public boolean ignoreSslWarnings() {
    return ignoreSslWarnings;
  }

  /**
   * Creates a Server instance from Properties. Requires "api.url" and
   * "web.url". "disable.ssl.warnings" is optional.
   */
  public static Server from(Properties properties) {
    String apiUrl = properties.getProperty("api.url");
    if (apiUrl == null) throw new NullPointerException("Missing api.url.");
    String webUrl = properties.getProperty("web.url");
    if (webUrl == null) throw new NullPointerException("Missing web.url.");
    String disableSslWarnings = properties.getProperty("disable.ssl.warnings",
        "false");
    return new Server(apiUrl, webUrl, Boolean.valueOf(disableSslWarnings));
  }
}

@@ -52,38 +52,8 @@
 p;%0A%0A
-import java.util.Properties;%0A%0A
 /**%0A
@@ -316,16 +316,75 @@
 rver %7B%0A%0A
+  public static final String DEFAULT_TYPE = %22production%22;%0A%0A
   privat
@@ -433,24 +433,53 @@
 ing webUrl;%0A
+  private final String type;%0A
   private fi
@@ -517,16 +517,238 @@
 %0A  p
-rotected
+ublic Server(String apiUrl, String webUrl) %7B%0A    this(apiUrl, webUrl, false);%0A  %7D%0A%0A  public Server(String apiUrl, String webUrl, boolean ignoreSslWarnings) %7B%0A    this(apiUrl, webUrl, DEFAULT_TYPE, ignoreSslWarnings);%0A  %7D%0A%0A  public
  Ser
@@ -772,32 +772,45 @@
 , String webUrl,
+ String type,
  boolean ignoreS
@@ -831,29 +831,150 @@
     
-this.apiUrl = apiUrl;
+if (!apiUrl.endsWith(%22/%22)) %7B%0A      apiUrl += %22/%22;%0A    %7D%0A    this.apiUrl = apiUrl;%0A%0A    if (!webUrl.endsWith(%22/%22)) %7B%0A      webUrl += %22/%22;%0A    %7D
 %0A   
@@ -995,16 +995,39 @@
  webUrl;
+%0A%0A    this.type = type;
 %0A    thi
@@ -1318,24 +1318,123 @@
 ebUrl;%0A  %7D%0A%0A
+  /**%0A   * Gets a human-readable server type for differentiating between multiple instances.%0A   */%0A
   public Str
@@ -1441,12 +1441,9 @@
 ing 
-getT
+t
 ype(
@@ -1457,28 +1457,20 @@
  return 
-%22production%22
+type
 ;%0A  %7D%0A%0A 
@@ -1672,635 +1672,7 @@
 %0A  %7D
-%0A%0A  /**%0A   * Creates a Server instance from Properties. Requires %22api.url%22 and%0A   * %22web.url%22. %22disable.ssl.warnings%22 is optional.%0A   */%0A  public static Server from(Properties properties) %7B%0A    String apiUrl = properties.getProperty(%22api.url%22);%0A    if (apiUrl == null) throw new NullPointerException(%22Missing api.url.%22);%0A    String webUrl = properties.getProperty(%22web.url%22);%0A    if (webUrl == null) throw new NullPointerException(%22Missing web.url.%22);%0A    String disableSslWarnings = properties.getProperty(%22disable.ssl.warnings%22,%0A        %22false%22);%0A    return new Server(apiUrl, webUrl, Boolean.valueOf(disableSslWarnings));%0A  %7D
 %0A%7D%0A

Clean up Server class a bit.