Class: Account
- Inherits:
-
Object
- Object
- Account
- Defined in:
- lib/raphael/account.rb
Class Attribute Summary collapse
-
.accounts ⇒ Object
readonly
Returns the value of attribute accounts.
Instance Attribute Summary collapse
-
#rest ⇒ Object
readonly
Returns the value of attribute rest.
-
#screen_name ⇒ Object
readonly
Returns the value of attribute screen_name.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#thread ⇒ Object
Returns the value of attribute thread.
Class Method Summary collapse
- .all ⇒ Object
- .find(screen_name) ⇒ Object
- .load_yaml(path) ⇒ Object
- .register(*args) ⇒ Object
- .threads ⇒ Object
Instance Method Summary collapse
-
#initialize(tag, token) ⇒ Account
constructor
A new instance of Account.
- #start_stream ⇒ Object
Constructor Details
#initialize(tag, token) ⇒ Account
Returns a new instance of Account.
8 9 10 11 12 13 |
# File 'lib/raphael/account.rb', line 8 def initialize(tag, token) @tag = tag @rest = Twitter::REST::Client.new(token) @stream = Twitter::Streaming::Client.new(token) @screen_name = @rest.user.screen_name end |
Class Attribute Details
.accounts ⇒ Object (readonly)
Returns the value of attribute accounts.
49 50 51 |
# File 'lib/raphael/account.rb', line 49 def accounts @accounts end |
Instance Attribute Details
#rest ⇒ Object (readonly)
Returns the value of attribute rest.
4 5 6 |
# File 'lib/raphael/account.rb', line 4 def rest @rest end |
#screen_name ⇒ Object (readonly)
Returns the value of attribute screen_name.
4 5 6 |
# File 'lib/raphael/account.rb', line 4 def screen_name @screen_name end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
4 5 6 |
# File 'lib/raphael/account.rb', line 4 def stream @stream end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
4 5 6 |
# File 'lib/raphael/account.rb', line 4 def tag @tag end |
#thread ⇒ Object
Returns the value of attribute thread.
5 6 7 |
# File 'lib/raphael/account.rb', line 5 def thread @thread end |
Class Method Details
.all ⇒ Object
55 56 57 |
# File 'lib/raphael/account.rb', line 55 def all Array(@accounts) end |
.find(screen_name) ⇒ Object
59 60 61 |
# File 'lib/raphael/account.rb', line 59 def find screen_name Account.all.find{|a|a.screen_name == screen_name} end |
.load_yaml(path) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/raphael/account.rb', line 67 def load_yaml path YAML.load_file(path).each do |tag, token| Account.register(tag, token) end rescue Error.callback($!) end |
.register(*args) ⇒ Object
51 52 53 |
# File 'lib/raphael/account.rb', line 51 def register *args @accounts << self.new(*args) end |
Instance Method Details
#start_stream ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/raphael/account.rb', line 15 def start_stream self.stream.user replies: 'all' do |obj| begin case obj when Twitter::Tweet Tweet.callback obj, self obj.text =~ /^@\w+?\s+?(.+)/ if $1 obj.args = $1.split end Command.all.each do |command| if obj.text =~ /^@(?:nkroid)\s+#{command.arg}/ command.proc.call obj, self end end when Twitter::Streaming::FriendList FriendList.callback obj, self when Twitter::Streaming::Event Event.callback obj, self when Twitter::Streaming::DeletedTweet DeletedTweet.callback obj, self end rescue Error.callback($!) next end end rescue Error.callback($!) retry end |