Skip to content

Commit 458619f

Browse files
author
Victor Benarbia
committed
clean-up javadoc error
fix gradle packaging group
1 parent acfb30a commit 458619f

8 files changed

+93
-28
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ Runtime:
2424
For development:
2525
- Gradle 6.7+ (https://gradle.org/install/)
2626

27+
## Maven / Gradle support
28+
29+
Edit your build.gradle file
30+
```java
31+
repositories {
32+
maven { url "https://jitpack.io" }
33+
}
34+
35+
dependencies {
36+
implementation 'com.github.serpapi:google-search-results-java:2.0.2'
37+
}
38+
```
39+
40+
To list all the version available.
41+
https://jitpack.io/api/builds/com.github.serpapi/google-search-results-java
42+
43+
Note: jitpack.io enables to download maven package directly from github release.
44+
2745
## Quick start
2846

2947
To get started with this project in Java.

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ plugins {
99

1010
// Package default
1111
archivesBaseName = 'google-search-results-java'
12-
version = '2.0.2'
13-
group = 'serpapi'
12+
version = '2.0.3'
13+
group = 'com.github.serpapi'
1414

1515
// java version
1616
sourceCompatibility = 1.8

demo/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ repositories {
1818
// Use jcenter for resolving your dependencies.
1919
// You can declare any Maven/Ivy/file repository here.
2020
jcenter()
21+
22+
maven { url "https://jitpack.io" }
2123
}
2224

2325
dependencies {
24-
implementation fileTree(dir: "./libs", includes: ['*.jar'])
25-
26+
// implementation fileTree(dir: "./libs", includes: ['*.jar'])
2627
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
28+
implementation 'com.github.serpapi:google-search-results-java:2.0.3'
2729
}
2830

2931
// Define the main class for the application

src/main/java/serpapi/ParameterStringBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
public class ParameterStringBuilder
1212
{
1313
/***
14+
* getParamsString
1415
* @param params search parameters
16+
* @return concatenated parameters
17+
* @throws UnsupportedEncodingException when none UTF-8 character is part of the parameter
1518
*/
1619
public static String getParamsString(Map<String, String> params)
1720
throws UnsupportedEncodingException

src/main/java/serpapi/SerpApiHttpClient.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,29 @@ public class SerpApiHttpClient {
2121
private int httpConnectionTimeout;
2222
private int httpReadTimeout;
2323

24-
// current API version
25-
public static String VERSION = "2.0.2";
24+
/**
25+
* current API version
26+
*/
27+
public static String VERSION = "2.0.3";
2628

27-
// backend service
29+
/**
30+
* backend service
31+
*/
2832
public static String BACKEND = "https://serpapi.com";
2933

30-
// initialize gson
34+
/**
35+
* initialize gson
36+
*/
3137
private static Gson gson = new Gson();
3238

33-
// current backend HTTP path
39+
/**
40+
* current backend HTTP path
41+
*/
3442
public String path;
3543

3644
/***
3745
* Constructor
38-
* @param path
46+
* @param path HTTP url path
3947
*/
4048
public SerpApiHttpClient(String path) {
4149
this.path = path;
@@ -47,7 +55,7 @@ public SerpApiHttpClient(String path) {
4755
* @param path url end point
4856
* @param parameter search parameter map like: { "q": "coffee", "location": "Austin, TX"}
4957
* @return httpUrlConnection
50-
* @throws SerpApiSearchException
58+
* @throws SerpApiSearchException wraps error message
5159
*/
5260
protected HttpURLConnection buildConnection(String path, Map<String, String> parameter) throws SerpApiSearchException {
5361
HttpURLConnection con;
@@ -121,6 +129,7 @@ public boolean verify(String hostname, SSLSession session) {
121129
*
122130
* @param parameter user search parameters
123131
* @return http response body
132+
* @throws SerpApiSearchException wraps error message
124133
*/
125134
public String getResults(Map<String, String> parameter) throws SerpApiSearchException {
126135
HttpURLConnection con = buildConnection(this.path, parameter);
@@ -166,6 +175,11 @@ public String getResults(Map<String, String> parameter) throws SerpApiSearchExce
166175
return content.toString();
167176
}
168177

178+
/**
179+
* trigger a exception on error
180+
* @param content raw JSON response from serpapi.com
181+
* @throws SerpApiSearchException wraps error message
182+
*/
169183
protected void triggerSerpApiClientException(String content) throws SerpApiSearchException {
170184
String errorMessage;
171185
try {

src/main/java/serpapi/SerpApiSearch.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ public class SerpApiSearch extends Exception {
2222
*/
2323
public static String api_key_default;
2424

25-
// instance level key
25+
/**
26+
* user secret API key
27+
*/
2628
protected String api_key;
2729

28-
// current search engine
30+
/**
31+
* Current search engine
32+
*/
2933
protected String engine;
3034

3135
/**
@@ -91,7 +95,7 @@ public SerpApiSearch(String api_key, String engine) {
9195
* @param path backend HTTP path
9296
* @param output type of output format (json, html, json_with_images)
9397
* @return format parameter hash map
94-
* @throws SerpApiSearchException
98+
* @throws SerpApiSearchException wraps backend error message
9599
*/
96100
public Map<String, String> buildQuery(String path, String output) throws SerpApiSearchException {
97101
// Initialize search if not done
@@ -134,8 +138,8 @@ public static String getApiKey() {
134138
/***
135139
* Get HTML output
136140
*
137-
* @return String
138-
* @throws SerpApiSearchException
141+
* @return raw HTML response from the search engine for custom parsing
142+
* @throws SerpApiSearchException wraps backend error message
139143
*/
140144
public String getHtml() throws SerpApiSearchException {
141145
Map<String, String> query = buildQuery("/search", "html");
@@ -146,7 +150,7 @@ public String getHtml() throws SerpApiSearchException {
146150
* Get JSON output
147151
*
148152
* @return JsonObject parent node
149-
* @throws SerpApiSearchException
153+
* @throws SerpApiSearchException wraps backend error message
150154
*/
151155
public JsonObject getJson() throws SerpApiSearchException {
152156
Map<String, String> query = buildQuery("/search", "json");
@@ -156,8 +160,8 @@ public JsonObject getJson() throws SerpApiSearchException {
156160
/***
157161
* Convert HTTP content to JsonValue
158162
*
159-
* @param content
160-
* @return JsonObject
163+
* @param content raw JSON HTTP response
164+
* @return JsonObject created by gson parser
161165
*/
162166
public JsonObject asJson(String content) {
163167
JsonElement element = gson.fromJson(content, JsonElement.class);
@@ -177,7 +181,7 @@ public SerpApiHttpClient getClient() {
177181
* @param q query
178182
* @param limit number of location
179183
* @return JsonObject location using Location API
180-
* @throws SerpApiSearchException
184+
* @throws SerpApiSearchException wraps backend error message
181185
*/
182186
public JsonArray getLocation(String q, Integer limit) throws SerpApiSearchException {
183187
Map<String, String> query = buildQuery("/locations.json", "json");
@@ -194,7 +198,7 @@ public JsonArray getLocation(String q, Integer limit) throws SerpApiSearchExcept
194198
*
195199
* @param searchID archived search result = search_metadata.id
196200
* @return JsonObject search result
197-
* @throws SerpApiSearchException
201+
* @throws SerpApiSearchException wraps backend error message
198202
*/
199203
public JsonObject getSearchArchive(String searchID) throws SerpApiSearchException {
200204
Map<String, String> query = buildQuery("/searches/" + searchID + ".json", "json");
@@ -207,7 +211,7 @@ public JsonObject getSearchArchive(String searchID) throws SerpApiSearchExceptio
207211
* Get account information using Account API
208212
*
209213
* @return JsonObject account information
210-
* @throws SerpApiSearchException
214+
* @throws SerpApiSearchException wraps backend error message
211215
*/
212216
public JsonObject getAccount() throws SerpApiSearchException {
213217
Map<String, String> query = buildQuery("/account", "json");

src/main/java/serpapi/YahooSearch.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,32 @@
2020
*/
2121
public class YahooSearch extends SerpApiSearch {
2222

23+
/**
24+
* Constructor
25+
* @param parameter search parameter
26+
* @param apiKey secret API key
27+
*/
2328
public YahooSearch(Map<String, String> parameter, String apiKey) {
2429
super(parameter, apiKey, "yahoo");
2530
}
2631

32+
/**
33+
* Constructor
34+
*/
2735
public YahooSearch() {
2836
super("yahoo");
2937
}
3038

39+
/**
40+
* Constructor
41+
* @param parameter search parameter
42+
*/
3143
public YahooSearch(Map<String, String> parameter) {
3244
super(parameter, "yahoo");
3345
}
3446

3547
@Override
36-
public JsonArray getLocation(String q, Integer limit) throws SerpApiSearchException {
37-
throw new SerpApiSearchException("location is not supported for Baidu");
38-
}
48+
public JsonArray getLocation(String q, Integer limit) throws SerpApiSearchException {
49+
throw new SerpApiSearchException("location is not supported for Baidu");
50+
}
3951
}

src/main/java/serpapi/YandexSearch.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,32 @@
2020
*/
2121
public class YandexSearch extends SerpApiSearch {
2222

23+
/**
24+
* Constructor
25+
* @param parameter search parameter
26+
* @param apiKey secret API key
27+
*/
2328
public YandexSearch(Map<String, String> parameter, String apiKey) {
2429
super(parameter, apiKey, "yandex");
2530
}
2631

32+
/**
33+
* Constructor
34+
*/
2735
public YandexSearch() {
2836
super("yandex");
2937
}
3038

39+
/**
40+
* Constructor
41+
* @param parameter search parameter
42+
*/
3143
public YandexSearch(Map<String, String> parameter) {
3244
super(parameter, "yandex");
3345
}
3446

3547
@Override
36-
public JsonArray getLocation(String q, Integer limit) throws SerpApiSearchException {
37-
throw new SerpApiSearchException("location is not supported for Baidu");
38-
}
48+
public JsonArray getLocation(String q, Integer limit) throws SerpApiSearchException {
49+
throw new SerpApiSearchException("location is not supported for Baidu");
50+
}
3951
}

0 commit comments

Comments
 (0)