Class: Twat::Actions
- Inherits:
-
Object
show all
- Defined in:
- lib/twat/actions.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
128
129
130
|
# File 'lib/twat/actions.rb', line 128
def method_missing(sym, *args, &block)
raise NoSuchCommand
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6
7
8
|
# File 'lib/twat/actions.rb', line 6
def config
@config
end
|
#failcount ⇒ Object
Returns the value of attribute failcount.
6
7
8
|
# File 'lib/twat/actions.rb', line 6
def failcount
@failcount
end
|
#opts ⇒ Object
Returns the value of attribute opts.
6
7
8
|
# File 'lib/twat/actions.rb', line 6
def opts
@opts
end
|
Instance Method Details
#add ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/twat/actions.rb', line 17
def add
v = Config.consumer_info.map do |key, value|
value
end
oauth = OAuth::Consumer.new( v[0], v[1],
{ site: "http://twitter.com" })
token_request = oauth.get_request_token()
puts "Please authenticate the application at #{token_request.authorize_url}, then enter pin"
pin = gets.chomp
begin
access_token = token_request.get_access_token(oauth_verifier: pin)
config.accounts[opts[:account]] = {
oauth_token: access_token.token,
oauth_token_secret: access_token.secret
}
config.save!
rescue OAuth::Unauthorized
puts "Couldn't authenticate you, did you enter the pin correctly?"
end
end
|
#delete ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/twat/actions.rb', line 40
def delete
if config.accounts.delete(opts[:account])
config.save!
puts "Successfully deleted"
else
puts "No such account"
end
end
|
#follow ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/twat/actions.rb', line 85
def follow
failcount = 0
= Twitter.home_timeline(:count => 5)
while true do
begin
last_id = process_followed() if .any?
sleep config.polling_interval
= Twitter.home_timeline(:since_id => last_id)
failcount = 0
rescue Interrupt
break
rescue Errno::ECONNRESET
if failcount > 2
puts "3 consecutive failures, giving up"
else
failcount += 1
end
end
end
end
|
#setoption ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/twat/actions.rb', line 49
def setoption
k, v = opts[:optval].split("=")
raise RequiresOptVal unless v
options = Options.new
options.send(:"#{k}=", v)
puts "Successfully set #{k} as #{v}"
end
|
#show ⇒ Object
62
63
64
65
66
67
|
# File 'lib/twat/actions.rb', line 62
def show
Twitter.home_timeline(:count => opts[:count]).each do ||
format()
end
end
|
8
9
10
11
12
13
14
15
|
# File 'lib/twat/actions.rb', line 8
def
raise TweetTooLong if opts.msg.length > 140
Twitter.update(opts.msg)
end
|
#updateconfig ⇒ Object
58
59
60
|
# File 'lib/twat/actions.rb', line 58
def updateconfig
config.update!
end
|
#user_feed ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/twat/actions.rb', line 112
def user_feed
begin
Twitter.user_timeline(opts[:user], :count => opts[:count]).each do ||
format()
end
rescue Twitter::NotFound
puts "#{opts[:user].bold.red} doesn't appear to be a valid user"
end
end
|