Class: Babili::Platform::Room
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Babili::Platform::Room
- Defined in:
- lib/babili/platform/room.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.all ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/babili/platform/room.rb', line 8 def self.all rooms = [] previous_first_seen_room_id = false first_seen_room_id = nil while previous_first_seen_room_id != first_seen_room_id previous_first_seen_room_id = first_seen_room_id if first_seen_room_id raw_rooms = Babili::Client.get(path + "?firstSeenRoomId=#{first_seen_room_id}") else raw_rooms = Babili::Client.get(path) end return rooms if raw_rooms["data"].empty? rooms.concat(raw_rooms["data"].map do |raw_room| room = new(raw_room["attributes"]) room.id = raw_room["id"] room.users = raw_room["relationships"]["users"]["data"].map do |raw_user| user = Babili::Platform::User.new({id: raw_user["id"]}) user end room end) first_seen_room_id = raw_rooms["data"].last["id"] end end |
.create(params = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/babili/platform/room.rb', line 34 def self.create(params = {}) user_ids = params[:user_ids] || params["user_ids"] formatted_params = { data: { id: params[:id] || params["id"], attributes: { name: params[:name] || params["name"] }, relationships: { users: {} } } } if user_ids formatted_params[:data][:relationships][:users][:data] = user_ids.map do |user_id| { id: user_id } end end raw_room = Babili::Client.post(path, formatted_params)["data"] room = new(raw_room["attributes"]) room.id = raw_room["id"] room end |
.path ⇒ Object
4 5 6 |
# File 'lib/babili/platform/room.rb', line 4 def self.path "platform/rooms" end |
.retreive(room_id) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/babili/platform/room.rb', line 58 def self.retreive(room_id) retreive_path = path + "/#{room_id}" raw_room = Babili::Client.get(retreive_path)["data"] room = new(raw_room["attributes"]) room.id = raw_room["id"] room end |
Instance Method Details
#delete ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/babili/platform/room.rb', line 70 def delete path = self.class.path + "/#{id}" raw_room = Babili::Client.delete(path)["data"] room = self.class.new(raw_room["attributes"]) room.id = raw_room["id"] room end |
#messages ⇒ Object
66 67 68 |
# File 'lib/babili/platform/room.rb', line 66 def Babili::Platform::Message.all_for_room(self.id) end |