Class: Flamethrower::Campfire::Connection

Inherits:
Object
  • Object
show all
Includes:
RestApi
Defined in:
lib/flamethrower/campfire/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RestApi

#campfire_get, #campfire_post, #campfire_put, #host

Constructor Details

#initialize(domain, token, connection) ⇒ Connection

Returns a new instance of Connection.



8
9
10
11
12
# File 'lib/flamethrower/campfire/connection.rb', line 8

def initialize(domain, token, connection)
  @domain = domain
  @token = token
  @connection = connection
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



4
5
6
# File 'lib/flamethrower/campfire/connection.rb', line 4

def domain
  @domain
end

#tokenObject (readonly)

Returns the value of attribute token.



4
5
6
# File 'lib/flamethrower/campfire/connection.rb', line 4

def token
  @token
end

Instance Method Details

#fetch_my_userObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/flamethrower/campfire/connection.rb', line 14

def fetch_my_user
  http = campfire_get("/users/me.json")
  http.callback do
    case http.response_header.status
    when 200
      json = JSON.parse(http.response)
      old_user = @connection.current_user.nickname
      new_user = Flamethrower::Campfire::User.new(json['user']).to_irc
      @connection.current_user = new_user
      @connection.send_rename(old_user, new_user.nickname)
    end
  end
end

#fetch_roomsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/flamethrower/campfire/connection.rb', line 28

def fetch_rooms
  http = campfire_get("/rooms.json")
  http.callback do
    case http.response_header.status
    when 200
      rooms = Array.new
      json = JSON.parse(http.response)
      json['rooms'].each do |room|
        rooms << Room.new(@domain, @token, room).tap do |r|
          r.connection = @connection
        end
      end
      @connection.irc_channels = rooms.map(&:to_irc)
      @connection.send_channel_list
    else
      ::FLAMETHROWER_LOGGER.debug http.response
    end
  end
end