Class: Databasedotcom::Chatter::Group

Inherits:
Record
  • Object
show all
Includes:
PhotoMethods
Defined in:
lib/databasedotcom/chatter/group.rb

Overview

A group of Users

Instance Attribute Summary

Attributes inherited from Record

#client, #id, #name, #raw_hash, #type, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PhotoMethods

#delete_photo, included, #photo, #upload_photo

Methods inherited from Record

all, delete, #delete, find, #initialize, #parent, #reload, resource_name, search, #user

Constructor Details

This class inherits a constructor from Databasedotcom::Chatter::Record

Class Method Details

.join(client, group_id, user_id = "me") ⇒ Object

Join the group identified by group_id as the user identified by user_id.



23
24
25
26
27
# File 'lib/databasedotcom/chatter/group.rb', line 23

def self.join(client, group_id, user_id="me")
  url = "/services/data/v#{client.version}/chatter/groups/#{group_id}/members"
  response = client.http_post(url, nil, :userId => user_id)
  GroupMembership.new(client, response.body)
end

.members(client, group_id) ⇒ Object

Returns a Collection of GroupMembership instances for the Group identified by group_id.



11
12
13
14
15
16
17
18
19
20
# File 'lib/databasedotcom/chatter/group.rb', line 11

def self.members(client, group_id)
  url = "/services/data/v#{client.version}/chatter/groups/#{group_id}/members"
  result = client.http_get(url)
  response = JSON.parse(result.body)
  collection = Databasedotcom::Collection.new(client, response["totalMemberCount"], response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
  response["members"].each do |member|
    collection << GroupMembership.new(client, member)
  end
  collection
end

Instance Method Details

#join(user_id = "me") ⇒ Object

Join this Group as the user identified by user_id.



40
41
42
# File 'lib/databasedotcom/chatter/group.rb', line 40

def join(user_id="me")
  self.class.join(self.client, self.id, user_id)
end

#membersObject

Get a Collection of GroupMembership objects for this Group. Returns cached data if it has been called before.



35
36
37
# File 'lib/databasedotcom/chatter/group.rb', line 35

def members
  @members ||= members!
end

#members!Object

Get a Collection of GroupMembership objects for this Group. Always makes a call to the server.



30
31
32
# File 'lib/databasedotcom/chatter/group.rb', line 30

def members!
  self.class.members(self.client, self.id)
end