lita-hcadmin 0.4.5 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc34b2696ab300c6bed1244ed01dc01669cc8c1d
4
- data.tar.gz: 95840dec11fcb76abc0fa97e04404557384dc2f1
3
+ metadata.gz: c178fe6da37330ea589d254a4544da656a00a1d1
4
+ data.tar.gz: 4472c5c8421040c42a286f6ac46353fa68f1fe94
5
5
  SHA512:
6
- metadata.gz: 77fa03c6b253ebc43344c803f928bc53d34d7fe4e03f2ef93a670ed2b179aa05f7999ed2ead110c87a4e2a89d616d3fb04d059e95c184d393a9df512f4c816a6
7
- data.tar.gz: c33814a51cf56658ba0d516c09f6a7a36ca3497110404ebbefb02c8e092d3c315532e51568737c2990d053cfff6226da8a5206b0b02aaf8696db17effbdd23c9
6
+ metadata.gz: 7d65fb91aa31dcae91f67b7e3db1048cba3cfbf31250101a499a38a04964af18529ac49dbfcd664b5b307d9109b9ebfb5660532bca9a34fe96a8851860b757c4
7
+ data.tar.gz: f811402bb564ff1e41336e38e3321320f4d42f69ba8ab2a0349fdbd84b69d1dc4286bd2e258382b7ccd08d735570384f32fae992729ada1ba5da2b19e7a72c06
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # lita-hcadmin
2
2
 
3
+ [0.5.3]
4
+ ---------
5
+ - [desktophero] -
6
+ - Fixed pagination for multiple API requests
7
+
8
+ [0.5.2]
9
+ ---------
10
+ - [desktophero] - not released
11
+ - Modify the HipChat admin pagination from multiple requests to the Get All User API
12
+
13
+ [0.5.1]
14
+ ---------
15
+ - [desktophero] - Not released
16
+ - Modify the HipChat admin return set
17
+
18
+ [0.5.0]
19
+ ---------
20
+ - [desktophero] - Not released
21
+ - Update HipChat admin lookup to V2 API
22
+ - Update applicable tests, including additional fixture for V2 Get Users
23
+ - Remove old tests
24
+
3
25
  [0.4.5]
4
26
  ---------
5
27
  - [desktophero] - Update tests to use `subject` and objects to validate private methods
@@ -148,22 +148,23 @@ module Lita
148
148
  end
149
149
 
150
150
  def identify_hipchat_admins(response)
151
- response.reply 'Admin search takes a moment ...'
152
- admin_message = nil
151
+ response.reply 'Admin search takes about a minute ...'
152
+ @all_admins = []
153
+ batch_count = user_count_api_iterations
154
+
153
155
  time = Benchmark.measure do
154
- parse_users = fetch_users
155
- if parse_users[:status] != 200
156
- admin_message = "I ran into an HTTP error ( HTTP code: #{parse_users[:status]} )"
157
- else
158
- all_users = parse(parse_users[:body], 'users')
159
- all_users.each do |u|
160
- next if u['is_group_admin'] == 0
161
- response.reply u['mention_name']
156
+ (0..batch_count + 1).each do |i|
157
+ i = i * 1000 - 1 unless i == 0 # fun with math!
158
+ response.reply "Checking users ( through #{i})"
159
+ parse_users = fetch_all_users_v2(i)
160
+ return response.reply "Admin list: I ran into an HTTP error ( HTTP code: #{parse_users[:status]} )" if parse_users[:status] != 200
161
+ all_users = parse(parse_users[:body], 'sponsor')
162
+ all_users['items'].each do |u|
163
+ admin_list(u['mention_name']) if u['is_group_admin'] == true
162
164
  end
163
- admin_message = 'complete'
164
165
  end
165
166
  end
166
- response.reply "Admin list: #{admin_message} ( #{time.real.to_i} s. to respond )"
167
+ response.reply "Admin list: #{@all_admins.join(', ')} ( #{time.real.to_i} s. to respond )"
167
168
  end
168
169
 
169
170
  def identify_room_owner(response)
@@ -188,6 +189,8 @@ module Lita
188
189
  json = json['rooms']
