Class: Twitter2Fleep::Bot

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter2fleep/bot.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Bot

Returns a new instance of Bot.



6
7
8
9
10
# File 'lib/twitter2fleep/bot.rb', line 6

def initialize(config)
  @twitter_client = Twitter::Streaming::Client.new(config[:twitter])
  @selected_user_ids = config[:selected_user_ids]
  @fleep_hook_url = config[:fleep_hook_url]
end

Instance Method Details

#startObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/twitter2fleep/bot.rb', line 12

def start
  @twitter_client.user do |object|
    case object
    when Twitter::Tweet
      tweet = object
      author = tweet.user

      if should_post?(tweet)
        message = "@#{author.screen_name}: #{tweet.text}"

        response = post_to_fleep(author.screen_name, message)

        puts message
        puts "----> #{response.status_code}"
      end
    when Twitter::Streaming::StallWarning
      warn "Falling behind!"
    end
  end
end