Class: Babili::Platform::Message
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Babili::Platform::Message
- Defined in:
- lib/babili/platform/message.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.all_for_room(room_id) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/babili/platform/message.rb', line 8 def self.all_for_room(room_id) create_path = path.gsub(":room_id", room_id) = [] = false = nil while != = if = Babili::Client.get(create_path + "?firstSeenMessageId=#{first_seen_message_id}") else = Babili::Client.get(create_path) end return if ["data"].empty? .concat(["data"].map do || = new(["attributes"]) .id = ["id"] end) = ["data"].first["id"] end end |
.create(params = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/babili/platform/message.rb', line 31 def self.create(params = {}) room_id = params.delete(:room_id) create_path = path.gsub(":room_id", room_id) sender_id = params[:sender_id] || params["sender_id"] formatted_params = { data: { type: "mesage", id: params[:id] || params["id"], relationships: {}, attributes: { content: params[:content] || params["content"], content_type: params[:content_type] || params["content_type"], read_by_user_ids: params[:read_by_user_ids] || params["read_by_user_ids"] } } } if sender_id formatted_params[:data][:relationships][:user] = { data: { id: sender_id } } end = Babili::Client.post(create_path, formatted_params)["data"] = new(["attributes"]) .id = ["id"] .room_id = room_id end |
.path ⇒ Object
4 5 6 |
# File 'lib/babili/platform/message.rb', line 4 def self.path "platform/rooms/:room_id/messages" end |
Instance Method Details
#delete ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/babili/platform/message.rb', line 59 def delete path = self.class.path.gsub(":room_id", room_id) + "/#{id}" = Babili::Client.delete(path)["data"] = self.class.new(["attributes"]) .id = ["id"] end |