189
190
  when 'user'
190
191
  json = json['user']
192
+ when 'items'
193
+ json = json['items']
191
194
  when 'users'
192
195
  json = json['users']
193
196
  when 'status'
@@ -285,6 +288,18 @@ module Lita
285
288
 
286
289
  private
287
290
 
291
+ def user_count_api_iterations
292
+ total_users = fetch_stats
293
+ total_users = parse(total_users[:body], 'users')
294
+ user_count_api_iterations = total_users / 1000
295
+ return 1 if user_count_api_iterations < 1
296
+ user_count_api_iterations
297
+ end
298
+
299
+ def admin_list(admin_mention)
300
+ @all_admins.push admin_mention
301
+ end
302
+
288
303
  def domain_from_email(email)
289
304
  at = email.index('@')
290
305
  email[at..-1]
@@ -374,6 +389,13 @@ module Lita
374
389
  json
375
390
  end
376
391
 
392
+ def fetch_all_users_v2(iteration)
393
+ url = "https://api.hipchat.com/v2/user?expand=items&max-results=1000&start-index=#{iteration}&auth_token=#{v2_admin_token}&format=json&"
394
+ proxy = http_proxy || nil
395
+ json = get url, proxy
396
+ json
397
+ end
398
+
377
399
  def email_domain_name
378
400
  config.email_domain_name
379
401
  end
data/lita-hcadmin.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-hcadmin"
3
- spec.version = "0.4.5"
3
+ spec.version = "0.5.3"
4
4
  spec.authors = ["Jason Walker"]
5
5
  spec.email = ["jason.walker@target.com"]
6
6
  spec.description = "HipChat admin plugin for Lita"
@@ -2,5 +2,5 @@
2
2
  "links": {
3
3
  "self": "https://api.hipchat.com/v2/group/11/statistics"
4
4
  },
5
- "users": 5315
5
+ "users": 900
6
6
  }
@@ -9,6 +9,8 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
9
9
  let(:user_json) { File.read(File.join('spec', 'fixtures', 'user_data.json')) }
10
10
  let(:all_user_json) { File.read(File.join('spec', 'fixtures', 'users_data.json')) }
11
11
  let(:user_v2_json) { File.read(File.join('spec', 'fixtures', 'v2_user_data.json')) }
12
+ let(:all_users_v2_json) { File.read(File.join('spec', 'fixtures', 'user_v2_all_users.json')) }
13
+ let(:all_users_v2_json_no_admins) { File.read(File.join('spec', 'fixtures', 'user_v2_all_users_no_admins.json')) }
12
14
  let(:user_v2_noaccount) { File.read(File.join('spec', 'fixtures', 'user_v2_notreal_email.json')) }
13
15
  let(:user_v2_not_found) { File.read(File.join('spec', 'fixtures', 'v2_user_not_found.json')) }
14
16
  let(:room_v2_not_found) { File.read(File.join('spec', 'fixtures', 'v2_room_not_found.json')) }
@@ -296,6 +298,58 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
296
298
  body: user_v2_json,
297
299
  headers: {}
298
300
  )
