Class: Nicoalert::Client
- Inherits:
-
Object
- Object
- Nicoalert::Client
- Defined in:
- lib/nicoalert/client.rb
Instance Attribute Summary collapse
-
#mail ⇒ Object
readonly
Returns the value of attribute mail.
Instance Method Summary collapse
- #addr ⇒ Object
- #communities ⇒ Object
- #connect(&block) ⇒ Object
-
#initialize(mail, password) ⇒ Client
constructor
A new instance of Client.
- #port ⇒ Object
- #thread ⇒ Object
- #user_hash ⇒ Object
- #user_id ⇒ Object
Constructor Details
#initialize(mail, password) ⇒ Client
Returns a new instance of Client.
11 12 13 14 |
# File 'lib/nicoalert/client.rb', line 11 def initialize(mail, password) @mail = mail @password = password end |
Instance Attribute Details
#mail ⇒ Object (readonly)
Returns the value of attribute mail.
9 10 11 |
# File 'lib/nicoalert/client.rb', line 9 def mail @mail end |
Instance Method Details
#addr ⇒ Object
24 25 26 |
# File 'lib/nicoalert/client.rb', line 24 def addr @addr ||= status.css('ms addr').text end |
#communities ⇒ Object
36 37 38 |
# File 'lib/nicoalert/client.rb', line 36 def communities @communities ||= status.css('communities community_id').map(&:text) end |
#connect(&block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/nicoalert/client.rb', line 40 def connect(&block) TCPSocket.open(addr, port) do |socket| socket << %{<thread thread="#{thread}" version="20061206" res_from="-1" />\0} while line = socket.gets("\0") item = Nokogiri::XML.fragment(line.sub("\0", '')) next unless chat = item.css('chat') id, community, user = chat.text.split(',') next unless id && community && user block.call Live.new(id, community) end end end |
#port ⇒ Object
28 29 30 |
# File 'lib/nicoalert/client.rb', line 28 def port @port ||= status.css('ms port').text end |
#thread ⇒ Object
32 33 34 |
# File 'lib/nicoalert/client.rb', line 32 def thread @thread ||= status.css('ms thread').text end |
#user_hash ⇒ Object
20 21 22 |
# File 'lib/nicoalert/client.rb', line 20 def user_hash @user_hash ||= status.css('user_hash').text end |
#user_id ⇒ Object
16 17 18 |
# File 'lib/nicoalert/client.rb', line 16 def user_id @user_id ||= status.css('user_id').text end |