Class: TwitterClient

Inherits:
Object
  • Object
show all
Defined in:
lib/clients/twitter_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(twitter_config) ⇒ TwitterClient

Returns a new instance of TwitterClient.



2
3
4
5
6
7
8
9
10
# File 'lib/clients/twitter_client.rb', line 2

def initialize(twitter_config)
  @rest_client = Twitter::REST::Client.new do |config|
    config.consumer_key = twitter_config.consumer_key
    config.consumer_secret = twitter_config.consumer_secret
    config.access_token = twitter_config.access_token
    config.access_token_secret = twitter_config.access_token_secret
  end
  @username = twitter_config.username
end

Instance Method Details

#follow(user) ⇒ Object



29
30
31
# File 'lib/clients/twitter_client.rb', line 29

def follow(user)
  @rest_client.follow(user)
end

#random_follower_of_random_followerObject



12
13
14
15
# File 'lib/clients/twitter_client.rb', line 12

def random_follower_of_random_follower
  follower = @rest_client.followers.attrs[:users].sample[:screen_name]
  @rest_client.friend_ids(follower).attrs[:ids].sample if follower
end

#search(query) ⇒ Object



25
26
27
# File 'lib/clients/twitter_client.rb', line 25

def search(query)
  @rest_client.search("#{query} -rt -from:#{@username}", { lang: 'en' }).first.text
end

#update(text) ⇒ Object



21
22
23
# File 'lib/clients/twitter_client.rb', line 21

def update(text)
  @rest_client.update(text)
end

#update_with_media(text, image_file) ⇒ Object



17
18
19
# File 'lib/clients/twitter_client.rb', line 17

def update_with_media(text, image_file)
  @rest_client.update_with_media(text, image_file)
end