Class: Myun2::TwitterShell::Tail

Inherits:
Object
  • Object
show all
Defined in:
lib/myun2/twitter_shell/tail.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile, *params) ⇒ Tail

Returns a new instance of Tail.



7
8
9
10
11
12
13
14
# File 'lib/myun2/twitter_shell/tail.rb', line 7

def initialize(profile, *params)
  Tail.home_timeline_streaming(profile) do |o|
    if o.is_a?(::Twitter::Tweet)
      puts "#{o.created_at} -> @#{o.user.screen_name}"
      puts "\e[38;5;#{o.user.id % 255}m<#{o.user.name}>\e[0m: #{o.text}"
    end
  end
end

Class Method Details

.home_timeline_streaming(profile, &block) ⇒ Object



25
26
27
# File 'lib/myun2/twitter_shell/tail.rb', line 25

def self.home_timeline_streaming(profile, &block)
  streaming_client(profile).user({}, &block)
end

.streaming_client(profile) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/myun2/twitter_shell/tail.rb', line 16

def self.streaming_client(profile)
  @@client ||= ::Twitter::Streaming::Client.new(
    consumer_key:         Myun2::TwitterShell::ConsumerKey::KEY,
    consumer_secret:      Myun2::TwitterShell::ConsumerKey::SECRET,
    access_token:         profile[:access_token],
    access_token_secret:  profile[:access_token_secret],
  )
end