package br.com.alura.agenda.web;

import java.io.IOException;
import java.io.PrintStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;

/**
 * Created by renan on 20/01/16.
 */
public class WebClient {
    public String post(String json) {
        try {
            URL url = new URL("https://www.caelum.com.br/mobile");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestProperty("Content-type", "application/json");
            connection.setRequestProperty("Accept", "application/json");

            connection.setDoOutput(true);

            PrintStream output = new PrintStream(connection.getOutputStream());
            output.println(json);

            connection.connect();

            Scanner scanner = new Scanner(connection.getInputStream());
            String resposta = scanner.next();
            return resposta;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}

@@ -27,16 +27,61 @@
 a.web;%0A%0A
+import android.support.annotation.Nullable;%0A%0A
 import j
@@ -254,49 +254,8 @@
 r;%0A%0A
-/**%0A * Created by renan on 20/01/16.%0A */%0A
 publ
@@ -325,78 +325,294 @@
     
+S
 tr
-y %7B%0A            URL url = new URL(%22https://www.caelum.com.br/mobile%22
+ing endereco = %22https://www.caelum.com.br/mobile%22;%0A        return realizaConexao(json, endereco);%0A    %7D%0A%0A    public void insere(String json) %7B%0A%0A    %7D%0A%0A    @Nullable%0A    private String realizaConexao(String json, String endereco) %7B%0A        try %7B%0A            URL url = new URL(endereco
 );%0A 
@@ -1129,144 +1129,27 @@
     
-String resposta = scanner.next();%0A            return resposta;%0A        %7D catch (MalformedURLException e) %7B%0A            e.printStackTrace
+return scanner.next
 ();%0A
@@ -1252,11 +1252,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Refactor WebClient class to connect different endpoints