Skip to content

Commit effde7e

Browse files
committed
Add setUserAgent and setResponseTimeoutMs methods
1 parent 83af1e1 commit effde7e

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ You can install this library for JVM-based languages, including Java, Kotlin, Cl
5454
Add this dependency to your project's build file:
5555

5656
```groovy
57-
implementation "com.listennotes:podcast-api:1.0.5"
57+
implementation "com.listennotes:podcast-api:1.0.6"
5858
```
5959

6060
### Maven users
@@ -65,7 +65,7 @@ Add this dependency to your project's POM:
6565
<dependency>
6666
<groupId>com.listennotes</groupId>
6767
<artifactId>podcast-api</artifactId>
68-
<version>1.0.5</version>
68+
<version>1.0.6</version>
6969
</dependency>
7070
```
7171

@@ -89,6 +89,12 @@ public class PodcastApiExample {
8989
String apiKey = System.getenv("LISTEN_API_KEY");
9090
Client objClient = new Client(apiKey);
9191

92+
// Set timeout for 15 seconds
93+
objClient.setResponseTimeoutMs(15000);
94+
95+
// Customize your user agent
96+
objClient.setUserAgent("My Great Podcast App");
97+
9298
// All parameters can be found at
9399
// https://www.listennotes.com/api/docs/
94100
HashMap<String, String> parameters = new HashMap<>();

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GROUP_ID=com.listennotes
2-
VERSION_NAME=1.0.5
2+
VERSION_NAME=1.0.6
33

44
POM_URL=https://github.com/ListenNotes/podcast-api-java
55
POM_SCM_URL[email protected]:ListenNotes/podcast-api-java.git

src/main/java/com/listennotes/podcast_api/Client.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,25 @@ public final class Client {
2727
public static final String USER_AGENT = "podcast-api-java";
2828

2929
protected String apiKey = "";
30+
protected Integer timeoutMs = 30000; // 30 seconds
31+
protected String userAgent = USER_AGENT;
3032
protected HttpURLConnection con;
3133
protected Map<String, String> requestParams;
3234

35+
public Client() {
36+
// No api key. Use api mock server.
37+
}
38+
3339
public Client(String apiKey) {
3440
this.apiKey = apiKey;
3541
}
3642

37-
public Client() {
38-
// No api key. Use api mock server.
43+
public void setResponseTimeoutMs(Integer timeoutMs) {
44+
this.timeoutMs = timeoutMs;
45+
}
46+
47+
public void setUserAgent(String userAgent) {
48+
this.userAgent = userAgent;
3949
}
4050

4151
public ApiResponse submitPodcast(Map<String, String> mapParams) throws ListenApiException {
@@ -155,12 +165,12 @@ public HttpURLConnection getConnection(String strUrl) throws ListenApiException
155165
}
156166

157167
con.setDoOutput(true);
158-
con.setRequestProperty("User-Agent", USER_AGENT);
168+
con.setRequestProperty("User-Agent", this.userAgent);
159169
if (this.apiKey != null && this.apiKey.length() > 0) {
160170
con.setRequestProperty("X-ListenAPI-Key", this.apiKey);
161171
}
162172
con.setConnectTimeout(5000);
163-
con.setReadTimeout(5000);
173+
con.setReadTimeout(this.timeoutMs);
164174
con.setInstanceFollowRedirects(false);
165175
return con;
166176
}

src/main/java/com/listennotes/podcast_api/Sample.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public static void main(String[] args) {
88
try {
99
String apiKey = System.getenv("LISTEN_API_KEY");
1010
Client objClient = new Client(apiKey);
11+
objClient.setResponseTimeoutMs(15000);
12+
objClient.setUserAgent("My Great Podcast App");
1113

1214
HashMap<String, String> parameters;
1315
ApiResponse response;

0 commit comments

Comments
 (0)