Class: Databasedotcom::Chatter::User

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

Overview

Defines a User in your org.

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

.conversations(client, subject_id) ⇒ Object

Returns a Collection of conversations that belong to the User identified by subject_id.



72
73
74
# File 'lib/databasedotcom/chatter/user.rb', line 72

def self.conversations(client, subject_id)
  Conversation.all(client, :user_id => subject_id)
end

.delete_status(client, subject_id = "me") ⇒ Object

Deletes the status of User identified by subject_id.



61
62
63
# File 'lib/databasedotcom/chatter/user.rb', line 61

def self.delete_status(client, subject_id="me")
  client.http_delete "/services/data/v#{client.version}/chatter/users/#{subject_id}/status"
end

.follow(client, subject_id, resource_id) ⇒ Object

Creates and returns a new Subscription object that represents the User identified by subject_id following the resource identified by resource_id.



66
67
68
69
# File 'lib/databasedotcom/chatter/user.rb', line 66

def self.follow(client, subject_id, resource_id)
  response = client.http_post("/services/data/v#{client.version}/chatter/users/#{subject_id}/following", nil, :subjectId => resource_id)
  Subscription.new(client, response.body)
end

.followers(client, subject_id = "me") ⇒ Object

Returns a Collection of Subscription objects that represents all followers of the User identified by subject_id.



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

def self.followers(client, subject_id="me")
  url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/followers"
  result = client.http_get(url)
  response = JSON.parse(result.body)
  collection = Databasedotcom::Collection.new(client, response["total"], response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
  response["followers"].each do |subscription|
    collection << Subscription.new(client, subscription)
  end
  collection
end

.following(client, subject_id = "me") ⇒ Object

Returns a Collection of Subscription objects that represent all entities that the User identified by subject_id is following.



23
24
25
26
27
28
29
30
31
32
# File 'lib/databasedotcom/chatter/user.rb', line 23

def self.following(client, subject_id="me")
  url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/following"
  result = client.http_get(url)
  response = JSON.parse(result.body)
  collection = Databasedotcom::Collection.new(client, response["total"], response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
  response["following"].each do |subscription|
    collection << Subscription.new(client, subscription)
  end
  collection
end

.groups(client, subject_id = "me") ⇒ Object

Returns a Collection of Group objects that represent all the groups that the User identified by subject_id is a part of.



35
36
37
38
39
40
41
42
43
44
# File 'lib/databasedotcom/chatter/user.rb', line 35

def self.groups(client, subject_id="me")
  url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/groups"
  result = client.http_get(url)
  response = JSON.parse(result.body)
  collection = Databasedotcom::Collection.new(client, response["total"], response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
  response["groups"].each do |group|
    collection << Group.new(client, group)
  end
  collection
end

.messages(client, subject_id) ⇒ Object

Returns a Collection of private messages that belong to the User identified by subject_id.



77
78
79
# File 'lib/databasedotcom/chatter/user.rb', line 77

def self.messages(client, subject_id)
  Message.all(client, :user_id => subject_id)
end

.post_status(client, subject_id, text) ⇒ Object

Posts a status update as the User identified by subject_id with content text.



54
55
56
57
58
# File 'lib/databasedotcom/chatter/user.rb', line 54

def self.post_status(client, subject_id, text)
  url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/status"
  result = client.http_post(url, nil, :text => text)
  JSON.parse(result.body)
end

.status(client, subject_id = "me") ⇒ Object

Returns the current status of the User identified by subject_id.



47
48
49
50
51
# File 'lib/databasedotcom/chatter/user.rb', line 47

def self.status(client, subject_id="me")
  url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/status"
  result = client.http_get(url)
  JSON.parse(result.body)
end

Instance Method Details

#conversationsObject

Get a Collection of Conversation objects that represents the conversations for this User. Returns cached data if it has been called before.



138
139
140
# File 'lib/databasedotcom/chatter/user.rb', line 138

def conversations
  @conversations ||= conversations!
end

#conversations!Object

Get a Collection of Conversation objects that represents the conversations for this User. Always makes a call to the server.



133
134
135
# File 'lib/databasedotcom/chatter/user.rb', line 133

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

#delete_statusObject

Deletes the current status of this User. Returns the deleted status.



112
113
114
115
# File 'lib/databasedotcom/chatter/user.rb', line 112

def delete_status
  self.class.delete_status(self.client, self.id)
  status
end

#follow(record_id) ⇒ Object

Creates a new Subscription that represents this User following the resource with id record_id.



128
129
130
# File 'lib/databasedotcom/chatter/user.rb', line 128

def follow(record_id)
  self.class.follow(self.client, self.id, record_id)
end

#followersObject

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



87
88
89
# File 'lib/databasedotcom/chatter/user.rb', line 87

def followers
  @followers ||= followers!
end

#followers!Object

Get a Collection of Subscription objects for this User. Always makes a call to the server.



82
83
84
# File 'lib/databasedotcom/chatter/user.rb', line 82

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

#followingObject

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
98
99
# File 'lib/databasedotcom/chatter/user.rb', line 97

def following
  @following ||= following!
end

#following!Object

Get a Collection of Subscription objects that represents all resources that this User is following. Always makes a call to the server.



92
93
94
# File 'lib/databasedotcom/chatter/user.rb', line 92

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

#groupsObject

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
124
125
# File 'lib/databasedotcom/chatter/user.rb', line 123

def groups
  @groups ||= groups!
end

#groups!Object

Get a Collection of Group objects that represents all groups that this User is in. Always makes a call to the server.



118
119
120
# File 'lib/databasedotcom/chatter/user.rb', line 118

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

#messagesObject

Get a Collection of Message objects that represents the messages for this User. Returns cached data if it has been called before.



148
149
150
# File 'lib/databasedotcom/chatter/user.rb', line 148

def messages
  @messages ||= messages!
end

#messages!Object

Get a Collection of Message objects that represents the messages for this User. Always makes a call to the server.



143
144
145
# File 'lib/databasedotcom/chatter/user.rb', line 143

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

#post_status(text) ⇒ Object

Posts a new status with content text for this User.



107
108
109
# File 'lib/databasedotcom/chatter/user.rb', line 107

def post_status(text)
  self.class.post_status(self.client, self.id, text)
end

#statusObject

Returns this current status of this User.



102
103
104
# File 'lib/databasedotcom/chatter/user.rb', line 102

def status
  self.raw_hash["currentStatus"]
end