Class: Yammer::Resources::User

Inherits:
Base
  • Object
show all
Defined in:
lib/yammer/resources/user.rb

Instance Attribute Summary

Attributes inherited from Base

#attrs, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#api_handler, attr_accessor_deffered, base_name, #base_name, #changes, #delete!, fetch, get, identity_map, #initialize, #load!, #load_deferred_attribute!, #loaded?, model_attributes, #modified?, #new_record?, #persisted?, #reload!, #save, #update

Methods included from ApiHandler

#api_handler, #establish_api_handler

Constructor Details

This class inherits a constructor from Yammer::Resources::Base

Class Method Details

.create(email) ⇒ Object

Creates a new user from email address



28
29
30
31
32
33
# File 'lib/yammer/resources/user.rb', line 28

def self.create(email)
  result = api_handler.create_user(:email => email)
  return nil unless result.created?
  id = result.headers[:location].split('/').last.to_i
  new(:id => id)
end

.currentObject

Returns authenticated user's details



20
21
22
23
24
# File 'lib/yammer/resources/user.rb', line 20

def self.current
  result = api_handler.current_user
  return nil unless result.success?
  new(result.body)
end

Instance Method Details

#emailObject

Returns user's primary email



43
44
45
46
47
48
49
# File 'lib/yammer/resources/user.rb', line 43

def email
  @email ||= begin
    self.contact[:email_addresses].map do |e|
      e[:address] if e[:type] == 'primary'
    end.first
  end
end

#followersObject

Returns all user's follwing this user



57
58
59
# File 'lib/yammer/resources/user.rb', line 57

def followers
  api_handler.users_following(@id)
end

#followingObject

Returns all users that this user is following



52
53
54
# File 'lib/yammer/resources/user.rb', line 52

def following
  api_handler.users_followed_by(@id)
end

#update!(params) ⇒ Object

Updates the user attributes



62
63
64
# File 'lib/yammer/resources/user.rb', line 62

def update!(params)
  api_handler.update_user(@id, params)
end