Search in sources :

Example 1 with Post

use of facebook4j.Post in project camel by apache.

the class FacebookComponentPageIdProducerTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() {
            from("timer:period=20000").setHeader("CamelFacebook.reading.limit", constant("10")).process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    if (lastTimestamp > 0) {
                        exchange.getIn().setHeader("CamelFacebook.reading.since", lastTimestamp);
                    }
                }
            }).to("facebook://getPosts?" + getOauthParams() + "&userId=" + APACHE_FOUNDATION_PAGE_ID + "&reading.limit=5").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    ResponseList<Post> body = (ResponseList<Post>) exchange.getIn().getBody();
                    log.info("Number of posts received: {}", body.size());
                    for (Post post : body) {
                        log.debug(post.toString());
                    }
                    if (!body.isEmpty()) {
                        lastTimestamp = body.get(0).getUpdatedTime().getTime();
                    }
                }
            }).to("mock:page");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Post(facebook4j.Post) ResponseList(facebook4j.ResponseList)

Aggregations

Post (facebook4j.Post)1 ResponseList (facebook4j.ResponseList)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1