Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 3379cad066ab02f305d478d9e31d711b11c834e5 Carin Meier committed Feb 22, 2011
@@ -0,0 +1,4 @@
+pom.xml
+*jar
+lib
+classes
@@ -0,0 +1,14 @@
+# twitter-social-graph
+
+This is a small sample project using Clojure twitter, oAuth and Midje. It contains functions to find the followers in common between two twitter usernames
+
+## Usage
+
+To use, you need to set up a Twitter Application http://twitter.com/apps/new.
+Once you have your oauth-access-token and your oauth-access-token-secret, you can put them in the core.clj file to connect up to Twitter.
+
+## License
+
+Copyright (C) 2010 FIXME
+
+Distributed under the Eclipse Public License, the same as Clojure.
@@ -0,0 +1,9 @@
+(defproject clojure-twitter-in-common "0.0.1"
+ :description "Twitter Followers In Common Demo using clojure-twitter"
+ :dependencies [[org.clojure/clojure "1.2.0"]
+ [org.clojure/clojure-contrib "1.2.0"]
+ [clj-oauth "1.2.10"]
+ [com.twinql.clojure/clj-apache-http "2.3.1"]
+ [clojure-twitter "1.2.5"]]
+ :dev-dependencies [[swank-clojure "1.2.1"]
+ [midje "1.1-alpha-1"]])
@@ -0,0 +1,40 @@
+(ns clojure-twitter-in-common.core
+ (:use [clojure.contrib.logging])
+ (:require [twitter] [oauth.client :as oauth]))
+
+
+;; This suppress warnings on the http client - Invalid Cookie Header
+(defn set-log-level! [level]
+ "Sets the root logger's level, and the level of all of its Handlers, to level.
+ Level should be one of the constants defined in java.util.logging.Level."
+ (let [logger (.getLogger (impl-get-log ""))]
+ (.setLevel logger level)
+ (doseq [handler (.getHandlers logger)]
+ (. handler setLevel level))))
+
+(set-log-level! java.util.logging.Level/SEVERE)
+
+(def oauth-access-token
+ "mNGQGY4H2CNHJyeVMgeeA")
+(def oauth-access-token-secret
+ "Brpf2a4140DmwRgoLsTq8YG4jqJ9BSjkBQYv4qXEVyQ")
+
+(def oauth-consumer (oauth/make-consumer oauth-access-token
+ oauth-access-token-secret
+ "https://api.twitter.com/oauth/request_token"
+ "https://api.twitter.com/oauth/access_token"
+ "https://api.twitter.com/oauth/authorize"
+ :hmac-sha1))
+(defn get-screen-name-from-id [twitterid]
+ (:screen_name (twitter/show-user-by-id (str twitterid))))
+
+
+(defn followers-in-common [username1 username2]
+ (pmap get-screen-name-from-id (clojure.set/intersection (set (twitter/followers-of-name username1))
+ (set (twitter/followers-of-name username2)))))
+
+
+
+
+
+
@@ -0,0 +1 @@
+myvalue="test"
@@ -0,0 +1,15 @@
+(ns clojure-twitter-in-common.test.core
+ (:use [clojure-twitter-in-common.core] :reload)
+ (:use [clojure.test])
+ (:use [midje.sweet])
+ (:use [clojure.contrib.logging]))
+
+(with-test
+ (def carin-followers (twitter/followers-of-name "carinmeier"))
+ (def carin-cinijs-followers-in-common (followers-in-common "carinmeier" "cincijs"))
+
+ (fact (< 0 (.size carin-followers)) => true)
+ (fact (< 0 (.size carin-cinijs-followers-in-common)) => true)
+ (fact (get-screen-name-from-id "205291621") => "cincijs"))
+
+

0 comments on commit 3379cad

Please sign in to comment.