Class SerpApiSearch

java.lang.Object
com.hw.serpapi.SerpApiSearch
Direct Known Subclasses:
GoogleSearch

public class SerpApiSearch extends Object
Due to Cant get this artifact from jitpack, I decided to add the serpapi-client module myself.

SerpApiSearch wraps HTTP interaction with the service serpapi.com

Author:
HamaWhite
  • Field Details

    • API_KEY_NAME

      public static final String API_KEY_NAME
      Set of constant
      See Also:
    • serpapiApiKey

      protected String serpapiApiKey
      user secret API key
    • engine

      protected String engine
      Current search engine
    • parameter

      public Map<String,String> parameter
      search parameters
  • Constructor Details

    • SerpApiSearch

      public SerpApiSearch(Map<String,String> parameter, String serpapiApiKey, String engine)
      Constructor
      Parameters:
      parameter - user search
      serpapiApiKey - secret user API key
      engine - service like: google, naver, yahoo...
    • SerpApiSearch

      public SerpApiSearch(Map<String,String> parameter, String engine)
      Constructor
      Parameters:
      parameter - user search
      engine - service like: google, yahoo, bing...
    • SerpApiSearch

      public SerpApiSearch(String engine)
      Constructor with no parameter
      Parameters:
      engine - service like: google, bing, yahoo...
    • SerpApiSearch

      public SerpApiSearch(String serpapiApiKey, String engine)
      Constructor
      Parameters:
      serpapiApiKey - secret API key
      engine - service like: google, bing, yahoo...
  • Method Details

    • buildQuery

      public Map<String,String> buildQuery(String path, String output) throws SerpApiSearchException
      Build a serp API query by expanding existing parameter
      Parameters:
      path - backend HTTP path
      output - type of output format (json, html, json_with_images)
      Returns:
      format parameter hash map
      Throws:
      SerpApiSearchException - wraps backend error message
    • getApiKeyFromEnv

      public static String getApiKeyFromEnv()
      Returns:
      current secret api key
    • getHtml

      public String getHtml() throws SerpApiSearchException
      Get HTML output
      Returns:
      raw HTML response from the search engine for custom parsing
      Throws:
      SerpApiSearchException - wraps backend error message
    • getJson

      public com.google.gson.JsonObject getJson() throws SerpApiSearchException
      Get JSON output
      Returns:
      JsonObject parent node
      Throws:
      SerpApiSearchException - wraps backend error message
    • asJson

      public com.google.gson.JsonObject asJson(String content)
      Convert HTTP content to JsonValue
      Parameters:
      content - raw JSON HTTP response
      Returns:
      JsonObject created by gson parser
    • getClient

      public SerpApiHttpClient getClient()
      Returns:
      http search
    • getLocation

      public com.google.gson.JsonArray getLocation(String q, Integer limit) throws SerpApiSearchException
      Get location
      Parameters:
      q - query
      limit - number of location
      Returns:
      JsonObject location using Location API
      Throws:
      SerpApiSearchException - wraps backend error message
    • getSearchArchive

      public com.google.gson.JsonObject getSearchArchive(String searchID) throws SerpApiSearchException
      Get search result from the Search Archive API
      Parameters:
      searchID - archived search result = search_metadata.id
      Returns:
      JsonObject search result
      Throws:
      SerpApiSearchException - wraps backend error message
    • getAccount

      public com.google.gson.JsonObject getAccount() throws SerpApiSearchException
      Get account information using Account API
      Returns:
      JsonObject account information
      Throws:
      SerpApiSearchException - wraps backend error message
    • setParameter

      public void setParameter(Map<String,String> parameter)