/*
 * The MIT License
 *
 * Copyright (c) 2016 Marcelo "Ataxexe" Guimarães <ataxexe@devnull.tools>
 *
 * 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.
 */

package tools.devnull.boteco.client.rest;

import com.google.gson.Gson;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.HttpClients;

import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;

public class DefaultRestClient implements RestClient {

  private final HttpClient client;

  public DefaultRestClient(HttpClient client) {
    this.client = client;
  }

  public DefaultRestClient() {
    this(HttpClients.createDefault());
  }

  @Override
  public RestConfiguration post(URI uri) throws IOException {
    return execute(new HttpPost(uri));
  }

  @Override
  public RestConfiguration post(String url) throws IOException {
    return execute(new HttpPost(url));
  }

  @Override
  public RestConfiguration get(URI uri) throws IOException {
    return execute(new HttpGet(uri));
  }

  @Override
  public RestConfiguration get(String url) throws IOException {
    return execute(new HttpGet(url));
  }

  private RestConfiguration execute(HttpUriRequest request) throws IOException {
    HttpResponse response = client.execute(request);
    String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
    Gson gson = new Gson();
    return new RestConfiguration() {
      @Override
      public RestConfiguration withHeader(String name, Object value) {
        request.addHeader(name, String.valueOf(value));
        return this;
      }

      @Override
      public String rawBody() {
        return content;
      }

      @Override
      public <E> E to(Class<? extends E> type) {
        return gson.fromJson(content, type);
      }
    };
  }
}

@@ -1472,19 +1472,168 @@
 ods.Http
-Get
+Delete;%0Aimport org.apache.http.client.methods.HttpGet;%0Aimport org.apache.http.client.methods.HttpHead;%0Aimport org.apache.http.client.methods.HttpOptions
 ;%0Aimport
@@ -1670,24 +1670,71 @@
 s.HttpPost;%0A
+import org.apache.http.client.methods.HttpPut;%0A
 import org.a
@@ -2585,32 +2585,32 @@
 s IOException %7B%0A
-
     return execu
@@ -2636,16 +2636,988 @@
 );%0A  %7D%0A%0A
+  @Override%0A  public RestConfiguration delete(URI uri) throws IOException %7B%0A    return execute(new HttpDelete(uri));%0A  %7D%0A%0A  @Override%0A  public RestConfiguration delete(String url) throws IOException %7B%0A    return execute(new HttpDelete(url));%0A  %7D%0A%0A  @Override%0A  public RestConfiguration put(URI uri) throws IOException %7B%0A    return execute(new HttpPut(uri));%0A  %7D%0A%0A  @Override%0A  public RestConfiguration put(String url) throws IOException %7B%0A    return execute(new HttpPut(url));%0A  %7D%0A%0A  @Override%0A  public RestConfiguration head(URI uri) throws IOException %7B%0A    return execute(new HttpHead(uri));%0A  %7D%0A%0A  @Override%0A  public RestConfiguration head(String url) throws IOException %7B%0A    return execute(new HttpHead(url));%0A  %7D%0A%0A  @Override%0A  public RestConfiguration options(URI uri) throws IOException %7B%0A    return execute(new HttpOptions(uri));%0A  %7D%0A%0A  @Override%0A  public RestConfiguration options(String url) throws IOException %7B%0A    return execute(new HttpOptions(url));%0A  %7D%0A%0A
   privat

add more verbs