Removed comments from author, reformat
This commit is contained in:
parent
d936889921
commit
3db7b36662
@ -1,25 +1,16 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.googlehttpclientguide;
|
||||
|
||||
import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler;
|
||||
import com.google.api.client.http.HttpRequest;
|
||||
import com.google.api.client.http.HttpRequestFactory;
|
||||
import com.google.api.client.http.HttpRequestInitializer;
|
||||
import com.google.api.client.http.HttpResponseException;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||
import com.google.api.client.json.JsonFactory;
|
||||
import com.google.api.client.json.JsonObjectParser;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||
import com.google.api.client.util.ExponentialBackOff;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Hugo
|
||||
*/
|
||||
public class DailyMotionExample {
|
||||
|
||||
static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
|
||||
@ -29,15 +20,20 @@ public class DailyMotionExample {
|
||||
private static void run() throws Exception {
|
||||
HttpRequestFactory requestFactory
|
||||
= HTTP_TRANSPORT.createRequestFactory(
|
||||
new HttpRequestInitializer() {
|
||||
|
||||
public void initialize(HttpRequest request) {
|
||||
(HttpRequest request) -> {
|
||||
request.setParser(new JsonObjectParser(JSON_FACTORY));
|
||||
}
|
||||
});
|
||||
DailyMotionUrl url = new DailyMotionUrl("https://api.dailymotion.com/videos/");
|
||||
url.fields = "id,tags,title,url";
|
||||
HttpRequest request = requestFactory.buildGetRequest(url);
|
||||
ExponentialBackOff backoff = new ExponentialBackOff.Builder()
|
||||
.setInitialIntervalMillis(500)
|
||||
.setMaxElapsedTimeMillis(900000)
|
||||
.setMaxIntervalMillis(6000)
|
||||
.setMultiplier(1.5)
|
||||
.setRandomizationFactor(0.5)
|
||||
.build();
|
||||
request.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(backoff));
|
||||
VideoFeed videoFeed = request.execute().parseAs(VideoFeed.class);
|
||||
if (videoFeed.list.isEmpty()) {
|
||||
System.out.println("No videos found.");
|
||||
|
@ -1,22 +1,15 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.googlehttpclientguide;
|
||||
|
||||
import com.google.api.client.http.GenericUrl;
|
||||
import com.google.api.client.util.Key;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Hugo
|
||||
*/
|
||||
|
||||
public class DailyMotionUrl extends GenericUrl {
|
||||
|
||||
public DailyMotionUrl(String encodedUrl) {
|
||||
super(encodedUrl);
|
||||
}
|
||||
|
||||
@Key public String fields;
|
||||
@Key
|
||||
public String fields;
|
||||
}
|
||||
|
@ -1,23 +1,20 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.googlehttpclientguide;
|
||||
|
||||
import com.google.api.client.json.GenericJson;
|
||||
import com.google.api.client.util.Key;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Hugo
|
||||
*/
|
||||
public class Video {
|
||||
@Key public String id;
|
||||
public class Video extends GenericJson {
|
||||
|
||||
@Key public List<String> tags;
|
||||
@Key
|
||||
public String id;
|
||||
|
||||
@Key public String title;
|
||||
@Key
|
||||
public List<String> tags;
|
||||
|
||||
@Key public String url;
|
||||
@Key
|
||||
public String title;
|
||||
|
||||
@Key
|
||||
public String url;
|
||||
}
|
@ -1,19 +1,12 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.googlehttpclientguide;
|
||||
|
||||
import com.google.api.client.util.Key;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Hugo
|
||||
*/
|
||||
public class VideoFeed {
|
||||
@Key public List<Video> list;
|
||||
|
||||
@Key
|
||||
public List<Video> list;
|
||||
|
||||
@Key("has_more")
|
||||
public boolean hasMore;
|
||||
|
Loading…
x
Reference in New Issue
Block a user