Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Showing with 42 additions and 11 deletions.
  1. +1 −0 Readme.rdoc
  2. +6 −1 app.rb
  3. +3 −7 models/user.rb
  4. +32 −3 workers/follows.rb
View
1 Readme.rdoc
@@ -27,6 +27,7 @@ You will need Redis in order to use Resque for background jobs.
heroku config:add CONSUMER_SECRET="Your Twitter Consumer Secret"
heroku addons:add neo4j
heroku addons:add redistogo
+ heroku addons:add apigee
git push heroku master
See it running live at http://neotweet.herokuapp.com
View
7 app.rb
@@ -11,6 +11,8 @@
set :key, ENV['CONSUMER_KEY']
set :secret, ENV['CONSUMER_SECRET']
set :neo, Neography::Rest.new
+ set :apigee_api, 'http://' + ENV['APIGEE_TWITTER_API_ENDPOINT']
+ set :apigee_search_api, 'http://' + ENV['APIGEE_TWITTER_SEARCH_API_ENDPOINT']
uri = URI.parse(ENV["REDISTOGO_URL"])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
@@ -19,7 +21,6 @@
require "models/user"
require "workers/follows"
-require 'pp'
use OmniAuth::Builder do
provider :twitter, settings.key, settings.secret
@@ -28,6 +29,10 @@
Twitter.configure do |config|
config.consumer_key = settings.key
config.consumer_secret = settings.secret
+ config.endpoint = settings.apigee_api
+ # config.gateway = settings.apigee_api # null in to string error
+ # config.gateway = "http://twitter.apigee.com" # null in to string error
+ # config.proxy = "twitter.apigee.com" # seems to ignore it and we get hit with the limit
end
helpers do
View
10 models/user.rb
@@ -28,7 +28,9 @@ def self.create_with_omniauth(auth)
def client
@client ||= Twitter::Client.new(
- :oauth_token => self.token,
+# :endpoint => settings.apigee_api,
+# :search_endpoint => settings.apigee_search_api,
+ :oauth_token => self.token,
:oauth_token_secret => self.secret
)
end
@@ -44,10 +46,4 @@ def self.create_from_twitter(friend)
user
end
-# def import_friends
-# client.friend_ids.ids.each do |f|
-# User.create_from_twitter(client.user(f))
-# end
-# end
-
end
View
35 workers/follows.rb
@@ -7,6 +7,8 @@ def self.perform(uid)
commands = []
cursor = "-1"
+ # Get the twitter users I follow
+
while cursor != 0 do
friends = user.client.friend_ids({:cursor => cursor})
cursor = friends.next_cursor
@@ -21,18 +23,45 @@ def self.perform(uid)
"uid" => friend.id
}]
end
-
end
batch_result = @neo.batch *commands
commands = []
+ # Add the twitter users I follow as my followers
+
batch_result.each do |b|
commands << [:create_unique_relationship, "follows_index", "nodes", "#{uid}-#{b["body"]["data"]["uid"]}", "follows", user, b["body"]["self"].split("/").last]
- end
- @neo.batch *commands
+ cursor = "-1"
+
+ # Get the twitter users that follow the users I follow
+
+ while cursor != 0 do
+ friends = user.client.friend_ids(b["body"]["data"]["uid"] , {:cursor => cursor})
+ cursor = friends.next_cursor
+ friends.ids.each do |f|
+ friend = user.client.user(f)
+ commands << [:create_unique_node, "users_index", "uid", friend.id,
+ {"name" => friend.name,
+ "nickname" => friend.screen_name,
+ "location" => friend.location,
+ "image_url" => friend.profile_image_url,
+ "uid" => friend.id
+ }]
+ end
+ end
+
+ batch_result_fofs = @neo.batch *commands
+ commands = []
+
+ batch_result_fofs.each do |c|
+ commands << [:create_unique_relationship, "follows_index", "nodes", "#{b["body"]["data"]["uid"]}-#{c["body"]["data"]["uid"]}", "follows", b["body"]["self"].split("/").last, c["body"]["self"].split("/").last]
+ end
+
+ @neo.batch *commands
+ end
end
end

No commit comments for this range

Something went wrong with that request. Please try again.