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 |
# 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 end) first_seen_room_id = raw_rooms["data"].last["id"] end end |
.create(params = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/babili/platform/room.rb', line 30 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 |
Instance Method Details
#delete ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/babili/platform/room.rb', line 62 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 |
#users ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/babili/platform/room.rb', line 70 def users path = self.class.path + "/#{id}/users" raw_users = Babili::Client.get(path) raw_users["data"].map do |raw_user| user = Babili::Platform::User.new(raw_user["attributes"]) user.id = raw_user["id"] user end end |