Class: Yammer::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yammer/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/yammer/client.rb', line 3

def initialize(options={})
  options.assert_has_keys(:consumer, :access) unless options.has_key?(:config)
  
  yammer_url = options.delete(:yammer_host) || "https://www.yammer.com"
  @api_path   = "/api/v1/"

  if options[:config]
    config              = YAML.load(open(options[:config]))
    options[:consumer]  = config['consumer'].symbolize_keys
    options[:access]    = config['access'].symbolize_keys
  end

  consumer = OAuth::Consumer.new(options[:consumer][:key], options[:consumer][:secret], :site => yammer_url)
  consumer.http.set_debug_output($stderr) if options[:verbose] == true
  @access_token = OAuth::AccessToken.new(consumer, options[:access][:token], options[:access][:secret])
end

Instance Method Details

#current_userObject Also known as: me



51
52
53
54
# File 'lib/yammer/client.rb', line 51

def current_user
  u = JSON.parse(yammer_request(:get, {:resource => :users, :action => :current}).body)
  Yammer::User.new(mash(u), self)
end

#message(action, params) ⇒ Object

POST or DELETE a message



36
37
38
39
# File 'lib/yammer/client.rb', line 36

def message(action, params)
  params.merge!(:resource => :messages)
  yammer_request(action, params)
end

#messages(action = :all, params = {}) ⇒ Object

TODO: modularize message and user handling



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/yammer/client.rb', line 22

def messages(action = :all, params = {})
  params.merge!(:resource => :messages)
  params.merge!(:action => action) unless action == :all

  parsed_response = JSON.parse(yammer_request(:get, params).body)
  older_available = parsed_response['meta']['older_available']

  ml = parsed_response['messages'].map do |m|
     mash(m)
  end
  Yammer::MessageList.new(ml, older_available, self)
end

#user(id) ⇒ Object



46
47
48
49
# File 'lib/yammer/client.rb', line 46

def user(id)
  u = JSON.parse(yammer_request(:get, {:resource => :users, :id => id}).body)
  Yammer::User.new(mash(u), self)
end

#users(params = {}) ⇒ Object



41
42
43
44
# File 'lib/yammer/client.rb', line 41

def users(params = {})
  params.merge!(:resource => :users)
  JSON.parse(yammer_request(:get, params).body).map { |u| Yammer::User.new(mash(u), self) }
end