Skip to content

Commit 3db7b36

Browse files
author
hgomez
committed
Removed comments from author, reformat
1 parent d936889 commit 3db7b36

4 files changed

Lines changed: 36 additions & 57 deletions

File tree

‎libraries/src/main/java/com/baeldung/googlehttpclientguide/DailyMotionExample.java‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1-
/*
2-
* To change this license header, choose License Headers in Project Properties.
3-
* To change this template file, choose Tools | Templates
4-
* and open the template in the editor.
5-
*/
61
package com.baeldung.googlehttpclientguide;
72

3+
import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler;
84
import com.google.api.client.http.HttpRequest;
95
import com.google.api.client.http.HttpRequestFactory;
10-
import com.google.api.client.http.HttpRequestInitializer;
116
import com.google.api.client.http.HttpResponseException;
127
import com.google.api.client.http.HttpTransport;
138
import com.google.api.client.http.javanet.NetHttpTransport;
149
import com.google.api.client.json.JsonFactory;
1510
import com.google.api.client.json.JsonObjectParser;
16-
import com.google.api.client.json.gson.GsonFactory;
1711
import com.google.api.client.json.jackson2.JacksonFactory;
12+
import com.google.api.client.util.ExponentialBackOff;
1813

19-
/**
20-
*
21-
* @author Hugo
22-
*/
2314
public class DailyMotionExample {
2415

2516
static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
@@ -29,15 +20,20 @@ public class DailyMotionExample {
2920
private static void run() throws Exception {
3021
HttpRequestFactory requestFactory
3122
= HTTP_TRANSPORT.createRequestFactory(
32-
new HttpRequestInitializer() {
33-
34-
public void initialize(HttpRequest request) {
35-
request.setParser(new JsonObjectParser(JSON_FACTORY));
36-
}
37-
});
23+
(HttpRequest request) -> {
24+
request.setParser(new JsonObjectParser(JSON_FACTORY));
25+
});
3826
DailyMotionUrl url = new DailyMotionUrl("https://api.dailymotion.com/videos/");
3927
url.fields = "id,tags,title,url";
4028
HttpRequest request = requestFactory.buildGetRequest(url);
29+
ExponentialBackOff backoff = new ExponentialBackOff.Builder()
30+
.setInitialIntervalMillis(500)
31+
.setMaxElapsedTimeMillis(900000)
32+
.setMaxIntervalMillis(6000)
33+
.setMultiplier(1.5)
34+
.setRandomizationFactor(0.5)
35+
.build();
36+
request.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(backoff));
4137
VideoFeed videoFeed = request.execute().parseAs(VideoFeed.class);
4238
if (videoFeed.list.isEmpty()) {
4339
System.out.println("No videos found.");
Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
/*
2-
* To change this license header, choose License Headers in Project Properties.
3-
* To change this template file, choose Tools | Templates
4-
* and open the template in the editor.
5-
*/
61
package com.baeldung.googlehttpclientguide;
72

83
import com.google.api.client.http.GenericUrl;
94
import com.google.api.client.util.Key;
105

11-
/**
12-
*
13-
* @author Hugo
14-
*/
15-
public class DailyMotionUrl extends GenericUrl {
6+
7+
public class DailyMotionUrl extends GenericUrl {
168

179
public DailyMotionUrl(String encodedUrl) {
18-
super(encodedUrl);
10+
super(encodedUrl);
1911
}
2012

21-
@Key public String fields;
22-
}
13+
@Key
14+
public String fields;
15+
}
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
/*
2-
* To change this license header, choose License Headers in Project Properties.
3-
* To change this template file, choose Tools | Templates
4-
* and open the template in the editor.
5-
*/
61
package com.baeldung.googlehttpclientguide;
72

3+
import com.google.api.client.json.GenericJson;
84
import com.google.api.client.util.Key;
95
import java.util.List;
106

11-
/**
12-
*
13-
* @author Hugo
14-
*/
15-
public class Video {
16-
@Key public String id;
7+
public class Video extends GenericJson {
178

18-
@Key public List<String> tags;
9+
@Key
10+
public String id;
1911

20-
@Key public String title;
12+
@Key
13+
public List<String> tags;
2114

22-
@Key public String url;
23-
}
15+
@Key
16+
public String title;
17+
18+
@Key
19+
public String url;
20+
}
Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
/*
2-
* To change this license header, choose License Headers in Project Properties.
3-
* To change this template file, choose Tools | Templates
4-
* and open the template in the editor.
5-
*/
61
package com.baeldung.googlehttpclientguide;
72

83
import com.google.api.client.util.Key;
94
import java.util.List;
105

11-
/**
12-
*
13-
* @author Hugo
14-
*/
15-
public class VideoFeed {
16-
@Key public List<Video> list;
6+
public class VideoFeed {
7+
8+
@Key
9+
public List<Video> list;
1710

1811
@Key("has_more")
1912
public boolean hasMore;
20-
}
13+
}

0 commit comments

Comments
 (0)