camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jans...@apache.org
Subject git commit: CAMEL-6493 - add additional options for consuming messages
Date Fri, 28 Jun 2013 19:54:18 GMT
Updated Branches:
  refs/heads/master 6c0c2c170 -> 29d8db8fa


CAMEL-6493 - add additional options for consuming messages


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

Branch: refs/heads/master
Commit: 29d8db8fa235b490fbb76930693b87022c2aaa07
Parents: 6c0c2c1
Author: Jonathan Anstey <janstey@gmail.com>
Authored: Fri Jun 28 17:23:55 2013 -0230
Committer: Jonathan Anstey <janstey@gmail.com>
Committed: Fri Jun 28 17:23:55 2013 -0230

----------------------------------------------------------------------
 .../component/yammer/YammerConfiguration.java   | 89 +++++++++++++++++---
 .../yammer/YammerConsumerMessageLimitTest.java  | 44 ----------
 .../YammerMessagesConsumerOptionTest.java       | 42 +++++++++
 3 files changed, 119 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/29d8db8f/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/YammerConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/YammerConfiguration.java
b/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/YammerConfiguration.java
index f3e3117..f758c37 100644
--- a/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/YammerConfiguration.java
+++ b/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/YammerConfiguration.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.yammer;
 
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
+import org.apache.camel.util.ObjectHelper;
 
 @UriParams
 public class YammerConfiguration {
@@ -40,6 +41,15 @@ public class YammerConfiguration {
     @UriParam
     private int limit = -1; // default is unlimited
     
+    @UriParam
+    private int olderThan = -1;
+
+    @UriParam
+    private int newerThan = -1;
+
+    @UriParam
+    private String threaded;
+    
     private ApiRequestor requestor;
     
     public String getConsumerKey() {
@@ -83,35 +93,66 @@ public class YammerConfiguration {
     }
 
     public String getApiUrl() throws Exception {    
-        StringBuilder sb = new StringBuilder();
+        StringBuilder url = new StringBuilder();
         
         switch (YammerFunctionType.fromUri(function)) {
         case MESSAGES:
-            sb.append(YammerConstants.YAMMER_BASE_API_URL);
-            sb.append(function);
-            sb.append(".json");
+            url.append(YammerConstants.YAMMER_BASE_API_URL);
+            url.append(function);
+            url.append(".json");
             break;
         case ALGO:
         case FOLLOWING:
         case MY_FEED:
         case PRIVATE:
         case SENT:
-            sb.append(YammerConstants.YAMMER_BASE_API_URL);
-            sb.append("messages/");
-            sb.append(function);
-            sb.append(".json");
+            url.append(YammerConstants.YAMMER_BASE_API_URL);
+            url.append("messages/");
+            url.append(function);
+            url.append(".json");
             break;
         default:
             throw new Exception(String.format("%s is not a valid Yammer function type.",
function));
         }        
         
+        StringBuilder args = new StringBuilder();
+        
         if (limit > 0) {
-            sb.append("?");
-            sb.append("limit=");
-            sb.append(limit);
+            args.append("limit=");
+            args.append(limit);
+        }        
+
+        if (getOlderThan() > 0) {
+            if (args.length() > 0) {
+                args.append("&");
+            }
+            args.append("older_than=");
+            args.append(getOlderThan());
+        }        
+
+        if (getNewerThan() > 0) {
+            if (args.length() > 0) {
+                args.append("&");
+            }            
+            args.append("newer_than=");
+            args.append(getNewerThan());
+        }        
+        
+        if (ObjectHelper.isNotEmpty(getThreaded()) 
+                && ("true".equals(getThreaded()) || "extended".equals(getThreaded())))
{
+            if (args.length() > 0) {
+                args.append("&");
+            }            
+            args.append("threaded=");
+            args.append(getThreaded());
         }        
         
-        return sb.toString();
+        if (args.length() > 0) {
+            url.append("?");
+            url.append(args);
+        }            
+        
+        return url.toString();
     }
 
     public boolean isUseJson() {
@@ -141,4 +182,28 @@ public class YammerConfiguration {
         this.limit = limit;
     }
 
+    public int getOlderThan() {
+        return olderThan;
+    }
+
+    public void setOlderThan(int olderThan) {
+        this.olderThan = olderThan;
+    }
+
+    public int getNewerThan() {
+        return newerThan;
+    }
+
+    public void setNewerThan(int newerThan) {
+        this.newerThan = newerThan;
+    }
+
+    public String getThreaded() {
+        return threaded;
+    }
+
+    public void setThreaded(String threaded) {
+        this.threaded = threaded;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/29d8db8f/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java
----------------------------------------------------------------------
diff --git a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java
b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java
deleted file mode 100644
index f014d17..0000000
--- a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.yammer;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.junit.Test;
-
-public class YammerConsumerMessageLimitTest extends YammerComponentTestSupport {
-
-    @Test
-    public void testConsumerMessageLimit() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMinimumMessageCount(1);
-        assertMockEndpointsSatisfied();
-        
-        // now check if limit option got applied
-        assertEquals(1, yammerComponent.getConfig().getLimit());
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            public void configure() {
-                // using dummy keys here since we are mocking out calls to yammer.com with
static json; in a real app, please use your own keys!
-                from("yammer:messages?consumerKey=aConsumerKey&consumerSecret=aConsumerSecretKey&accessToken=aAccessToken&limit=1").to("mock:result");
-            }
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/29d8db8f/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerMessagesConsumerOptionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerMessagesConsumerOptionTest.java
b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerMessagesConsumerOptionTest.java
new file mode 100644
index 0000000..728fdf9
--- /dev/null
+++ b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerMessagesConsumerOptionTest.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.yammer;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class YammerMessagesConsumerOptionTest extends YammerComponentTestSupport {
+
+    @Test
+    public void testOptions() throws Exception {
+        // now check if options got applied
+        assertEquals(1, yammerComponent.getConfig().getLimit());
+        assertEquals("true", yammerComponent.getConfig().getThreaded());
+        assertEquals(130, yammerComponent.getConfig().getOlderThan());
+        assertEquals(127, yammerComponent.getConfig().getNewerThan());
+        assertEquals(YammerConstants.YAMMER_BASE_API_URL + "messages.json?limit=1&older_than=130&newer_than=127&threaded=true",
yammerComponent.getConfig().getApiUrl());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                from("yammer:messages?consumerKey=aConsumerKey&consumerSecret=aConsumerSecretKey&accessToken=aAccessToken&limit=1&threaded=true&olderThan=130&newerThan=127").to("mock:result");
+            }
+        };
+    }
+}


Mime
View raw message