301
+
302
+ stub_request(:get, 'https://api.hipchat.com/v2/user?expand=items&auth_token=abc&format=json&max-results=1000&start-index=0')
303
+ .with(
304
+ headers: {
305
+ 'Accept' => 'application/json',
306
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
307
+ 'Content-Type' => 'application/json',
308
+ 'User-Agent' => 'Faraday v0.9.2' })
309
+ .to_return(
310
+ status: 200,
311
+ body: all_users_v2_json,
312
+ headers: {}
313
+ )
314
+
315
+ stub_request(:get, 'https://api.hipchat.com/v2/user?expand=items&auth_token=abc&format=json&max-results=1000&start-index=999')
316
+ .with(
317
+ headers: {
318
+ 'Accept' => 'application/json',
319
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
320
+ 'Content-Type' => 'application/json',
321
+ 'User-Agent' => 'Faraday v0.9.2' })
322
+ .to_return(
323
+ status: 200,
324
+ body: all_users_v2_json_no_admins,
325
+ headers: {}
326
+ )
327
+
328
+ stub_request(:get, 'https://api.hipchat.com/v2/user?expand=items&auth_token=abc&format=json&max-results=1000&start-index=1999')
329
+ .with(
330
+ headers: {
331
+ 'Accept' => 'application/json',
332
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
333
+ 'Content-Type' => 'application/json',
334
+ 'User-Agent' => 'Faraday v0.9.2' })
335
+ .to_return(
336
+ status: 200,
337
+ body: all_users_v2_json_no_admins,
338
+ headers: {}
339
+ )
340
+
341
+ stub_request(:get, 'https://api.hipchat.com/v2/group/171096/statistics?auth_token=abc&format=json')
342
+ .with(
343
+ headers: {
344
+ 'Accept' => 'application/json',
345
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
346
+ 'Content-Type' => 'application/json',
347
+ 'User-Agent' => 'Faraday v0.9.2' })
348
+ .to_return(
349
+ status: 200,
350
+ body: group_stats,
351
+ headers: {}
352
+ )
299
353
  end
300
354
 
301
355
  it 'routes the identify room owner command room name has spaces' do
@@ -389,47 +443,33 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
389
443
 
390
444
  describe '#identify_hipchat_admins' do
391
445
  describe 'successful HTTP request against the API' do
392
- before(:each) do
393
- stub_request(:get, 'https://api.hipchat.com/v1/users/list?auth_token=123&format=json')
394
- .with(
395
- headers: {
396
- 'Accept' => 'application/json',
397
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
398
- 'Content-Type' => 'application/json',
399
- 'User-Agent' => 'Faraday v0.9.2' })
400
- .to_return(
401
- status: 200,
402
- body: all_user_json,
403
- headers: {}
404
- )
405
- end
406
446
  it 'receives a list of admins from a JSON payload' do
407
447
  send_command('identify hipchat admins')
408
- expect(replies.last).to eq('Admin list: complete ( 0 s. to respond )')
448
+ expect(replies.last).to eq('Admin list: DummyAccount, DummyAccount3 ( 0 s. to respond )')
409
449
  end
410
450
  end
411
451
 
412
452
  describe 'handles Bad Gateway errors' do
413
453
  before(:each) do
414
- stub_request(:get, 'https://api.hipchat.com/v1/users/list?auth_token=123&format=json')
454
+ stub_request(:get, 'https://api.hipchat.com/v2/user?expand=items&auth_token=abc&format=json&max-results=1000&start-index=0')
415
455
  .with(headers: { 'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' })
416
456
  .to_return(status: 502, body: bad_gateway, headers: {})
417
457
  end
418
458
  it 'sends a request for admins that fails with a 502 and responds with exception details' do
419
459
  send_command('identify hipchat admins')
420
- expect(replies.last).to eq('Admin list: I ran into an HTTP error ( HTTP code: 502 ) ( 0 s. to respond )')
460
+ expect(replies.last).to eq('Admin list: I ran into an HTTP error ( HTTP code: 502 )')
421
461
  end
422
462
  end
423
463
 
424
464
  describe 'handles non-200 series' do
425
465
  before(:each) do
426
- stub_request(:get, 'https://api.hipchat.com/v1/users/list?auth_token=123&format=json')
466
+ stub_request(:get, 'https://api.hipchat.com/v2/user?expand=items&auth_token=abc&format=json&max-results=1000&start-index=0')
427
467
  .with(headers: { 'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' })
428
468
  .to_return(status: 501, body: bad_gateway, headers: {})
429
469
  end
430
470
  it 'sends a request for admins that fails with a 501 and responds with exception details' do
431
471
  send_command('identify hipchat admins')
432
- expect(replies.last).to eq('Admin list: I ran into an HTTP error ( HTTP code: 501 ) ( 0 s. to respond )')
472
+ expect(replies.last).to eq('Admin list: I ran into an HTTP error ( HTTP code: 501 )')
433
473
  end
434
474
  end
435
475
  end # end identify_hipchat_admins
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-hcadmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-23 00:00:00.000000000 Z
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita