class Channel
Public Class Methods
default_attributes()
click to toggle source
# File lib/mattermost/models/channel.rb, line 102 def self.default_attributes {:display_name => String, :team_id => String, :type => Integer, :purpose => String} end
Public Instance Methods
add_member(user)
click to toggle source
Add a user to a channel Send a user object or a user_id
# File lib/mattermost/models/channel.rb, line 67 def add_member(user) user_id = user.is_a? User ? user.id : user Mattermost.post("/channels/#{self.id}/add", :body => {:user_id => user_id}) end
Also aliased as: add_user
delete()
click to toggle source
Delete a channel
# File lib/mattermost/models/channel.rb, line 12 def delete Mattermost.post("/channels/#{self.id}/delete") end
Also aliased as: destroy
get_channel_extra_info(member_limit = nil)
click to toggle source
Get the users in a channel
# File lib/mattermost/models/channel.rb, line 38 def get_channel_extra_info(member_limit = nil) uri = "/channels/#{self.id}/extra_info" uri += "/#{member_limit}" if member_limit request = Mattermost.get(uri) response = {} response['id'] = request.parsed_response['id'] response['member_count'] = request.parsed_response['member_count'] response['members'] = [] request.parsed_response['members'].each do |user| response['members'] << User.new(user) end response end
Also aliased as: users
info()
click to toggle source
Get channel info
# File lib/mattermost/models/channel.rb, line 18 def info Mattermost.get("/channels/#{self.id}/") end
join()
click to toggle source
Join the channel with your authenticated user If you're looking to add a user to a channel, see add_member
# File lib/mattermost/models/channel.rb, line 55 def join Mattermost.post("/channels/#{self.id}/join") end
leave()
click to toggle source
Leave the channel with your authenticated user If you're looking to remove a user from a channel, see remove_member
# File lib/mattermost/models/channel.rb, line 61 def leave Mattermost.post("/channels/#{self.id}/leave") end
name()
click to toggle source
# File lib/mattermost/models/channel.rb, line 7 def name @name ||= self.display_name.gsub(" ", '-') end
posts(before = nil)
click to toggle source
Returns posts for the channel before a given post.id
@param before [string] to get posts before a given post id
# File lib/mattermost/models/channel.rb, line 25 def posts(before = nil) uri = "/channels/#{self.id}/posts" uri += "/#{before}" if before uri += "/0/60?_=#{Time.now.to_i}" request = Mattermost.get("/channels/#{self.id}/posts/0/60?_=#{Time.now.to_i}") response = {} request.parsed_response['posts'].each do |_, post| response[k] = Post.new(post) end response end
remove_member(user)
click to toggle source
Add a user to a channel Send a user object or a user_id
# File lib/mattermost/models/channel.rb, line 75 def remove_member(user) user_id = user.is_a? User ? user.id : user Mattermost.post("/channels/#{self.id}/remove", :body => {:user_id => user_id}) end
Also aliased as: remove_user
save()
click to toggle source
# File lib/mattermost/models/channel.rb, line 3 def save defined?(self.id) ? update : create_channel end
update_attributes(attributes = {})
click to toggle source
# File lib/mattermost/models/channel.rb, line 85 def update_attributes(attributes = {}) raise NotImplementedError Mattermost.post("/channels/update") end
update_header(header)
click to toggle source
Update the channel's header. I really hate that they have a specific method for this.
# File lib/mattermost/models/channel.rb, line 92 def update_header(header) Mattermost.post("/teams/#{Mattermost.team.id}/channels/#{self.id}/update_header", :body => {:channel_id => self.id, :channel_header => header}.to_json) end
update_last_viewed_at()
click to toggle source
# File lib/mattermost/models/channel.rb, line 81 def update_last_viewed_at Mattermost.post("/channels/#{self.id}/update_last_viewed_at") end
update_purpose(purpose)
click to toggle source
Update the channel's purpose. I really hate that they have a specific method for this.
# File lib/mattermost/models/channel.rb, line 98 def update_purpose(purpose) Mattermost.post("/teams/#{Mattermost.team.id}/channels/#{self.id}/update_purpose", :body => {:channel_id => self.id, :channel_purpose => purpose}.to_json) end
Protected Instance Methods
create_channel()
click to toggle source
# File lib/mattermost/models/channel.rb, line 107 def create_channel Mattermost.post("/channels/create", :body => { :display_name => self.display_name, :name => self.name, :team_id => Mattermost::Team.id, :purpose => self.purpose, :type => self.type }.to_json) end