Class: AnonClient
- Inherits:
-
Object
- Object
- AnonClient
- Defined in:
- lib/chatx/polling.rb
Instance Attribute Summary collapse
-
#rooms ⇒ Object
Returns the value of attribute rooms.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
-
#initialize(bot, server, room_id, poll_frequency: 2) ⇒ AnonClient
constructor
A new instance of AnonClient.
- #join_room(room_id) ⇒ Object
- #kill ⇒ Object
Constructor Details
#initialize(bot, server, room_id, poll_frequency: 2) ⇒ AnonClient
Returns a new instance of AnonClient.
4 5 6 7 8 9 10 11 |
# File 'lib/chatx/polling.rb', line 4 def initialize(bot, server, room_id, poll_frequency: 2) @poll_frequency = poll_frequency @bot = bot @dead = false @server = server join_room room_id start_loop end |
Instance Attribute Details
#rooms ⇒ Object
Returns the value of attribute rooms.
2 3 4 |
# File 'lib/chatx/polling.rb', line 2 def rooms @rooms end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
3 4 5 |
# File 'lib/chatx/polling.rb', line 3 def server @server end |
Instance Method Details
#join_room(room_id) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/chatx/polling.rb', line 13 def join_room(room_id) @fkey = Nokogiri::HTML(open("https://chat.#{server}.com/rooms/#{room_id}").read).search("//input[@name='fkey']").attribute("value") events_json = Net::HTTP.post_form(URI("https://chat.#{@server}.com/chats/#{room_id}/events"), fkey: @fkey, since: 0, mode: "Messages", msgCount: 100).body events = JSON.parse(events_json)["events"] last_event_time = events.max_by { |event| event['time_stamp'] }['time_stamp'] @rooms = {"r#{room_id}" => last_event_time} end |
#kill ⇒ Object
26 27 28 29 |
# File 'lib/chatx/polling.rb', line 26 def kill @dead = true @thread.join end |