package com.jakubsprega.untestable.code.f;

import com.google.common.io.CharStreams;
import com.google.gson.Gson;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;

/**
 * Google client
 * 
 * @author jakubsprega
 */
public class GoogleClient {

    public GoogleResult search(String searchPhrase) throws Exception {
        String googleApiUrl = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=";
        String charset = "UTF-8";
        URL url = new URL(googleApiUrl + URLEncoder.encode(searchPhrase, charset));
        String rawJsonGoogleResponse = CharStreams.toString(
            new InputStreamReader(url.openStream(), charset)
        );
        
        GoogleResult results = new Gson().fromJson(rawJsonGoogleResponse, GoogleResult.class);
        return results;
    }
}

@@ -483,26 +483,69 @@
     
-URL url = new URL(
+String googleRequestUrl = String.format(%0A            %22%25s%25s%22, 
 goog
@@ -556,10 +556,9 @@
 iUrl
- +
+,
  URL
@@ -594,16 +594,79 @@
 charset)
+%0A        );%0A        %0A        URL url = new URL(googleRequestUrl
 );%0A     
@@ -897,16 +897,25 @@
 class);%0A
+        %0A
         

Improve google client