@@ -38,14 +38,23 @@ public SerpApi(Map<String, String> parameter) {
3838 this .parameter = parameter ;
3939 }
4040
41+ /***
42+ * Constructor
43+ *
44+ * @param parameter default search parameter should include {"api_key": "secret_api_key", "engine": "google" }
45+ */
46+ public SerpApi () {
47+ this .parameter = new HashMap ();
48+ }
49+
4150 /***
4251 * Returns HTML search results as a raw HTML String
4352 *
4453 * @param parameter html search parameter
4554 * @return raw HTML response from the client engine for custom parsing
4655 * @throws SerpApiException wraps backend error message
4756 */
48- public String html (HashMap <String , String > parameter ) throws SerpApiException {
57+ public String html (Map <String , String > parameter ) throws SerpApiException {
4958 return get ("/client" , "html" , parameter );
5059 }
5160
@@ -56,8 +65,8 @@ public String html(HashMap<String, String> parameter) throws SerpApiException {
5665 * @return JsonObject search results parent node
5766 * @throws SerpApiException wraps backend error message
5867 */
59- public JsonObject search (HashMap <String , String > parameter ) throws SerpApiException {
60- return json ("/client " , parameter );
68+ public JsonObject search (Map <String , String > parameter ) throws SerpApiException {
69+ return json ("/search " , parameter );
6170 }
6271
6372 /***
@@ -67,7 +76,7 @@ public JsonObject search(HashMap<String, String> parameter) throws SerpApiExcept
6776 * @return JsonObject location using Location API
6877 * @throws SerpApiException wraps backend error message
6978 */
70- public JsonObject location (HashMap <String , String > parameter ) throws SerpApiException {
79+ public JsonObject location (Map <String , String > parameter ) throws SerpApiException {
7180 return json ("/locations.json" , parameter );
7281 }
7382
@@ -88,21 +97,33 @@ public JsonObject searchArchive(String clientID) throws SerpApiException {
8897 /***
8998 * Get account information using Account API
9099 *
91- * @param parameter HashMap including the api_key if not set in the default client parameter
100+ * @param parameter Map including the api_key if not set in the default client parameter
92101 * @return JsonObject account information
93102 * @throws SerpApiException wraps backend error message
94103 */
95- public JsonObject account (HashMap <String , String > parameter ) throws SerpApiException {
104+ public JsonObject account (Map <String , String > parameter ) throws SerpApiException {
96105 return json ("/account.json" , parameter );
97106 }
98107
108+
109+ /***
110+ * Get account information using Account API
111+ *
112+ * @param parameter Map including the api_key if not set in the default client parameter
113+ * @return JsonObject account information
114+ * @throws SerpApiException wraps backend error message
115+ */
116+ public JsonObject account () throws SerpApiException {
117+ return json ("/account.json" , this .parameter );
118+ }
119+
99120 /***
100121 * Convert HTTP content to JsonValue
101122 *
102123 * @param content raw JSON HTTP response
103124 * @return JsonObject created by gson parser
104125 */
105- private JsonObject json (String endpoint , HashMap <String , String > parameter ) throws SerpApiException {
126+ private JsonObject json (String endpoint , Map <String , String > parameter ) throws SerpApiException {
106127 String content = get (endpoint , "json" , parameter );
107128 JsonElement element = gson .fromJson (content , JsonElement .class );
108129 return element .getAsJsonObject ();
@@ -124,7 +145,7 @@ public SerpApiHttp getClient() {
124145 * @return format parameter hash map
125146 * @throws SerpApiException wraps backend error message
126147 */
127- public String get (String path , String output , HashMap <String , String > parameter ) throws SerpApiException {
148+ public String get (String path , String output , Map <String , String > parameter ) throws SerpApiException {
128149 // Initialize client if not done
129150 if (this .client == null ) {
130151 this .client = new SerpApiHttp (path );
@@ -133,7 +154,7 @@ public String get(String path, String output, HashMap<String, String> parameter)
133154 this .client .path = path ;
134155 }
135156
136- HashMap <String , String > query = new HashMap ();
157+ Map <String , String > query = new HashMap ();
137158 // Merge default parameter
138159 query .putAll (this .parameter );
139160
0 commit comments