Class: TwitterAccount

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTwitterAccount

Returns a new instance of TwitterAccount.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/twitter_account.rb', line 7

def initialize
  config = ConfigStore.new("#{ENV['HOME']}/.twitter")
  httpauth = Twitter::HTTPAuth.new(config['email'], config['password'])
  @account = Twitter::Base.new(httpauth)

  @friends = @account.friends.map do |friend|
    friend.screen_name
  end

  @followers = @account.followers.map do |follower|
    follower.screen_name
  end
end

Instance Attribute Details

#followersObject (readonly)

Returns the value of attribute followers.



5
6
7
# File 'lib/twitter_account.rb', line 5

def followers
  @followers
end

#friendsObject (readonly)

Returns the value of attribute friends.



5
6
7
# File 'lib/twitter_account.rb', line 5

def friends
  @friends
end

Instance Method Details

#direct_messagesObject



28
29
30
31
# File 'lib/twitter_account.rb', line 28

def direct_messages
  texts = @account.direct_messages.map {|t| "#{t.sender.screen_name}> #{t.text}"}
  texts.join("\n") + "\n"
end

#friends_timelineObject

wating for a better formating (see twitter gem bien) this methods are looking for some factoring



23
24
25
26
# File 'lib/twitter_account.rb', line 23

def friends_timeline
  texts = @account.friends_timeline.map {|t| "#{t.user.screen_name}> #{t.text}"}
  texts.join("\n") + "\n"
end

#repliesObject



38
39
40
41
# File 'lib/twitter_account.rb', line 38

def replies
  texts = @account.replies.map {|t| "#{t.user.screen_name}> #{t.text}"}
  texts.join("\n") + "\n"
end

#update(msg) ⇒ Object



43
44
45
# File 'lib/twitter_account.rb', line 43

def update(msg)
  @account.update msg
end

#updatesObject



33
34
35
36
# File 'lib/twitter_account.rb', line 33

def updates
  texts = @account.user_timeline.map {|t| "#{t.user.screen_name}> #{t.text}"}
  texts.join("\n") + "\n"
end

#user_timeline(user) ⇒ Object



47
48
49
50
# File 'lib/twitter_account.rb', line 47

def user_timeline(user)
  texts = Twitter::Search.new(user).map {|t| "#{t.from_user}> #{t.text}"}
  texts.join("\n") + "\n"
end