package edu.pdx.cs410J.apptbookweb;

import com.google.common.annotations.VisibleForTesting;
import edu.pdx.cs410J.web.HttpRequestHelper;

import java.io.IOException;

/**
 * A helper class for accessing the rest client
 */
public class AppointmentBookRestClient extends HttpRequestHelper
{
    private static final String WEB_APP = "apptbook";
    private static final String SERVLET = "appointments";

    private final String url;


    /**
     * Creates a client to the appointment book REST service running on the given host and port
     * @param hostName The name of the host
     * @param port The port
     */
    public AppointmentBookRestClient( String hostName, int port )
    {
        this.url = String.format( "http://%s:%d/%s/%s", hostName, port, WEB_APP, SERVLET );
    }

    /**
     * Returns all keys and values from the server
     */
    public Response getAllKeysAndValues() throws IOException
    {
        return get(this.url );
    }

    /**
     * Returns all values for the given key
     */
    public Response getValues( String key ) throws IOException
    {
        return get(this.url, "key", key);
    }

    public Response addKeyValuePair( String key, String value ) throws IOException
    {
        return postToMyURL("key", key, "value", value);
    }

    @VisibleForTesting
    Response postToMyURL(String... keysAndValues) throws IOException {
        return post(this.url, keysAndValues);
    }

    public Response removeAllMappings() throws IOException {
        return delete(this.url);
    }
}

@@ -285,13 +285,11 @@
 lper
-%0A
+ 
 %7B%0A
-  
   pr
@@ -336,18 +336,16 @@
 tbook%22;%0A
-  
   privat
@@ -395,18 +395,16 @@
 ts%22;%0A%0A  
- 
- 
 private 
@@ -423,26 +423,22 @@
  url;%0A%0A%0A
-  
   /**%0A
-  
    * Cre
@@ -522,26 +522,29 @@
 and port%0A   
+*%0A
   
+ 
 * @param hos
@@ -573,18 +573,16 @@
 host%0A   
-  
 * @param
@@ -587,16 +587,20 @@
 am port 
+    
 The port
@@ -599,31 +599,27 @@
 The port%0A   
-  
 */%0A
-  
   public App
@@ -641,17 +641,16 @@
 tClient(
- 
 String h
@@ -670,21 +670,12 @@
 port
- )%0A    %7B%0A    
+) %7B%0A
     
@@ -699,17 +699,16 @@
 .format(
- 
 %22http://
@@ -753,29 +753,24 @@
  SERVLET
- 
 );%0A
-  
   %7D%0A%0A
-  
   /**%0A  
@@ -762,34 +762,32 @@
 ;%0A  %7D%0A%0A  /**%0A   
- 
- 
 * Returns all ke
@@ -815,33 +815,29 @@
 e server%0A   
-  
 */%0A  
- 
- 
 public Respo
@@ -876,35 +876,27 @@
  IOException
-%0A    %7B%0A    
+ %7B%0A
     return g
@@ -910,29 +910,22 @@
 .url
- 
 );%0A  
- 
- 
 %7D%0A%0A  
- 
- 
 /**%0A
-  
    *
@@ -965,23 +965,19 @@
  key%0A   
-  
 */%0A
-  
   public
@@ -996,17 +996,16 @@
 tValues(
- 
 String k
@@ -1006,17 +1006,16 @@
 ring key
- 
 ) throws
@@ -1022,35 +1022,27 @@
  IOException
-%0A    %7B%0A    
+ %7B%0A
     return g
@@ -1067,25 +1067,21 @@
 , key);%0A
-  
   %7D%0A%0A
-  
   public
@@ -1106,17 +1106,16 @@
 luePair(
- 
 String k
@@ -1130,17 +1130,16 @@
 ng value
- 
 ) throws
@@ -1154,19 +1154,11 @@
 tion
-%0A    %7B%0A    
+ %7B%0A
     
@@ -1205,25 +1205,21 @@
 value);%0A
-  
   %7D%0A%0A
-  
   @Visib
@@ -1231,18 +1231,16 @@
 Testing%0A
-  
   Respon
@@ -1300,28 +1300,24 @@
 ption %7B%0A    
- 
-   
 return post(
@@ -1346,17 +1346,13 @@
 s);%0A
-  
   %7D%0A%0A
-  
   pu
@@ -1406,20 +1406,16 @@
 ption %7B%0A
-    
     retu
@@ -1435,16 +1435,14 @@
 s.url);%0A
-  
   %7D%0A%7D%0A

Indent with 2 space.