lolcommits-yammer 0.0.2 → 0.0.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.
- checksums.yaml +4 -4
- data/lib/lolcommits/plugin/yammer.rb +21 -28
- data/lib/lolcommits/yammer/version.rb +1 -1
- data/lolcommits-yammer.gemspec +1 -1
- data/test/lolcommits/plugin/yammer_test.rb +11 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c08eaf8175131baf2871fcd4970104c45955bd1b
|
4
|
+
data.tar.gz: edcb63a618c579c0079104e265b3d8bfdccf5336
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fe5007c65c62d3d85d28b34580ab997f654610b170cab6a712ec584dfcd7f2e21ccae1b4f64368772894658099ecdc7cc12b5d7358b4fe272b0abc2c88ee916
|
7
|
+
data.tar.gz: 2f62b1962d901bbca44ff073da351212fa8fd75302448a5539af72d962d0b4f9b254ccae6b183628c13d114c353b48bccb426245c890889ad6cc0f3aa89db1fc
|
@@ -1,20 +1,19 @@
|
|
1
1
|
require 'lolcommits/plugin/base'
|
2
2
|
require 'lolcommits/cli/launcher'
|
3
|
-
require 'net/http'
|
4
|
-
require 'uri'
|
5
3
|
require 'webrick'
|
4
|
+
require 'rest-client'
|
6
5
|
require 'cgi'
|
7
|
-
require 'yammer'
|
8
6
|
|
9
7
|
module Lolcommits
|
10
8
|
module Plugin
|
11
9
|
class Yammer < Base
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
MESSAGES_API_URL = "https://www.yammer.com/api/v1/messages".freeze
|
12
|
+
ACCESS_TOKEN_URL = 'https://www.yammer.com/oauth2/access_token.json'.freeze
|
13
|
+
OAUTH_CLIENT_ID = 'abbxXRgeSagk9GtiWW9rFw'.freeze
|
14
|
+
OAUTH_CLIENT_SECRET = 'gHVw5Ekyy2mWOWsBzrZPs5EPnR6s04RibApcbuy10'.freeze
|
15
|
+
OAUTH_REDIRECT_PORT = 5429
|
16
|
+
OAUTH_REDIRECT_URL = "http://localhost:#{OAUTH_REDIRECT_PORT}".freeze
|
18
17
|
|
19
18
|
##
|
20
19
|
# Returns the name of the plugin.
|
@@ -78,11 +77,14 @@ module Lolcommits
|
|
78
77
|
#
|
79
78
|
def run_capture_ready
|
80
79
|
print "Posting to Yammer ... "
|
81
|
-
response =
|
82
|
-
|
80
|
+
response = RestClient.post(
|
81
|
+
"https://www.yammer.com/api/v1/messages",
|
82
|
+
{ body: yammer_message, attachment1: File.new(runner.main_image) },
|
83
|
+
{ 'Authorization' => "Bearer #{configuration["access_token"]}" }
|
83
84
|
)
|
84
|
-
|
85
|
+
|
85
86
|
if response.code != 201
|
87
|
+
debug response.body.inspect
|
86
88
|
raise "Invalid response code (#{response.code})"
|
87
89
|
end
|
88
90
|
|
@@ -98,16 +100,6 @@ module Lolcommits
|
|
98
100
|
|
99
101
|
private
|
100
102
|
|
101
|
-
def yammer
|
102
|
-
@yammer ||= begin
|
103
|
-
::Yammer.configure do |c|
|
104
|
-
c.client_id = YAMMER_CLIENT_ID
|
105
|
-
c.client_secret = YAMMER_CLIENT_SECRET
|
106
|
-
end
|
107
|
-
::Yammer::Client.new(access_token: configuration['access_token'])
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
103
|
def yammer_message
|
112
104
|
"#{runner.message} #lolcommits"
|
113
105
|
end
|
@@ -126,12 +118,13 @@ module Lolcommits
|
|
126
118
|
|
127
119
|
if @oauth_code
|
128
120
|
debug "Requesting Yammer OAuth Token with code: #{@oauth_code}"
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
121
|
+
oauth_response = RestClient.post(ACCESS_TOKEN_URL,
|
122
|
+
{
|
123
|
+
'client_id' => OAUTH_CLIENT_ID,
|
124
|
+
'client_secret' => OAUTH_CLIENT_SECRET,
|
125
|
+
'code' => @oauth_code
|
126
|
+
}
|
127
|
+
)
|
135
128
|
|
136
129
|
if oauth_response.code.to_i == 200
|
137
130
|
return JSON.parse(oauth_response.body)['access_token']['token']
|
@@ -144,7 +137,7 @@ module Lolcommits
|
|
144
137
|
end
|
145
138
|
|
146
139
|
def authorize_url
|
147
|
-
"https://www.yammer.com/oauth2/authorize?client_id=#{
|
140
|
+
"https://www.yammer.com/oauth2/authorize?client_id=#{OAUTH_CLIENT_ID}&response_type=code&redirect_uri=#{OAUTH_REDIRECT_URL}"
|
148
141
|
end
|
149
142
|
|
150
143
|
def open_url(url)
|
data/lolcommits-yammer.gemspec
CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
|
36
36
|
spec.required_ruby_version = ">= 2.0.0"
|
37
37
|
|
38
|
-
spec.add_runtime_dependency "
|
38
|
+
spec.add_runtime_dependency "rest-client"
|
39
39
|
spec.add_runtime_dependency "webrick"
|
40
40
|
|
41
41
|
spec.add_development_dependency "lolcommits", ">= 0.9.5"
|
@@ -71,12 +71,11 @@ describe Lolcommits::Plugin::Yammer do
|
|
71
71
|
|
72
72
|
output.must_equal "Posting to Yammer ... done!\n"
|
73
73
|
assert_requested :post, create_message_api_url, times: 1, headers: {
|
74
|
-
'
|
75
|
-
'
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
}
|
74
|
+
'Authorization' => 'Bearer oV4MuwnNKql3ebJMAYZRaD',
|
75
|
+
'Content-Type' => /multipart\/form-data/
|
76
|
+
} do |req|
|
77
|
+
req.body.must_match(/Content-Disposition: form-data;.+name="attachment1"; filename="main_image.jpg.+"/)
|
78
|
+
end
|
80
79
|
end
|
81
80
|
end
|
82
81
|
|
@@ -88,7 +87,7 @@ describe Lolcommits::Plugin::Yammer do
|
|
88
87
|
output.split("\n").must_equal(
|
89
88
|
[
|
90
89
|
"Posting to Yammer ... failed :(",
|
91
|
-
"Yammer error:
|
90
|
+
"Yammer error: 503 Service Unavailable",
|
92
91
|
"Try a lolcommits capture with `--debug` and check for errors: `lolcommits -c --debug`"
|
93
92
|
]
|
94
93
|
)
|
@@ -137,11 +136,11 @@ describe Lolcommits::Plugin::Yammer do
|
|
137
136
|
yammer_oauth_code = "yam-oauth-code"
|
138
137
|
klass = plugin.class
|
139
138
|
|
140
|
-
stub_request(:post, klass::
|
139
|
+
stub_request(:post, klass::ACCESS_TOKEN_URL).with(
|
141
140
|
body: {
|
142
|
-
"client_id" => klass::
|
143
|
-
"client_secret" => klass::
|
144
|
-
"code" => yammer_oauth_code
|
141
|
+
"client_id" => klass::OAUTH_CLIENT_ID,
|
142
|
+
"client_secret" => klass::OAUTH_CLIENT_SECRET,
|
143
|
+
"code" => [yammer_oauth_code]
|
145
144
|
}
|
146
145
|
).to_return(
|
147
146
|
status: 200,
|
@@ -170,7 +169,7 @@ describe Lolcommits::Plugin::Yammer do
|
|
170
169
|
private
|
171
170
|
|
172
171
|
def create_message_api_url
|
173
|
-
|
172
|
+
plugin.class::MESSAGES_API_URL
|
174
173
|
end
|
175
174
|
|
176
175
|
# fake click for the authorize step in Yammer, by hitting local webrick server
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lolcommits-yammer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Hutchinson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rest-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|