From 458619faea5a1e594b2f6a8a9b9e3f8fa892b906 Mon Sep 17 00:00:00 2001 From: Victor Benarbia Date: Sat, 29 Jan 2022 14:44:55 -0600 Subject: [PATCH] clean-up javadoc error fix gradle packaging group --- README.md | 18 ++++++++++++ build.gradle | 4 +-- demo/build.gradle | 6 ++-- .../java/serpapi/ParameterStringBuilder.java | 3 ++ src/main/java/serpapi/SerpApiHttpClient.java | 28 ++++++++++++++----- src/main/java/serpapi/SerpApiSearch.java | 26 +++++++++-------- src/main/java/serpapi/YahooSearch.java | 18 ++++++++++-- src/main/java/serpapi/YandexSearch.java | 18 ++++++++++-- 8 files changed, 93 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index f710e76..3d9346a 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,24 @@ Runtime: For development: - Gradle 6.7+ (https://gradle.org/install/) +## Maven / Gradle support + +Edit your build.gradle file +```java +repositories { + maven { url "https://jitpack.io" } +} + +dependencies { + implementation 'com.github.serpapi:google-search-results-java:2.0.2' +} +``` + +To list all the version available. +https://jitpack.io/api/builds/com.github.serpapi/google-search-results-java + +Note: jitpack.io enables to download maven package directly from github release. + ## Quick start To get started with this project in Java. diff --git a/build.gradle b/build.gradle index b65bbef..78b13f3 100644 --- a/build.gradle +++ b/build.gradle @@ -9,8 +9,8 @@ plugins { // Package default archivesBaseName = 'google-search-results-java' -version = '2.0.2' -group = 'serpapi' +version = '2.0.3' +group = 'com.github.serpapi' // java version sourceCompatibility = 1.8 diff --git a/demo/build.gradle b/demo/build.gradle index eb08d53..7a956ef 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -18,12 +18,14 @@ repositories { // Use jcenter for resolving your dependencies. // You can declare any Maven/Ivy/file repository here. jcenter() + + maven { url "https://jitpack.io" } } dependencies { - implementation fileTree(dir: "./libs", includes: ['*.jar']) - + // implementation fileTree(dir: "./libs", includes: ['*.jar']) implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5' + implementation 'com.github.serpapi:google-search-results-java:2.0.3' } // Define the main class for the application diff --git a/src/main/java/serpapi/ParameterStringBuilder.java b/src/main/java/serpapi/ParameterStringBuilder.java index 59b31e1..231563b 100644 --- a/src/main/java/serpapi/ParameterStringBuilder.java +++ b/src/main/java/serpapi/ParameterStringBuilder.java @@ -11,7 +11,10 @@ public class ParameterStringBuilder { /*** + * getParamsString * @param params search parameters + * @return concatenated parameters + * @throws UnsupportedEncodingException when none UTF-8 character is part of the parameter */ public static String getParamsString(Map params) throws UnsupportedEncodingException diff --git a/src/main/java/serpapi/SerpApiHttpClient.java b/src/main/java/serpapi/SerpApiHttpClient.java index 09ef0f8..9adf786 100644 --- a/src/main/java/serpapi/SerpApiHttpClient.java +++ b/src/main/java/serpapi/SerpApiHttpClient.java @@ -21,21 +21,29 @@ public class SerpApiHttpClient { private int httpConnectionTimeout; private int httpReadTimeout; - // current API version - public static String VERSION = "2.0.2"; + /** + * current API version + */ + public static String VERSION = "2.0.3"; - // backend service + /** + * backend service + */ public static String BACKEND = "https://serpapi.com"; - // initialize gson + /** + * initialize gson + */ private static Gson gson = new Gson(); - // current backend HTTP path + /** + * current backend HTTP path + */ public String path; /*** * Constructor - * @param path + * @param path HTTP url path */ public SerpApiHttpClient(String path) { this.path = path; @@ -47,7 +55,7 @@ public SerpApiHttpClient(String path) { * @param path url end point * @param parameter search parameter map like: { "q": "coffee", "location": "Austin, TX"} * @return httpUrlConnection - * @throws SerpApiSearchException + * @throws SerpApiSearchException wraps error message */ protected HttpURLConnection buildConnection(String path, Map parameter) throws SerpApiSearchException { HttpURLConnection con; @@ -121,6 +129,7 @@ public boolean verify(String hostname, SSLSession session) { * * @param parameter user search parameters * @return http response body + * @throws SerpApiSearchException wraps error message */ public String getResults(Map parameter) throws SerpApiSearchException { HttpURLConnection con = buildConnection(this.path, parameter); @@ -166,6 +175,11 @@ public String getResults(Map parameter) throws SerpApiSearchExce return content.toString(); } + /** + * trigger a exception on error + * @param content raw JSON response from serpapi.com + * @throws SerpApiSearchException wraps error message + */ protected void triggerSerpApiClientException(String content) throws SerpApiSearchException { String errorMessage; try { diff --git a/src/main/java/serpapi/SerpApiSearch.java b/src/main/java/serpapi/SerpApiSearch.java index 490ea41..660f307 100644 --- a/src/main/java/serpapi/SerpApiSearch.java +++ b/src/main/java/serpapi/SerpApiSearch.java @@ -22,10 +22,14 @@ public class SerpApiSearch extends Exception { */ public static String api_key_default; - // instance level key + /** + * user secret API key + */ protected String api_key; - // current search engine + /** + * Current search engine + */ protected String engine; /** @@ -91,7 +95,7 @@ public SerpApiSearch(String api_key, String engine) { * @param path backend HTTP path * @param output type of output format (json, html, json_with_images) * @return format parameter hash map - * @throws SerpApiSearchException + * @throws SerpApiSearchException wraps backend error message */ public Map buildQuery(String path, String output) throws SerpApiSearchException { // Initialize search if not done @@ -134,8 +138,8 @@ public static String getApiKey() { /*** * Get HTML output * - * @return String - * @throws SerpApiSearchException + * @return raw HTML response from the search engine for custom parsing + * @throws SerpApiSearchException wraps backend error message */ public String getHtml() throws SerpApiSearchException { Map query = buildQuery("/search", "html"); @@ -146,7 +150,7 @@ public String getHtml() throws SerpApiSearchException { * Get JSON output * * @return JsonObject parent node - * @throws SerpApiSearchException + * @throws SerpApiSearchException wraps backend error message */ public JsonObject getJson() throws SerpApiSearchException { Map query = buildQuery("/search", "json"); @@ -156,8 +160,8 @@ public JsonObject getJson() throws SerpApiSearchException { /*** * Convert HTTP content to JsonValue * - * @param content - * @return JsonObject + * @param content raw JSON HTTP response + * @return JsonObject created by gson parser */ public JsonObject asJson(String content) { JsonElement element = gson.fromJson(content, JsonElement.class); @@ -177,7 +181,7 @@ public SerpApiHttpClient getClient() { * @param q query * @param limit number of location * @return JsonObject location using Location API - * @throws SerpApiSearchException + * @throws SerpApiSearchException wraps backend error message */ public JsonArray getLocation(String q, Integer limit) throws SerpApiSearchException { Map query = buildQuery("/locations.json", "json"); @@ -194,7 +198,7 @@ public JsonArray getLocation(String q, Integer limit) throws SerpApiSearchExcept * * @param searchID archived search result = search_metadata.id * @return JsonObject search result - * @throws SerpApiSearchException + * @throws SerpApiSearchException wraps backend error message */ public JsonObject getSearchArchive(String searchID) throws SerpApiSearchException { Map query = buildQuery("/searches/" + searchID + ".json", "json"); @@ -207,7 +211,7 @@ public JsonObject getSearchArchive(String searchID) throws SerpApiSearchExceptio * Get account information using Account API * * @return JsonObject account information - * @throws SerpApiSearchException + * @throws SerpApiSearchException wraps backend error message */ public JsonObject getAccount() throws SerpApiSearchException { Map query = buildQuery("/account", "json"); diff --git a/src/main/java/serpapi/YahooSearch.java b/src/main/java/serpapi/YahooSearch.java index 98cdd08..6f3c68e 100644 --- a/src/main/java/serpapi/YahooSearch.java +++ b/src/main/java/serpapi/YahooSearch.java @@ -20,20 +20,32 @@ */ public class YahooSearch extends SerpApiSearch { + /** + * Constructor + * @param parameter search parameter + * @param apiKey secret API key + */ public YahooSearch(Map parameter, String apiKey) { super(parameter, apiKey, "yahoo"); } + /** + * Constructor + */ public YahooSearch() { super("yahoo"); } + /** + * Constructor + * @param parameter search parameter + */ public YahooSearch(Map parameter) { super(parameter, "yahoo"); } @Override - public JsonArray getLocation(String q, Integer limit) throws SerpApiSearchException { - throw new SerpApiSearchException("location is not supported for Baidu"); - } + public JsonArray getLocation(String q, Integer limit) throws SerpApiSearchException { + throw new SerpApiSearchException("location is not supported for Baidu"); + } } \ No newline at end of file diff --git a/src/main/java/serpapi/YandexSearch.java b/src/main/java/serpapi/YandexSearch.java index 2dbd3f6..94e2d05 100644 --- a/src/main/java/serpapi/YandexSearch.java +++ b/src/main/java/serpapi/YandexSearch.java @@ -20,20 +20,32 @@ */ public class YandexSearch extends SerpApiSearch { + /** + * Constructor + * @param parameter search parameter + * @param apiKey secret API key + */ public YandexSearch(Map parameter, String apiKey) { super(parameter, apiKey, "yandex"); } + /** + * Constructor + */ public YandexSearch() { super("yandex"); } + /** + * Constructor + * @param parameter search parameter + */ public YandexSearch(Map parameter) { super(parameter, "yandex"); } @Override - public JsonArray getLocation(String q, Integer limit) throws SerpApiSearchException { - throw new SerpApiSearchException("location is not supported for Baidu"); - } + public JsonArray getLocation(String q, Integer limit) throws SerpApiSearchException { + throw new SerpApiSearchException("location is not supported for Baidu"); + } } \ No newline at end of file