Skip to content

Instantly share code, notes, and snippets.

@mwawrusch
Created June 23, 2011 07:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mwawrusch/1042106 to your computer and use it in GitHub Desktop.
Save mwawrusch/1042106 to your computer and use it in GitHub Desktop.
Twitter.configure do |config|
# config.gateway = "http://#{self.apigee_twitter_api_endpoint}"
config.consumer_key = self.twitter_key
config.consumer_secret= self.twitter_secret
config.oauth_token = authentication.token
config.oauth_token_secret = authentication.secret
end
user.set_is_working! true, 1,"Retrieving followers and friends!",false
#log "Key: #{self.twitter_key} against http://#{self.apigee_twitter_api_endpoint}"
log "Retrieving friends for user #{self.user_name}"
client = Twitter::Client.new
max_tries = 50 # e.g. limit = 5000
cursor = -1
total_user_count= 0
begin
max_tries = max_tries - 1
# client
hashie = client.friends(:cursor => cursor)
cursor = hashie.next_cursor
log "Request results in #{hashie.users.count} users"
hashie.users.each do |x|
begin
p = SocialPerson.create_or_update_social_person!('twitter',
x['screen_name'],
x['name'],
x['screen_name'],
x['description'],
x['profile_image_url'],
x['location'])
c = SocialConnection.get_or_create!(user,p)
rescue Exception => e
log "Oops #{e.message}"
# TODO: LOG THIS AS AN IMPORT ERROR FOR GECKOBOARD
end
# create relationship here
end
total_user_count =total_user_count +hashie.users.count
user.set_is_working! true, 50,"Fetching social_persons. #{total_user_count} social_persons so far.",false
log "Fetched #{hashie.users.count} social_persons."
end until max_tries < 0 || cursor == nil || cursor == 0
#user.user_status.is_new_user = true
user.set_is_working false, 100,"Setup completed successfully!",false
user.user_status.is_setup_complete = true
user.save!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment