Author: dblevins
Date: Mon May 30 23:53:01 2011
New Revision: 1129438

URL: http://svn.apache.org/viewvc?rev=1129438&view=rev
Log:
Patch from Vishwanath (@stratwine) OPENEJB-1565: OpenEJB Retweet Bot
Thanks, Vishwanath!

Added:
    
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/AuthorizationUrlGenerator.java
   (with props)
    
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/StoreAccessToken.java
   (with props)
Modified:
    openejb/trunk/sandbox/tools/pom.xml
    
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/examples/GenerateIndex.java
    
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/Retweet.java

Modified: openejb/trunk/sandbox/tools/pom.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/pom.xml?rev=1129438&r1=1129437&r2=1129438&view=diff
==============================================================================
--- openejb/trunk/sandbox/tools/pom.xml (original)
+++ openejb/trunk/sandbox/tools/pom.xml Mon May 30 23:53:01 2011
@@ -65,6 +65,19 @@
       <version>4.8.1</version>
       <scope>test</scope>
     </dependency>
+    
+      <dependency>
+        <groupId>oauth.signpost</groupId>
+        <artifactId>signpost-core</artifactId>
+        <version>1.2</version>
+        <scope>compile</scope>
+      </dependency>
+      
+<dependency>
+    <groupId>org.springframework</groupId>
+    <artifactId>spring-core</artifactId>
+    <version>3.0.5.RELEASE</version>
+</dependency>
 
   </dependencies>
 </project>

Modified: 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/examples/GenerateIndex.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/examples/GenerateIndex.java?rev=1129438&r1=1129437&r2=1129438&view=diff
==============================================================================
--- 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/examples/GenerateIndex.java
 (original)
+++ 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/examples/GenerateIndex.java
 Mon May 30 23:53:01 2011
@@ -19,38 +19,24 @@ package org.apache.openejb.tools.example
 /**
  * Most the examples do not have any documentation.
  *
- * There are some wiki pages for some of the examples, but these
- * are hard to create and maintain.  The examples change frequently
- * enough that we really should have documentation that goes with
- * each version of the examples.
- *
- * If we put a README.md file in each example and use Markdown
- * which is a really simple text format that has many tools
- * capable of generating html, we could probably generate a
- * web page for each example.  Then we could generate a index
- * for all the examples.
+ * There are some wiki pages for some of the examples, but these are hard to 
create and maintain.  The examples change frequently enough that we really 
should have documentation that goes with each version of the examples.
+ *
+ * If we put a README.md file in each example and use Markdown which is a 
really simple text format that has many tools capable of generating html, we 
could probably generate a web page for each example.  Then we could generate a 
index for all the examples.
  *
  * We could then take this all and upload it to the website
  *
- * Something kind of like this:
- *    http://people.apache.org/~dblevins/simple-stateless.html
+ * Something kind of like this, but nicer looking, with breadcrumbs and links 
for navigating around to other examples: 
http://people.apache.org/~dblevins/simple-stateless.html
+ *
  *
- * But nicer looking, with breadcrumbs and links for navigating
- * around to other examples
  *
  *
  * IDEAS FOR AFTER SOMETHING IS WORKING
  *
- * Perhaps at some point some xref style processing of the source
- * and links to the source
+ * Perhaps at some point some xref style processing of the source and links to 
the source
+ *
+ * Perhaps at some point use ASM to see what annotations and API classes were 
used and make an index that lists examples by which APIs are used
  *
- * Perhaps at some point use ASM to see what annotations and API
- * classes were used and make an index that lists examples by
- * which APIs are used
- *
- * Perhaps at some point use Swizzle stream to do a sort of SNIPPET
- * thing like the Confluence plugin, so we wouldn't have to copy
- * source into the example
+ * Perhaps at some point use Swizzle stream to do a sort of SNIPPET thing like 
the Confluence plugin, so we wouldn't have to copy source into the example
  *
  * @version $Rev$ $Date$
  */

Added: 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/AuthorizationUrlGenerator.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/AuthorizationUrlGenerator.java?rev=1129438&view=auto
==============================================================================
--- 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/AuthorizationUrlGenerator.java
 (added)
+++ 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/AuthorizationUrlGenerator.java
 Mon May 30 23:53:01 2011
@@ -0,0 +1,114 @@
+/**
+ * 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.openejb.tools.twitter;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+
+import oauth.signpost.OAuth;
+import oauth.signpost.OAuthConsumer;
+import oauth.signpost.OAuthProvider;
+import oauth.signpost.basic.DefaultOAuthConsumer;
+import oauth.signpost.basic.DefaultOAuthProvider;
+import oauth.signpost.exception.OAuthCommunicationException;
+import oauth.signpost.exception.OAuthExpectationFailedException;
+import oauth.signpost.exception.OAuthMessageSignerException;
+import oauth.signpost.exception.OAuthNotAuthorizedException;
+
+import org.springframework.core.io.ClassPathResource;
+
+public class AuthorizationUrlGenerator {
+       static Properties retweetToolProperties;
+       static OAuthConsumer consumer;
+       static OAuthProvider provider;
+
+       public static void main(String[] args) {
+               retweetToolProperties = getTwitterAppProperties();
+               intializeOAuthConsumerAndProvider();
+               getAuthorizationUrl();
+
+       }
+
+       private static Properties getTwitterAppProperties() {
+
+               Properties retweetAppProperties = new Properties();
+               try {
+                       ClassPathResource retweetToolPropertiesFile = new 
ClassPathResource(
+                       "RetweetTool.properties");
+                       retweetAppProperties.load(retweetToolPropertiesFile
+                                       .getInputStream());
+               } catch (FileNotFoundException e) {
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+
+               System.out.print("Using the following properties: ");
+               System.out.print("---------------------------------");
+               retweetAppProperties.list(System.out);
+               return retweetAppProperties;
+
+       }
+       
+       private static void intializeOAuthConsumerAndProvider() {
+
+               consumer = new DefaultOAuthConsumer(
+                               
retweetToolProperties.getProperty("retweetApp.consumer.key"),
+                               retweetToolProperties
+                               .getProperty("retweetApp.consumerSecret.key"));
+
+               provider = new DefaultOAuthProvider(
+                               "http://twitter.com/oauth/request_token";,
+                               "http://twitter.com/oauth/access_token";,
+                               "http://twitter.com/oauth/authorize";);
+
+       }
+
+       
+       private static void getAuthorizationUrl() {
+
+               try {
+                       getAccessAuthorizationURL();
+               } catch (OAuthMessageSignerException e) {
+                       e.printStackTrace();
+               } catch (OAuthNotAuthorizedException e) {
+                       e.printStackTrace();
+               } catch (OAuthExpectationFailedException e) {
+                       e.printStackTrace();
+               } catch (OAuthCommunicationException e) {
+                       e.printStackTrace();
+               }
+
+       }
+
+       private static void getAccessAuthorizationURL()
+       throws OAuthMessageSignerException, OAuthNotAuthorizedException,
+       OAuthExpectationFailedException, OAuthCommunicationException {
+
+               String authUrl;
+               authUrl = provider.retrieveRequestToken(consumer, 
OAuth.OUT_OF_BAND);
+               System.out.println("#####################");
+               System.out.println("Paste the below URL in the browser and 
authorize");
+               System.out.println(authUrl);
+               System.out.println("#####################");
+
+       }
+
+       
+       
+}

Propchange: 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/AuthorizationUrlGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/Retweet.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/Retweet.java?rev=1129438&r1=1129437&r2=1129438&view=diff
==============================================================================
--- 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/Retweet.java
 (original)
+++ 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/Retweet.java
 Mon May 30 23:53:01 2011
@@ -16,6 +16,22 @@
  */
 package org.apache.openejb.tools.twitter;
 
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+
+import oauth.signpost.OAuthConsumer;
+import oauth.signpost.OAuthProvider;
+import oauth.signpost.basic.DefaultOAuthConsumer;
+import oauth.signpost.basic.DefaultOAuthProvider;
+import oauth.signpost.exception.OAuthCommunicationException;
+import oauth.signpost.exception.OAuthExpectationFailedException;
+import oauth.signpost.exception.OAuthMessageSignerException;
+import oauth.signpost.exception.OAuthNotAuthorizedException;
+
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.util.Assert;
+
 /**
  *
  * We should monitor this feed http://twitter.com/#!/OpenEJB/contributors
@@ -41,8 +57,8 @@ public class Retweet {
     // Implementation ideas
 
     //  Seems signpost is just what we need for OAuth 
http://code.google.com/p/oauth-signpost/wiki/GettingStarted
-
-    //  Twitter API
+          
+       //  Twitter API
 
     //  list - HTTP GET 
http://api.twitter.com/1/lists/statuses.xml?slug=contributors&owner_screen_name=OpenEJB
 
@@ -52,7 +68,16 @@ public class Retweet {
 
     public static void main(String[] args) {
 
-
+       // Register a Twitter App
+        
+       // User should authorize it with READ/WRITE access. See 
AuthorizationUrlGenerator.java (user=OpenEJB Twitter Account)
+       
+       // On Authorization, user is given a PIN number. 
+       
+       // Based on the PIN number get the AccessToken. And save the access 
token permanently (File / DB ) 
+       
+       // Use this access token for any READ/WRITE 
+        
         // Grab the http://twitter.com/#!/OpenEJB/contributors feed via the 
Twitter API
 
         // Scan for new tweets from the last hour
@@ -60,7 +85,16 @@ public class Retweet {
         // Retweet any tweets that haven't been retweeted
 
         // We could look at the OpenEJB twitter feed itself to determine if a 
tweet
-        // has already been retweeted
-
+        // has already been retweeted  
+      
     }
+
+
+       
+       
+               
+
+
+
+       
 }

Added: 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/StoreAccessToken.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/StoreAccessToken.java?rev=1129438&view=auto
==============================================================================
--- 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/StoreAccessToken.java
 (added)
+++ 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/StoreAccessToken.java
 Mon May 30 23:53:01 2011
@@ -0,0 +1,23 @@
+/**
+ * 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.openejb.tools.twitter;
+
+public class StoreAccessToken {
+  //Retrieve access token based on the PIN number provided by the user.
+  // Store it in File/DB
+  // This access token would be used for any READ/WRITE
+}

Propchange: 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/StoreAccessToken.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to