-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(java): add
requestOptions
(#487)
- Loading branch information
Showing
5 changed files
with
205 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...arch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/RequestOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.algolia.utils; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Request options are used to pass extra parameters, headers, timeout to the request. Parameters | ||
* set in the request option will override default parameter. | ||
*/ | ||
public class RequestOptions { | ||
|
||
private final Map<String, String> headers = new HashMap<String, String>(); | ||
private final Map<String, String> queryParams = new HashMap<String, String>(); | ||
private Integer timeout = null; | ||
|
||
public RequestOptions addExtraHeader( | ||
@Nonnull String key, | ||
@Nonnull String value | ||
) { | ||
headers.put(key, value); | ||
return this; | ||
} | ||
|
||
public RequestOptions addExtraQueryParameters( | ||
@Nonnull String key, | ||
@Nonnull String value | ||
) { | ||
queryParams.put(key, value); | ||
return this; | ||
} | ||
|
||
public Map<String, String> getExtraHeaders() { | ||
return headers; | ||
} | ||
|
||
public Map<String, String> getExtraQueryParams() { | ||
return queryParams; | ||
} | ||
|
||
public Integer getTimeout() { | ||
return timeout; | ||
} | ||
|
||
public RequestOptions setTimeout(Integer timeout) { | ||
this.timeout = timeout; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ( | ||
"RequestOptions{" + | ||
"headers=" + | ||
headers + | ||
", queryParams=" + | ||
queryParams + | ||
'\'' + | ||
'}' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.