Class SerpApiHttpClient

java.lang.Object
com.hw.serpapi.SerpApiHttpClient

public class SerpApiHttpClient extends Object
HTTPS search for Serp API
Author:
HamaWhite
  • Field Details

    • VERSION

      public static String VERSION
      current API version
    • BACKEND

      public static String BACKEND
      backend service
    • path

      public String path
      current backend HTTP path
  • Constructor Details

    • SerpApiHttpClient

      public SerpApiHttpClient(String path)
      Constructor
      Parameters:
      path - HTTP url path
  • Method Details

    • buildConnection

      protected HttpURLConnection buildConnection(String path, Map<String,String> parameter) throws SerpApiSearchException
      Build URL
      Parameters:
      path - url end point
      parameter - search parameter map like: { "q": "coffee", "location": "Austin, TX"}
      Returns:
      httpUrlConnection
      Throws:
      SerpApiSearchException - wraps error message
    • getResults

      public String getResults(Map<String,String> parameter) throws SerpApiSearchException
      Get results
      Parameters:
      parameter - user search parameters
      Returns:
      http response body
      Throws:
      SerpApiSearchException - wraps error message
    • triggerSerpApiClientException

      protected void triggerSerpApiClientException(String content) throws SerpApiSearchException
      trigger a exception on error
      Parameters:
      content - raw JSON response from serpapi.com
      Throws:
      SerpApiSearchException - wraps error message
    • getHttpConnectionTimeout

      public int getHttpConnectionTimeout()
      Returns:
      current HTTP connection timeout
    • setHttpConnectionTimeout

      public void setHttpConnectionTimeout(int httpConnectionTimeout)
      Parameters:
      httpConnectionTimeout - set HTTP connection timeout
    • getHttpReadTimeout

      public int getHttpReadTimeout()
      Returns:
      current HTTP read timeout
    • setHttpReadTimeout

      public void setHttpReadTimeout(int httpReadTimeout)
      Parameters:
      httpReadTimeout - set HTTP read timeout