From 732dbe5cf23cf60f7b0d0114f6c96cd477c151a7 Mon Sep 17 00:00:00 2001 From: yann ARMAND Date: Wed, 13 Jun 2012 17:21:49 -0700 Subject: [PATCH] Reverse example to original behavior. Add explanations through comments to activate example for TokenClient and new gem features. --- example.rb | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/example.rb b/example.rb index 907a041..20f0264 100644 --- a/example.rb +++ b/example.rb @@ -1,28 +1,34 @@ require 'yammer4r' config_path = File.dirname(__FILE__) + '/oauth.yml' -# yammer = Yammer::OAuthClient.new(:config => config_path) -yammer = Yammer::TokenClient.new(:token => "d2wBYkJrgspivfpmJgu1VQ") +yammer = Yammer::OAuthClient.new(:config => config_path) +## comment previous line and uncomment next to try Token based client. +# You have to set the token. you can find it in your file oauth.yml or use on given by a 3rd party oauth2 tool +# yammer = Yammer::TokenClient.new(:token => "d2wBYkJrgspivfpmJgu1VQ") # Get all messages -# messages = yammer.messages -# puts messages.size -# puts messages.last.body.plain -# puts messages.last.body.parsed +messages = yammer.messages +puts messages.size +puts messages.last.body.plain +puts messages.last.body.parsed # Print out all the users -#yammer.users.each do |u| -# puts "#{u.name} - #{u.me?}" -#end - -topic=Yammer::Topic.find_by_name("Yaflow",yammer) -parsed_all = JSON.parse(yammer.raw_request("messages/about_topic/#{topic.id}").body) unless topic.nil? -msg_with_attach = parsed_all["messages"].select{|m| !m["attachments"].empty? } -pages_json = [] -msg_with_attach.each do |m| - m["attachments"].each do |a| - pages_json = pages_json.push(a["real_id"]) if a["real_type"] == "page" - end +yammer.users.each do |u| + puts "#{u.name} - #{u.me?}" end -puts pages_json +# a more complex example to find all pages attached to message from a given topic. +# note the usage of raw_request +# +### uncomment following lines to test it ### +#topic=Yammer::Topic.find_by_name("a_topic",yammer) +#parsed_all = JSON.parse(yammer.raw_request("messages/about_topic/#{topic.id}").body) unless topic.nil? +#msg_with_attach = parsed_all["messages"].select{|m| !m["attachments"].empty? } +#pages_json = [] +#msg_with_attach.each do |m| +# m["attachments"].each do |a| +# pages_json = pages_json.push(a["real_id"]) if a["real_type"] == "page" +# end +#end +#puts pages_json +#############################################