Repository: camel
Updated Branches:
  refs/heads/master 5e10ebaf6 -> 93f76929e


CAMEL-8817: Expose additional geolocation search api.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/04971dcc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/04971dcc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/04971dcc

Branch: refs/heads/master
Commit: 04971dccfecb168285a43be083cc79e34ce9b909
Parents: 5e10eba
Author: Jason Taylor <jason.tay...@baesystemsdetica.com>
Authored: Fri May 29 11:17:13 2015 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sat May 30 09:16:06 2015 +0200

----------------------------------------------------------------------
 .../component/twitter/TwitterConfiguration.java | 57 ++++++++++++++++++++
 .../twitter/consumer/search/SearchConsumer.java | 37 ++++++++++---
 2 files changed, 86 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/04971dcc/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
----------------------------------------------------------------------
diff --git 
a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
 
b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
index 413c47f..9a47954 100644
--- 
a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
+++ 
b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
@@ -69,6 +69,15 @@ public class TwitterConfiguration {
     private String httpProxyPassword;
     @UriParam
     private Integer httpProxyPort;
+    @UriParam
+    private Double latitude;
+    @UriParam
+    private Double longitude;
+    @UriParam
+    private Double radius;
+    @UriParam(defaultValue = "km")
+    private String distanceMetric;
+    
     
     /**
      * Singleton, on demand instances of Twitter4J's Twitter & TwitterStream.
@@ -352,4 +361,52 @@ public class TwitterConfiguration {
     public int getHttpProxyPort() {
         return httpProxyPort;
     }
+
+    public Double getLongitude() {
+       return longitude;
+    }
+
+    /**
+     * Used by the non-stream geography search.
+     * @param longitude
+     */
+    public void setLongitude(Double longitude) {
+       this.longitude = longitude;
+    }
+
+    public Double getRadius() {
+       return radius;
+    }
+
+    /**
+     * Used by the non-stream geography search.
+     * @param radius
+     */
+    public void setRadius(Double radius) {
+       this.radius = radius;
+    }
+
+    public String getDistanceMetric() {
+       return distanceMetric;
+    }
+
+    /**
+     * Used by the non-stream geography search, defaults to km.
+     * @param distanceMetric
+     */
+    public void setDistanceMetric(String distanceMetric) {
+       this.distanceMetric = distanceMetric;
+    }
+
+    public Double getLatitude() {
+       return latitude;
+    }
+
+    /**
+     * Used by the non-stream geography search.
+     * @param latitude
+     */
+    public void setLatitude(Double latitude) {
+       this.latitude = latitude;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/04971dcc/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
 
b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
index 599f9f3..d42c914 100644
--- 
a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
+++ 
b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
@@ -24,7 +24,10 @@ import 
org.apache.camel.component.twitter.consumer.Twitter4JConsumer;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
+import twitter4j.GeoLocation;
 import twitter4j.Query;
+import twitter4j.Query.Unit;
 import twitter4j.QueryResult;
 import twitter4j.Status;
 import twitter4j.Twitter;
@@ -42,14 +45,23 @@ public class SearchConsumer extends Twitter4JConsumer {
     }
 
     public List<Status> pollConsume() throws TwitterException {
-        String keywords = te.getProperties().getKeywords();
-        Query query = new Query(keywords);
-        if (te.getProperties().isFilterOld()) {
-            query.setSinceId(lastId);
-        }
-        
-        LOG.debug("Searching twitter with keywords: {}", keywords);
-        return search(query);
+       String keywords = te.getProperties().getKeywords();
+
+       Query query;
+
+       if(keywords!=null && keywords.trim().length() > 0) {
+               query = new Query(keywords);
+               LOG.debug("Searching twitter with keywords: {}", keywords);
+       } else {
+               query = new Query();
+               LOG.debug("Searching twitter without keywords.");
+       }
+
+       if (te.getProperties().isFilterOld()) {
+               query.setSinceId(lastId);
+       }
+
+       return search(query);
     }
 
     public List<Status> directConsume() throws TwitterException {
@@ -78,6 +90,15 @@ public class SearchConsumer extends Twitter4JConsumer {
             numberOfPages = te.getProperties().getNumberOfPages();
         }
         
+        if (ObjectHelper.isNotEmpty(te.getProperties().getLatitude()) &&
+                       
ObjectHelper.isNotEmpty(te.getProperties().getLongitude()) &&
+                       
ObjectHelper.isNotEmpty(te.getProperties().getRadius())) {
+               GeoLocation location = new 
GeoLocation(te.getProperties().getLatitude(), 
te.getProperties().getLongitude());
+               query.setGeoCode(location, te.getProperties().getRadius(), 
Unit.valueOf(te.getProperties().getDistanceMetric()));
+
+               LOG.debug("Searching with additional geolocation parameters.");
+        }
+        
         LOG.debug("Searching with {} pages.", numberOfPages);
 
         Twitter twitter = te.getProperties().getTwitter();

Reply via email to