Skip to content

Instantly share code, notes, and snippets.

@onedal
Created July 5, 2016 00:51
Show Gist options
  • Save onedal/3bd4213bd4c94274062b8ef3974ca81f to your computer and use it in GitHub Desktop.
Save onedal/3bd4213bd4c94274062b8ef3974ca81f to your computer and use it in GitHub Desktop.
class Twitter::Client
def initialize(token, secret)
@client = ::Twitter::REST::Client.new do |config|
config.consumer_key = Rails.application.secrets.twitter_api_key
config.consumer_secret = Rails.application.secrets.twitter_api_secret
config.access_token = token
config.access_token_secret = secret
end
end
# Cleaning twitter account
def all_clear(user)
#if twitter?(bip)
loop do
following_clear(user)
favorites_clear(user)
tweets_clear(user)
retweets_clear(user)
break
end
#end
end
def following_clear(user, start = 0 )
loop do
followings = client_user(user).friend_ids.attrs[:ids]
break if followings.count == 0 || (start == 15)
@client.unfollow(followings)
start += 1
end
end
def favorites_clear(user, start = 0 )
loop do
favorites = client_user(user).favorites({count: 100})
break if favorites.count == 0 || (start == 15)
@client.unfavorite(favorites)
start += 1
end
end
def tweets_clear(user, start = 0 )
loop do
tweets = client_user(user).user_timeline({count: 200})
break if tweets.count == 0 || (start == 150)
@client.destroy_status(tweets)
start += 1
end
end
def retweets_clear(user, start = 0 )
loop do
retweets = client_user(user).retweeted_by_me({count: 200})
break if retweets.count == 0 || (start == 15)
@client.destroy_status(retweets)
start += 1
end
end
# Last 100
def follow_to_followers(user)
followers = client_user(user).follower_ids({count: 100})
ids = followers.attrs[:ids]
@client.follow(ids)
end
def oembed(tid, user = current_user)
@client.oembed(tid)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment