Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejch committed Sep 29, 2020
1 parent ff4f44c commit 121859d
Showing 1 changed file with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package kentico.kontent.delivery.sample.dancinggoat.springboot;

import kentico.kontent.delivery.DeliveryClient;
import kentico.kontent.delivery.InlineContentItemsResolver;
import kentico.kontent.delivery.sample.dancinggoat.models.Tweet;
import org.springframework.boot.json.JsonParserFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@Configuration
public class KontentConfiguration {
Expand All @@ -11,36 +17,33 @@ public DeliveryClient deliveryClient() {
DeliveryClient client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3");
client.scanClasspathForMappings("kentico.kontent.delivery.sample.dancinggoat.models");

client.
client.registerInlineContentItemsResolver(new InlineContentItemsResolver<Tweet>() {
@Override
public String resolve(Tweet item) {
String theme = item.getTheme().get(0).getName().toLowerCase();
Boolean hideThread = item
.getDisplayOptions()
.stream()
.filter(o -> o.getCodename().equals("hide_thread"))
.findFirst()
.isPresent();
Boolean hideMedia = item
.getDisplayOptions()
.stream()
.filter(o -> o.getCodename().equals("hide_media"))
.findFirst()
.isPresent();

String options = String.format("&hide_thread=%b&hide_media=%b", hideThread, hideMedia);
String tweetLink = item.getTweetLink();
String url = String.format("https://publish.twitter.com/oembed?url=%s&theme=%s%s", tweetLink, theme, options);

// client.registerInlineContentItemsResolver(new InlineContentItemsResolver<Tweet>() {
// @Override
// public String resolve(Tweet item) {
// String theme = item.getTheme().get(0).getName().toLowerCase();
// Boolean hideThread = item
// .getDisplayOptions()
// .stream()
// .filter(o -> o.getCodename().equals("hide_thread"))
// .findFirst()
// .isPresent();
// Boolean hideMedia = item
// .getDisplayOptions()
// .stream()
// .filter(o -> o.getCodename().equals("hide_media"))
// .findFirst()
// .isPresent();
//
// String options = String.format("&hide_thread=%b&hide_media=%b", hideThread, hideMedia);
// String tweetLink = item.getTweetLink();
// String url = String.format("https://publish.twitter.com/oembed?url=%s&theme=%s%s", tweetLink, theme, options);
//
// RestTemplate restTemplate = new RestTemplate();
// String responseBody = restTemplate.getForObject(url, String.class);
// Map<String, Object> object = JsonParserFactory.getJsonParser().parseMap(responseBody);
// return (String) object.get("html");
// }
// });
RestTemplate restTemplate = new RestTemplate();
String responseBody = restTemplate.getForObject(url, String.class);
Map<String, Object> object = JsonParserFactory.getJsonParser().parseMap(responseBody);
return (String) object.get("html");
}
});
return client;
}
}

0 comments on commit 121859d

Please sign in to comment.