Module: Firering::Requests

Included in:
Connection
Defined in:
lib/firering/requests.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(&callback) ⇒ Object

Calls /users/me route on campfire to get the authenticated user information, including token



5
6
7
8
9
10
# File 'lib/firering/requests.rb', line 5

def authenticate(&callback)
  user("me") do |user|
    self.token = user.token
    callback.call(user)
  end
end

#room(id, &callback) ⇒ Object

returns a room by id



20
21
22
23
24
# File 'lib/firering/requests.rb', line 20

def room(id, &callback)
  http(:get, "/room/#{id}.json") do |data, http|
    Firering::Room.instantiate(self, data, :room, &callback)
  end
end

#rooms(&callback) ⇒ Object

Returns all rooms. For getting the users, each specific room must be queries with Firering.room multi: if true, gets all the users from each room as Firering::User objects



28
29
30
31
32
33
34
35
36
37
# File 'lib/firering/requests.rb', line 28

def rooms(&callback)
  http(:get, "/rooms.json") do |data, http|
    if data[:rooms]
      callback.call(data[:rooms].map{|room| Firering::Room.instantiate(self, room)}) if callback
    else
      logger.error(http.response)
      callback.call([])
    end
  end
end

#search_messages(query, &callback) ⇒ Object

Returns all the messages containing the supplied term.



40
41
42
43
44
# File 'lib/firering/requests.rb', line 40

def search_messages(query, &callback)
  http(:get, "/search/#{query}.json") do |data, http|
    callback.call(data[:messages].map { |msg| Firering::Message.instantiate(self, msg) }) if callback
  end
end

#star_message(id, yes_or_no = true, &callback) ⇒ Object

Toggles the star next to a message



47
48
49
50
51
# File 'lib/firering/requests.rb', line 47

def star_message(id, yes_or_no = true, &callback)
  http(yes_or_no ? :post : :delete, "/messages/#{id}/star.json") do |data, http|
    callback.call(data) if callback
  end
end

#user(id, &callback) ⇒ Object

returns a user by id



13
14
15
16
17
# File 'lib/firering/requests.rb', line 13

def user(id, &callback)
  http(:get, "/users/#{id}.json") do |data, http|
    Firering::User.instantiate(self, data, :user, &callback)
  end
end