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 ⇒ Object
86
87
88
|
# File 'lib/twat/actions.rb', line 86
def method_missing
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
|
#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
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/twat/actions.rb', line 15
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
38
39
40
41
42
43
44
45
|
# File 'lib/twat/actions.rb', line 38
def delete
if config.accounts.delete(opts[:account])
config.save!
puts "Successfully deleted"
else
puts "No such account"
end
end
|
#setdefault ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/twat/actions.rb', line 47
def setdefault
unless config.accounts.include?(opts[:account])
raise NoSuchAccount
end
config[:default] = opts[:account]
config.save!
puts "Successfully set #{opts[:account]} as default"
end
|
#show ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'lib/twat/actions.rb', line 61
def show
Twitter.home_timeline.each_with_index do |, idx|
format()
break if idx == opts[:count]
end
end
|
8
9
10
11
12
13
|
# File 'lib/twat/actions.rb', line 8
def
Twitter.update(opts.msg)
end
|
#updateconfig ⇒ Object
57
58
59
|
# File 'lib/twat/actions.rb', line 57
def updateconfig
config.update!
end
|
#user_feed ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/twat/actions.rb', line 70
def user_feed
begin
Twitter.user_timeline(opts[:user]).first.tap do ||
puts "#{.user.screen_name.bold.cyan}: #{.text}"
end
rescue Twitter::NotFound
puts "#{opts[:user].bold.red} doesn't appear to be a valid user"
end
end
|