Class: Lifen::Flow
Instance Method Summary collapse
Instance Method Details
#attach_users!(users) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lifen/flow.rb', line 22 def attach_users!(users) users = Array(users) params = users.map(&:uuid).compact.uniq json = client.post("central/api/chats/#{uuid}/attach_users?rel=activeUsers", params) Array(json["activeUsers"]).each do |element| self.active_users << Lifen::User.new(element) end users.each do |user| raise Lifen::Error, "User #{user.uuid} was not attached to this flow" if !active_users.map(&:uuid).include? user.uuid end self end |
#create ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/lifen/flow.rb', line 9 def create json = client.post("central/api/chats", {title: title}) flow = self.class.new(json.first) self.user = user self.uuid = flow.uuid self.active_users = [] self.title = flow.title self end |
#detach_users!(users) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lifen/flow.rb', line 40 def detach_users!(users) users = Array(users) params = users.map(&:uuid).compact.uniq json = client.post("central/api/chats/#{uuid}/detach_users?rel=activeUsers", params) self.active_users = [] Array(json["activeUsers"]).each do |element| self.active_users << Lifen::User.new(element) end users.each do |user| raise Lifen::Error, "User #{user.uuid} was not detached to this flow" if active_users.map(&:uuid).include? user.uuid end self end |