Skip to content

Commit

Permalink
clean-up javadoc error
Browse files Browse the repository at this point in the history
fix gradle packaging group
  • Loading branch information
Victor Benarbia committed Jan 29, 2022
1 parent acfb30a commit 458619f
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 28 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/serpapi/ParameterStringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> params)
throws UnsupportedEncodingException
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/serpapi/SerpApiHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String> parameter) throws SerpApiSearchException {
HttpURLConnection con;
Expand Down Expand Up @@ -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<String, String> parameter) throws SerpApiSearchException {
HttpURLConnection con = buildConnection(this.path, parameter);
Expand Down Expand Up @@ -166,6 +175,11 @@ public String getResults(Map<String, String> 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 {
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/serpapi/SerpApiSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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<String, String> buildQuery(String path, String output) throws SerpApiSearchException {
// Initialize search if not done
Expand Down Expand Up @@ -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<String, String> query = buildQuery("/search", "html");
Expand All @@ -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<String, String> query = buildQuery("/search", "json");
Expand All @@ -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);
Expand All @@ -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<String, String> query = buildQuery("/locations.json", "json");
Expand All @@ -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<String, String> query = buildQuery("/searches/" + searchID + ".json", "json");
Expand All @@ -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<String, String> query = buildQuery("/account", "json");
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/serpapi/YahooSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,32 @@
*/
public class YahooSearch extends SerpApiSearch {

/**
* Constructor
* @param parameter search parameter
* @param apiKey secret API key
*/
public YahooSearch(Map<String, String> parameter, String apiKey) {
super(parameter, apiKey, "yahoo");
}

/**
* Constructor
*/
public YahooSearch() {
super("yahoo");
}

/**
* Constructor
* @param parameter search parameter
*/
public YahooSearch(Map<String, String> 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");
}
}
18 changes: 15 additions & 3 deletions src/main/java/serpapi/YandexSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,32 @@
*/
public class YandexSearch extends SerpApiSearch {

/**
* Constructor
* @param parameter search parameter
* @param apiKey secret API key
*/
public YandexSearch(Map<String, String> parameter, String apiKey) {
super(parameter, apiKey, "yandex");
}

/**
* Constructor
*/
public YandexSearch() {
super("yandex");
}

/**
* Constructor
* @param parameter search parameter
*/
public YandexSearch(Map<String, String> 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");
}
}

0 comments on commit 458619f

Please sign in to comment.