yammerstats 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/README.rdoc +32 -0
- data/Rakefile +35 -0
- data/VERSION +1 -0
- data/bin/yammerstats +49 -0
- data/examples/data/users.json +12 -0
- data/examples/html/FCF_Column3D.swf +0 -0
- data/examples/html/top_updaters.html +16 -0
- data/examples/templates/top_updaters.erb +6 -0
- data/lib/ext/yammer/client.rb +15 -0
- data/lib/yammer/stats.rb +33 -0
- data/lib/yammerstats.rb +6 -0
- data/spec/rcov.opts +1 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/yammer/stats_spec.rb +55 -0
- metadata +80 -0
data/.gitignore
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= yammerstats
|
2
|
+
|
3
|
+
* http://github.com/pmoran/yammerstats
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
yammerstats is a simple command line tool for fetching data for a Yammer network and presenting it in a useful way. It runs a Yammer query and outputs the results using an ERB template.
|
8
|
+
|
9
|
+
The first usage has been focused on generating 3D column charts using http://www.fusioncharts.com.
|
10
|
+
|
11
|
+
== SYNOPSIS:
|
12
|
+
|
13
|
+
yammerstats uses yammer4r to query a Yammer network. You will need to follow the steps described by yammer4r to register an application and create a credentials config file.
|
14
|
+
|
15
|
+
* gem install yammer4r
|
16
|
+
* ruby yammer4r/bin/yammer_create_oauth_yml.rb (and follow instructions in the script)
|
17
|
+
|
18
|
+
To run a stats request, use:
|
19
|
+
|
20
|
+
yammerstats [options]
|
21
|
+
|
22
|
+
== EXAMPLE USAGE:
|
23
|
+
|
24
|
+
Run the default (and currently only) stat top_updaters, generating an xml file that can be consumed by Fusion Charts
|
25
|
+
yammerstats --config=oauth.yml
|
26
|
+
|
27
|
+
|
28
|
+
== TODO
|
29
|
+
|
30
|
+
* Gemify
|
31
|
+
* Add possibly useful stats
|
32
|
+
* Heat map of user posts - when is a user posting?
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
|
7
|
+
desc "Run all specs"
|
8
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
9
|
+
t.spec_files = FileList['spec/**/*spec.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
Spec::Rake::SpecTask.new("rcov:spec") do |t|
|
13
|
+
t.spec_opts = ['--options', "\"spec/spec.opts\""]
|
14
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
15
|
+
t.rcov = true
|
16
|
+
t.rcov_opts = lambda do
|
17
|
+
IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
begin
|
22
|
+
require 'jeweler'
|
23
|
+
Jeweler::Tasks.new do |gemspec|
|
24
|
+
gemspec.name = "yammerstats"
|
25
|
+
gemspec.summary = "Fetch some (possibly) useful info from your Yammer domain"
|
26
|
+
gemspec.description = "Fetches Yammer information and outputs it to the format of your choice, using Erb templates."
|
27
|
+
gemspec.email = "workingpeter@gmail.com"
|
28
|
+
gemspec.homepage = "http://github.com/pmoran/yammerstats"
|
29
|
+
gemspec.authors = ["Peter Moran"]
|
30
|
+
end
|
31
|
+
rescue LoadError
|
32
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => [:spec]
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/yammerstats
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
4
|
+
|
5
|
+
require 'optparse'
|
6
|
+
require 'yammerstats'
|
7
|
+
|
8
|
+
OPTIONS = {
|
9
|
+
:config => 'oauth.yml',
|
10
|
+
:stat => "top_updaters"
|
11
|
+
}
|
12
|
+
|
13
|
+
ARGV.options do |o|
|
14
|
+
script_name = File.basename($0)
|
15
|
+
|
16
|
+
o.set_summary_indent(' ')
|
17
|
+
o.banner = "Usage: #{script_name} [OPTIONS]"
|
18
|
+
o.define_head "Generate stats for your Yammer network"
|
19
|
+
o.separator ""
|
20
|
+
|
21
|
+
o.on("-c", "--config=val", String, "oauth config file", "Default: #{OPTIONS[:config]}") do |c|
|
22
|
+
OPTIONS[:config] = c
|
23
|
+
end
|
24
|
+
o.on("-s", "--stat=val", String, "Stat to run", "Default: #{OPTIONS[:stat]}") do |s|
|
25
|
+
OPTIONS[:stat] = s
|
26
|
+
end
|
27
|
+
o.on("-t", "--template=val", String, "Erb template file") do |t|
|
28
|
+
OPTIONS[:template] = t
|
29
|
+
end
|
30
|
+
o.on("-o", "--output=val", String, "Output file") do |o|
|
31
|
+
OPTIONS[:output] = o
|
32
|
+
end
|
33
|
+
o.on("-d", "--dump", "Dump results to the screen, rather than an output file") do |d|
|
34
|
+
OPTIONS[:dump] = d
|
35
|
+
end
|
36
|
+
o.on("--stub", "Stub Yammer client for testing purposes") do |s|
|
37
|
+
OPTIONS[:stub] = s
|
38
|
+
end
|
39
|
+
|
40
|
+
o.separator ""
|
41
|
+
|
42
|
+
o.on_tail("-h", "--help", "Show this help message.") { puts o; exit }
|
43
|
+
o.parse!
|
44
|
+
end
|
45
|
+
|
46
|
+
require File.expand_path(File.dirname(__FILE__) + "../../lib/ext/yammer/client") if OPTIONS[:stub]
|
47
|
+
|
48
|
+
stats = Yammer::Stats.new(:config => OPTIONS[:config], :verbose => false)
|
49
|
+
stats.send(OPTIONS[:stat], OPTIONS)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"timezone":"Sydney","interests":null,"type":"user","contact": {"im":{"provider":"aim","username":""},"email_addresses": [{"type":"primary","address":"r.maldon@diuscomputing.com.au"} ],
|
4
|
+
"phone_numbers":[]},"hire_date":null,"location":null,"guid":null,"job_title":"Software Craftsman","network_id":42785,"schools":[],"kids_names":null,"significant_other":null,"web_url":"https://www.yammer.com/diuscomputing.com.au/users/r-maldon","network_domains":["diuscomputing.com.au"],"id":481091,"mugshot_url":"https://assets3.yammer.com/user_uploaded/photos/p1/0044/5440/the-real-shaq_small.jpg","stats":{"updates":21,"following":31,"followers":32},"external_urls":[],
|
5
|
+
"full_name":"THE_REAL_SHAQ","name":"r-maldon","url":"https://www.yammer.com/api/v1/users/481091","expertise":null,"summary":null,"previous_companies":[],"birth_date":"","network_name":"diuscomputing.com.au","state":"active"
|
6
|
+
},
|
7
|
+
{
|
8
|
+
"timezone":"Melbourne","interests":null,"type":"user","contact":{"im":{"provider":"aim","username":""},"email_addresses":[{"type":"primary","address":"w.godfrey@diuscomputing.com.au"}],"phone_numbers":[{"type":"mobile","number":"0408409465"}]},"hire_date":null,"location":null,"guid":null,"job_title":"Developer","network_id":42785,"schools":[],"kids_names":null,"significant_other":null,"web_url":"https://www.yammer.com/diuscomputing.com.au/users/w-godfrey","network_domains":["diuscomputing.com.au"],
|
9
|
+
"id":394365,"mugshot_url":"https://assets3.yammer.com/images/no_photo_small.gif","stats":{"updates":3,"following":27,"followers":38},"external_urls":[],
|
10
|
+
"full_name":"Warner Godfrey","name":"x-godfrey","url":"https://www.yammer.com/api/v1/users/394365","expertise":null,"summary":null,"previous_companies":[],"birth_date":"","network_name":"diuscomputing.com.au","state":"active"
|
11
|
+
}
|
12
|
+
]
|
Binary file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Yammer Stats</title>
|
4
|
+
</head>
|
5
|
+
<body bgcolor="#ffffff">
|
6
|
+
<h2 align="center">Yammer Updates by User</h2>
|
7
|
+
<div align="center">
|
8
|
+
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="800" height="400" >
|
9
|
+
<param name="movie" value="FCF_Column3D.swf" />
|
10
|
+
<param name="FlashVars" value="&dataURL=../data/top_updaters.xml&chartWidth=800&chartHeight=400">
|
11
|
+
<param name="quality" value="high" />
|
12
|
+
<embed src="FCF_Column3D.swf" width="800" height="400" flashVars="&dataURL=../data/top_updaters.xml&chartWidth=800&chartHeight=400" quality="high" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
|
13
|
+
</object>
|
14
|
+
</div>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<% COLOURS = %w(AFD8F8, F6BD0F, 8BBA00, FF8E46, 008E8E, D64646, 8E468E, 588526, B3AA00, 008ED6, 9D080D, A186BE) %>
|
2
|
+
<graph caption='Top Yammer Updaters' xAxisName='Users' yAxisName='Updates' showNames='1' decimalPrecision='0' formatNumberScale='0' rotateNames="1">
|
3
|
+
<% users[0..12].sort_by{|u| u.name }.each_with_index do |user, i| %>
|
4
|
+
<set name='<%= user.name %>' value='<%= user.stats.updates %>' color='<%=COLOURS[i]%>' />
|
5
|
+
<% end %>
|
6
|
+
</graph>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Yammer
|
2
|
+
class Client
|
3
|
+
|
4
|
+
def users(options = {})
|
5
|
+
file = "examples/data/users.json"
|
6
|
+
p ("Yammer::Client stubbed. Reading users from #{file}")
|
7
|
+
s = IO.read(file)
|
8
|
+
JSON.parse(s).map do |u|
|
9
|
+
Yammer::User.new(mash(u), self)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
data/lib/yammer/stats.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Yammer
|
4
|
+
|
5
|
+
class Stats
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
options.merge!(:config => "oauth.yml") unless options[:config]
|
9
|
+
@yammer = Yammer::Client.new(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def top_updaters(options = {})
|
13
|
+
users = @yammer.users(:sort_by => "messages", :reverse => false)
|
14
|
+
if options.delete(:dump) == true
|
15
|
+
users.each {|u| puts "#{u.name} - #{u.stats.updates}" }
|
16
|
+
else
|
17
|
+
template, output_file = options_or_defaults(options)
|
18
|
+
output = ERB.new(IO.read(template), nil, '<>').result(binding)
|
19
|
+
File.open(output_file, 'w') {|f| f.write(output)}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def options_or_defaults(options)
|
26
|
+
template = options.delete(:template) || 'examples/templates/top_updaters.erb'
|
27
|
+
output_file = options.delete(:output) || 'top_updaters.xml'
|
28
|
+
[template, output_file]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/yammerstats.rb
ADDED
data/spec/rcov.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--exclude "spec/*,gems/*"
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
describe Yammer::Stats do
|
5
|
+
|
6
|
+
it "initialises a yammer client" do
|
7
|
+
stats = Yammer::Stats.new
|
8
|
+
stats.instance_variable_get(:@yammer).should_not be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
context "top updaters" do
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
@mock_yammer = mock(Yammer::Client)
|
15
|
+
@mock_yammer.stub!("users").and_return([OpenStruct.new(:name => "foo", :stats => OpenStruct.new(:updates => nil))])
|
16
|
+
Yammer::Client.stub!("new").and_return(@mock_yammer)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can dump results to the screen" do
|
20
|
+
stats = Yammer::Stats.new
|
21
|
+
File.should_not_receive("open")
|
22
|
+
stats.top_updaters(:dump => true)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "with files" do
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
@stats = Yammer::Stats.new
|
29
|
+
mock_erb = mock(ERB)
|
30
|
+
mock_erb.stub!("result")
|
31
|
+
ERB.stub!("new").and_return(mock_erb)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "uses default files if not specified" do
|
35
|
+
IO.should_receive("read").with("examples/templates/top_updaters.erb")
|
36
|
+
File.should_receive("open").with("top_updaters.xml", 'w')
|
37
|
+
@stats.top_updaters
|
38
|
+
end
|
39
|
+
|
40
|
+
it "reads a specified template" do
|
41
|
+
File.stub!("open")
|
42
|
+
IO.should_receive("read").with("foo/bar.erb")
|
43
|
+
@stats.top_updaters(:template => "foo/bar.erb")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "writes to a specified output file" do
|
47
|
+
File.should_receive("open").with("foo/myoutput.file", 'w')
|
48
|
+
@stats.top_updaters(:output => "foo/myoutput.file")
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yammerstats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Moran
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-07 00:00:00 +11:00
|
13
|
+
default_executable: yammerstats
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: yammer4r
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.1.5
|
24
|
+
version:
|
25
|
+
description: Fetches Yammer information and outputs it to the format of your choice, using Erb templates.
|
26
|
+
email: workingpeter@gmail.com
|
27
|
+
executables:
|
28
|
+
- yammerstats
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- README.rdoc
|
36
|
+
- Rakefile
|
37
|
+
- VERSION
|
38
|
+
- bin/yammerstats
|
39
|
+
- examples/data/users.json
|
40
|
+
- examples/html/FCF_Column3D.swf
|
41
|
+
- examples/html/top_updaters.html
|
42
|
+
- examples/templates/top_updaters.erb
|
43
|
+
- lib/ext/yammer/client.rb
|
44
|
+
- lib/yammer/stats.rb
|
45
|
+
- lib/yammerstats.rb
|
46
|
+
- spec/rcov.opts
|
47
|
+
- spec/spec.opts
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
- spec/yammer/stats_spec.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/pmoran/yammerstats
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --charset=UTF-8
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Fetch some (possibly) useful info from your Yammer domain
|
78
|
+
test_files:
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
- spec/yammer/stats_spec.rb
|