lolcommits-yammer 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3378d5ec0c2ad9ee8e6d941f9446161b73abd3e4
4
- data.tar.gz: 1a1c1ccbc0c6b8454eb4c16a2eba222a836fcc0f
3
+ metadata.gz: c08eaf8175131baf2871fcd4970104c45955bd1b
4
+ data.tar.gz: edcb63a618c579c0079104e265b3d8bfdccf5336
5
5
  SHA512:
6
- metadata.gz: 80a60dd1ad84e9ec146bf41e6fa03e67189f4e88d8aa594e16e4f76978017046147c696a289052bfa1544dbde27700c6f774328ab21df8aa4bfddcb9e1110d06
7
- data.tar.gz: ec383a1ba1c2c9680ca7bc513c147cdc8237617999c564a59ab4ead02fb7bc725f8de822feb14d0de6c9556264ba9c9eff89c13c4d61bfe539604ca00f28f3c1
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
- YAMMER_CLIENT_ID = 'abbxXRgeSagk9GtiWW9rFw'.freeze
14
- YAMMER_CLIENT_SECRET = 'gHVw5Ekyy2mWOWsBzrZPs5EPnR6s04RibApcbuy10'.freeze
15
- YAMMER_ACCESS_TOKEN_URL = 'https://www.yammer.com/oauth2/access_token.json'.freeze
16
- OAUTH_REDIRECT_PORT = 5429
17
- OAUTH_REDIRECT_URL = "http://localhost:#{OAUTH_REDIRECT_PORT}".freeze
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 = yammer.create_message(
82
- yammer_message, attachment1: File.new(runner.main_image)
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
- debug response.body.inspect
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
- oauth_response = Net::HTTP.post_form(URI(YAMMER_ACCESS_TOKEN_URL), {
131
- 'client_id' => YAMMER_CLIENT_ID,
132
- 'client_secret' => YAMMER_CLIENT_SECRET,
133
- 'code' => @oauth_code
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=#{YAMMER_CLIENT_ID}&response_type=code&redirect_uri=#{OAUTH_REDIRECT_URL}"
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)
@@ -1,5 +1,5 @@
1
1
  module Lolcommits
2
2
  module Yammer
3
- VERSION = "0.0.2".freeze
3
+ VERSION = "0.0.3".freeze
4
4
  end
5
5
  end
@@ -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 "yam"
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
- 'Accept' => 'application/json',
75
- 'Accept-Encoding' => 'gzip, deflate',
76
- 'Authorization' => 'Bearer oV4MuwnNKql3ebJMAYZRaD',
77
- 'Content-Type' => /multipart\/form-data/,
78
- 'User-Agent' => /Yammer Ruby Gem/
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: Invalid response code (503)",
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::YAMMER_ACCESS_TOKEN_URL).with(
139
+ stub_request(:post, klass::ACCESS_TOKEN_URL).with(
141
140
  body: {
142
- "client_id" => klass::YAMMER_CLIENT_ID,
143
- "client_secret" => klass::YAMMER_CLIENT_SECRET,
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
- "https://www.yammer.com/api/v1/messages"
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.2
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-10 00:00:00.000000000 Z
11
+ date: 2017-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: yam
14
+ name: rest-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="