yammer-cli 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  *.gem
2
2
  config.yml
3
3
  Gemfile.lock
4
+ .ruby-version
5
+ .ruby-gemset
data/README.md CHANGED
@@ -10,13 +10,13 @@ Installation
10
10
 
11
11
  Usage
12
12
  -----
13
- yammer -s (Setup oAuth parameters)
13
+ yammer -s consumer_token,consumer_secret (Setup oAuth parameters)
14
14
 
15
15
  yammer -u "Yammer from the command line is so much quicker!" (post update)
16
16
 
17
- yammer -l (list last 20 updates)
17
+ yammer -g group_id (post update in a group)
18
18
 
19
- Right now you'll have to manually configure your OAuth token and secret in the source code.
19
+ yammer -l (list last 20 updates)
20
20
 
21
21
  TODO
22
22
  ----
data/bin/yammer CHANGED
@@ -4,6 +4,7 @@ require 'optparse'
4
4
  require 'yammer-cli'
5
5
 
6
6
  options = {}
7
+ params = {}
7
8
 
8
9
  optparse = OptionParser.new do|opts|
9
10
  opts.banner = "Usage: yammer [options] ..."
@@ -13,14 +14,22 @@ optparse = OptionParser.new do|opts|
13
14
  options[:update] = true
14
15
  end
15
16
 
17
+ options[:group] = false
18
+ opts.on( '-g, id', Integer, 'Groupe id to post on' ) do |id|
19
+ options[:group] = true
20
+ params[:group_id] = id
21
+ end
22
+
16
23
  options[:list] = false
17
24
  opts.on( '-l', '--list', 'Get the last 20 updates' ) do
18
25
  options[:list] = true
19
26
  end
20
27
 
21
28
  options[:setup] = false
22
- opts.on( '-s', '--setup', 'Setup OAuth authentication to Yammer' ) do
29
+ opts.on( '-s', '--setup consumer_token,consumer_secret', Array, 'Setup OAuth authentication to Yammer' ) do |setup|
23
30
  options[:setup] = true
31
+ options[:consumer_token] = setup[0]
32
+ options[:consumer_secret] = setup[1]
24
33
  end
25
34
 
26
35
  opts.on( '-h', '--help', 'Display this screen' ) do
@@ -32,13 +41,12 @@ end
32
41
  #parse command line arguments and remove parsed flags from ARGV
33
42
  optparse.parse!
34
43
 
35
-
36
- if options[:update]
44
+ if options[:update] or options[:group]
37
45
  yammer = YammerCli.new
38
- yammer.send_update(ARGV.join(' '))
46
+ yammer.send_update(ARGV.join(' '), params)
39
47
  elsif options[:list]
40
48
  yammer = YammerCli.new
41
49
  yammer.list
42
50
  elsif options[:setup]
43
- YammerCli.setup
51
+ YammerCli.setup(options[:consumer_token], options[:consumer_secret])
44
52
  end
data/lib/yammer-cli.rb CHANGED
@@ -8,10 +8,7 @@ require 'yaml'
8
8
  class YammerCli
9
9
 
10
10
  #attr_accessor :yammer
11
-
12
- CONSUMER_TOKEN = 'mWn3PY7sc2znsuZxEMvNUQ'
13
- CONSUMER_SECRET = 'AGP2akBsMwybb1AoGBp7RdLc4vfb2l3NY4P6VM'
14
-
11
+
15
12
  def self.new
16
13
  super
17
14
  end
@@ -29,8 +26,8 @@ class YammerCli
29
26
 
30
27
  #configure the yammer authentication parameters
31
28
  Yammer.configure do |config|
32
- config.consumer_key = CONSUMER_TOKEN
33
- config.consumer_secret = CONSUMER_SECRET
29
+ config.consumer_key = settings[:consumer_token]
30
+ config.consumer_secret = settings[:consumer_secret]
34
31
  config.oauth_token = settings[:oauth_token]
35
32
  config.oauth_token_secret = settings[:oauth_secret]
36
33
  end
@@ -40,9 +37,9 @@ class YammerCli
40
37
 
41
38
  end
42
39
 
43
- def send_update(update)
40
+ def send_update(update, params)
44
41
  puts "Sending update to Yammer: #{update}"
45
- @yammer.update(update)
42
+ @yammer.update(update, params)
46
43
  end
47
44
 
48
45
  def list
@@ -51,18 +48,28 @@ class YammerCli
51
48
  #parse out user objects from references
52
49
  users = messages[:references].select {|f| f[:type] == 'user' }
53
50
 
51
+ current_date = ""
52
+
54
53
  #parse each message and look up user names from users array
55
54
  messages[:messages].each do |message|
56
55
  body = message[:body][:plain]
57
- created_at = DateTime.parse(message[:created_at]).to_time.getlocal.strftime("%I:%M%p")
56
+ created_at = DateTime.parse(message[:created_at])
57
+ date = get_date(created_at.to_date)
58
58
  user = get_user(users, message[:sender_id])[:full_name]
59
- puts user.foreground(:red) + " at " + created_at.foreground(:blue) + " " + body
59
+
60
+ # write out current date
61
+ if date != current_date
62
+ puts " --- #{date} ---".foreground(:yellow)
63
+ current_date = date
64
+ end
65
+
66
+ puts user.foreground(:red) + " at " + created_at.strftime("%I:%M%p").foreground(:blue) + " " + body
60
67
  end
61
68
  end
62
69
 
63
- def self.setup
64
- consumer=OAuth::Consumer.new CONSUMER_TOKEN,
65
- CONSUMER_SECRET,
70
+ def self.setup(consumer_token, consumer_secret)
71
+ consumer=OAuth::Consumer.new consumer_token,
72
+ consumer_secret,
66
73
  {:site=>"https://www.yammer.com"}
67
74
 
68
75
  request_token=consumer.get_request_token
@@ -74,7 +81,7 @@ class YammerCli
74
81
 
75
82
  access_token = request_token.get_access_token(:oauth_verifier => pin)
76
83
 
77
- tokens = {:oauth_token => access_token.token, :oauth_secret => access_token.secret}
84
+ tokens = {:oauth_token => access_token.token, :oauth_secret => access_token.secret, :consumer_token => consumer_token, :consumer_secret => consumer_secret}
78
85
 
79
86
  settings_path = File.dirname(__FILE__) + '/config.yml'
80
87
 
@@ -93,5 +100,10 @@ class YammerCli
93
100
  user.first
94
101
  end
95
102
 
103
+ # return either Today or formatted date
104
+ def get_date(date)
105
+ date == Date.today ? "Today" : date.strftime("%A, %B %e %Y")
106
+ end
107
+
96
108
 
97
109
  end
data/yammer-cli.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "yammer-cli"
3
- gem.version = "0.2.2"
3
+ gem.version = "0.2.3"
4
4
  gem.authors = ["Joe Wright"]
5
5
  gem.email = ["joe.wright@noventech.com"]
6
6
  gem.description = "A yammer command line client."
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: yammer-cli
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.2
5
+ version: 0.2.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Joe Wright
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-11-02 00:00:00 Z
13
+ date: 2013-04-30 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: yammer