File: databasedotcom/chatter/user.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Databasedotcom#4
  module: Chatter#5
  class: User#7
includes
  PhotoMethods ( Databasedotcom::Chatter )
inherits from
  Record ( Databasedotcom::Chatter )
has properties
class method: followers (1/2) / 2 #11
class method: following (1/2) / 2 #23
class method: groups (1/2) / 2 #35
class method: status (1/2) / 2 #47
class method: post_status (1/2) / 3 #54
class method: delete_status (1/2) / 2 #61
class method: follow (1/2) / 3 #66
class method: conversations (1/2) / 2 #72
class method: messages (1/2) / 2 #77
method: followers! #82
method: followers (2/E) #87
method: following! #92
method: following (2/E) #97
method: status (2/E) #102
method: post_status (2/E) / 1 #107
method: delete_status (2/E) #112
method: groups! #118
method: groups (2/E) #123
method: follow (2/E) / 1 #128
method: conversations! #133
method: conversations (2/E) #138
method: messages! #143
method: messages (2/E) #148

Class Hierarchy

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

Code

   1  require 'databasedotcom/chatter/record'
   2  require 'databasedotcom/chatter/photo_methods'
   3 
   4  module Databasedotcom
   5    module Chatter
   6      # Defines a User in your org.
   7      class User < Record
   8        include PhotoMethods
   9 
  10        # Returns a Collection of Subscription objects that represents all followers of the User identified by _subject_id_.
  11        def self.followers(client, subject_id="me")
  12          url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/followers"
  13          result = client.http_get(url)
  14          response = JSON.parse(result.body)
  15          collection = Databasedotcom::Collection.new(client, response["total"], response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
  16          response["followers"].each do |subscription|
  17            collection << Subscription.new(client, subscription)
  18          end
  19          collection
  20        end
  21 
  22        # Returns a Collection of Subscription objects that represent all entities that the User identified by _subject_id_ is following.
  23        def self.following(client, subject_id="me")
  24          url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/following"
  25          result = client.http_get(url)
  26          response = JSON.parse(result.body)
  27          collection = Databasedotcom::Collection.new(client, response["total"], response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
  28          response["following"].each do |subscription|
  29            collection << Subscription.new(client, subscription)
  30          end
  31          collection
  32        end
  33 
  34        # Returns a Collection of Group objects that represent all the groups that the User identified by _subject_id_ is a part of.
  35        def self.groups(client, subject_id="me")
  36          url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/groups"
  37          result = client.http_get(url)
  38          response = JSON.parse(result.body)
  39          collection = Databasedotcom::Collection.new(client, response["total"], response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
  40          response["groups"].each do |group|
  41            collection << Group.new(client, group)
  42          end
  43          collection
  44        end
  45 
  46        # Returns the current status of the User identified by _subject_id_.
  47        def self.status(client, subject_id="me")
  48          url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/status"
  49          result = client.http_get(url)
  50          JSON.parse(result.body)
  51        end
  52 
  53        # Posts a status update as the User identified by _subject_id_ with content _text_.
  54        def self.post_status(client, subject_id, text)
  55          url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/status"
  56          result = client.http_post(url, nil, :text => text)
  57          JSON.parse(result.body)
  58        end
  59 
  60        # Deletes the status of User identified by _subject_id_.
  61        def self.delete_status(client, subject_id="me")
  62          client.http_delete "/services/data/v#{client.version}/chatter/users/#{subject_id}/status"
  63        end
  64 
  65        # Creates and returns a new Subscription object that represents the User identified by _subject_id_ following the resource identified by _resource_id_.
  66        def self.follow(client, subject_id, resource_id)
  67          response = client.http_post("/services/data/v#{client.version}/chatter/users/#{subject_id}/following", nil, :subjectId => resource_id)
  68          Subscription.new(client, response.body)
  69        end
  70 
  71        # Returns a Collection of conversations that belong to the User identified by _subject_id_.
  72        def self.conversations(client, subject_id)
  73          Conversation.all(client, :user_id => subject_id)
  74        end
  75 
  76        # Returns a Collection of private messages that belong to the User identified by _subject_id_.
  77        def self.messages(client, subject_id)
  78          Message.all(client, :user_id => subject_id)
  79        end
  80 
  81        # Get a Collection of Subscription objects for this User. Always makes a call to the server.
  82        def followers!
  83          self.class.followers(self.client, self.id)
  84        end
  85 
  86        # Get a Collection of Subscription objects for this User. Returns cached data if it has been called before.
  87        def followers
  88          @followers ||= followers!
  89        end
  90 
  91        # Get a Collection of Subscription objects that represents all resources that this User is following. Always makes a call to the server.
  92        def following!
  93          self.class.following(self.client, self.id)
  94        end
  95 
  96        # Get a Collection of Subscription objects that represents all resources that this User is following. Returns cached data if it has been called before.
  97        def following
  98          @following ||= following!
  99        end
 100 
 101        # Returns this current status of this User.
 102        def status
 103          self.raw_hash["currentStatus"]
 104        end
 105 
 106        # Posts a new status with content _text_ for this User.
 107        def post_status(text)
 108          self.class.post_status(self.client, self.id, text)
 109        end
 110 
 111        # Deletes the current status of this User. Returns the deleted status.
 112        def delete_status
 113          self.class.delete_status(self.client, self.id)
 114          status
 115        end
 116 
 117        # Get a Collection of Group objects that represents all groups that this User is in. Always makes a call to the server.
 118        def groups!
 119          self.class.groups(self.client, self.id)
 120        end
 121 
 122        # Get a Collection of Group objects that represents all groups that this User is in. Returns cached data if it has been called before.
 123        def groups
 124          @groups ||= groups!
 125        end
 126 
 127        # Creates a new Subscription that represents this User following the resource with id _record_id_.
 128        def follow(record_id)
 129          self.class.follow(self.client, self.id, record_id)
 130        end
 131 
 132        # Get a Collection of Conversation objects that represents the conversations for this User. Always makes a call to the server.
 133        def conversations!
 134          self.class.conversations(self.client, self.id)
 135        end
 136 
 137        # Get a Collection of Conversation objects that represents the conversations for this User. Returns cached data if it has been called before.
 138        def conversations
 139          @conversations ||= conversations!
 140        end
 141 
 142        # Get a Collection of Message objects that represents the messages for this User. Always makes a call to the server.
 143        def messages!
 144          self.class.messages(self.client, self.id)
 145        end
 146 
 147        # Get a Collection of Message objects that represents the messages for this User. Returns cached data if it has been called before.
 148        def messages
 149          @messages ||= messages!
 150        end
 151      end
 152    end
 153  en