File: databasedotcom/chatter/group.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Databasedotcom#4
  module: Chatter#5
  class: Group#7
includes
  PhotoMethods ( Databasedotcom::Chatter )
inherits from
  Record ( Databasedotcom::Chatter )
has properties
class method: members (1/2) / 2 #11
class method: join (1/2) / 3 #23
method: members! #30
method: members (2/E) #35
method: join (2/E) / 1 #40

Class Hierarchy

Object ( Builtin-Module )
Record ( Databasedotcom::Chatter )
  Group    #7

Code

   1  require 'databasedotcom/chatter/record'
   2  require 'databasedotcom/chatter/photo_methods'
   3 
   4  module Databasedotcom
   5    module Chatter
   6      # A group of Users
   7      class Group < Record
   8        include PhotoMethods
   9 
  10        # Returns a Collection of GroupMembership instances for the Group identified by _group_id_.
  11        def self.members(client, group_id)
  12          url = "/services/data/v#{client.version}/chatter/groups/#{group_id}/members"
  13          result = client.http_get(url)
  14          response = JSON.parse(result.body)
  15          collection = Databasedotcom::Collection.new(client, response["totalMemberCount"], response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
  16          response["members"].each do |member|
  17            collection << GroupMembership.new(client, member)
  18          end
  19          collection
  20        end
  21 
  22        # Join the group identified by _group_id_ as the user identified by _user_id_.
  23        def self.join(client, group_id, user_id="me")
  24          url = "/services/data/v#{client.version}/chatter/groups/#{group_id}/members"
  25          response = client.http_post(url, nil, :userId => user_id)
  26          GroupMembership.new(client, response.body)
  27        end
  28 
  29        # Get a Collection of GroupMembership objects for this Group. Always makes a call to the server.
  30        def members!
  31          self.class.members(self.client, self.id)
  32        end
  33 
  34        # Get a Collection of GroupMembership objects for this Group. Returns cached data if it has been called before.
  35        def members
  36          @members ||= members!
  37        end
  38 
  39        # Join this Group as the user identified by _user_id_.
  40        def join(user_id="me")
  41          self.class.join(self.client, self.id, user_id)
  42        end
  43      end
  44    end
  45  en