lita-debug-queue 0.2.0 → 0.3.0

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: 13062639eb8ef466d93d44bc1421d2d8a6643cd5
4
- data.tar.gz: 3349600d80156d2c2df971fc0c61b8bd32ed18a1
3
+ metadata.gz: 81cb7c42ab50cfb2dcc68a79f3f12e506e96b3f4
4
+ data.tar.gz: f1601cff61d894a7c979bb1a23f9cf25f94ec80e
5
5
  SHA512:
6
- metadata.gz: e6f8d5c8fe8c84d6d18e3e15e135358e23238bf350e6e3f78471e30b1046500c18d8a97dc80e3b32262c7f0c6d8f5702bd3721b6bfbb24abd67243199ad7030b
7
- data.tar.gz: 2c15f5ced824dc95a2d0e246422ba3118ce7f848b3170a980d3ace919afd27d1b8ea098a62a1d60221d0ec9a25b5459fc68532f5c003e554d9e04ba8c79bfb3a
6
+ metadata.gz: eceb98b633cbec29a8f09224eb37cf8c7d343f6599a4356338b4459d15dad7c01be5132a5d02b024b0c20f7ea27f952e06366bb9ee2ccc2c794fbe3414b6ffc9
7
+ data.tar.gz: 09e2794ffbe2964b58d9ec370baab6af3857ad4fcea7bd5e6911ee37729c46874666c920f70a15afcb56571885b2aca8e14d074aaf7328b1a54b339c9c7b023a
data/NEWS.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## News
2
2
 
3
+ ### 0.3.0 (2016-02-21)
4
+
5
+ * The main addition is an API for administrators to interact with the queue.
6
+ The API is on by default and is *NOT* designed to be secure, only requiring an API key,
7
+ so it is recommended for most users to stick with version 0.2.0 for the time being.
8
+ The API methods available are documented in the README.
9
+
3
10
  ### 0.2.0 (2015-10-18)
4
11
 
5
12
  * Restrict users adding themselves to the queue
data/README.md CHANGED
@@ -15,17 +15,20 @@ gem "lita-debug-queue"
15
15
 
16
16
  ## Configuration
17
17
 
18
- lita-debug-queue expects three things to be present for correct operation:
18
+ lita-debug-queue expects four things to be present for correct operation:
19
19
 
20
20
  1. An `:instructors` authorization group containing admin users.
21
21
  If you want TAs to also be able to modify (but not clear) the
22
22
  queue you should add them to an `:assistants` group.
23
23
 
24
- 2. A `classrooms` config option containing a Hash that maps instructor mention nam es to classroom channels.
24
+ 2. A `debug_queue.classrooms` config option containing a Hash that maps instructor mention nam es to classroom channels.
25
25
 
26
- 3. A `schedule` config option containing a Hash that maps from days of the week
26
+ 3. A `debug_queue.schedule` config option containing a Hash that maps from days of the week
27
27
  (as from `DateTime.now.strftime("%a")`), to ranges of hours in the
28
28
  [server's time zone][heroku-tz].
29
+
30
+ 4. A `debug_api.passphrase` config option which is just a static string. A way to disable the API
31
+ will be available in a future release.
29
32
 
30
33
  [heroku-tz]: http://blog.pardner.com/2012/08/setting-the-default-time-zone-for-a-heroku-app/
31
34
 
@@ -43,3 +46,33 @@ lita-debug-queue expects three things to be present for correct operation:
43
46
  * `debug next` - Notify the next student to be helped.
44
47
  * `debug drop NAME` - Remove the student with NAME from the queue.
45
48
  * `debug clear` - Empty the queue.
49
+
50
+ ### API
51
+
52
+ Better docs coming soon. ... Ish.
53
+
54
+ ### General Conventions
55
+
56
+ *AUTH*: Every request to the API must include a Query Param `?passphrase=FOO`. Check with your local debug queue admin.``
57
+
58
+ In the event that an invalid room is supplied or incorrect authorization is provided,
59
+ a JSON object containing an `error` key will be returned.
60
+ All correct API requests will result in a response with `queue` and `message` keys.
61
+
62
+ #### Retrieve the Queue for a Class
63
+
64
+ `GET /api/:classroom/queue`
65
+
66
+ #### Pop the Next Debugee
67
+
68
+ `PUT /api/:classroom/queue`
69
+
70
+ #### Drop a specific Debugee
71
+
72
+ `DELETE /api/:classroom/drop`
73
+
74
+ *PARAMS:* Drop requires a `student` query param with the mention name of the student to be removed from the queue.
75
+
76
+ #### Clear the Queue
77
+
78
+ `DELETE /api/:classroom/clear`
@@ -7,6 +7,7 @@ Lita.load_locales Dir[File.expand_path(
7
7
  require "lita/handlers/room_finder"
8
8
  require "lita/handlers/room_queue"
9
9
  require "lita/handlers/debug_queue"
10
+ require "lita/handlers/debug_api"
10
11
 
11
12
  Lita::Handlers::DebugQueue.template_root File.expand_path(
12
13
  File.join("..", "..", "templates"),
@@ -0,0 +1,102 @@
1
+ module Lita
2
+ module Handlers
3
+ class DebugApi
4
+ extend Lita::Handler::HTTPRouter
5
+
6
+ config :passphrase # The worst auth strategy.
7
+
8
+ http.get "api/:classroom/queue", :show
9
+ http.put "api/:classroom/next", :next
10
+ http.delete "api/:classroom/drop", :drop
11
+ http.delete "api/:classroom/clear", :clear
12
+
13
+ def show(request, response)
14
+ return unless validate!(request, response)
15
+ result = { queue: @room.queue }
16
+ response.write(MultiJson.dump(result))
17
+ end
18
+
19
+ def next(request, response)
20
+ return unless validate!(request, response)
21
+ if @room.count.zero?
22
+ result = {
23
+ queue: @room.queue,
24
+ message: "The queue is empty. :beer:?"
25
+ }
26
+ else
27
+ student = @room.next
28
+ send_message(student, "@#{student}: You're up. Let's debug :allthethings:!")
29
+ result = {
30
+ queue: @room.queue,
31
+ message: "#{student} is up next and has been notified."
32
+ }
33
+ end
34
+ response.write(MultiJson.dump(result))
35
+ end
36
+
37
+ def clear(request, response)
38
+ return unless validate!(request, response)
39
+ @room.clear!
40
+ result = { queue: @room.queue, message: "So much for that. :control_knobs:" }
41
+ response.write(MultiJson.dump(result))
42
+ end
43
+
44
+ def drop(request, response)
45
+ return unless validate!(request, response)
46
+ params = request.env["router.params"]
47
+ student = request.params["student"]
48
+
49
+ if @room.include?(student)
50
+ @room.remove(student)
51
+ result = { queue: @room.queue, message: "#{student} has been removed." }
52
+ else
53
+ result = { queue: @room.queue, message: "#{student} isn't in the queue!" }
54
+ end
55
+ response.write(MultiJson.dump(result))
56
+ end
57
+
58
+ private
59
+
60
+ ## NOTES: These private methods are a tangle of stateful filth.
61
+ ## This is out of an attempt at DRYness since we need to return
62
+ ## JSON everywhere and I lack a nice error handling mechanism
63
+ ## like rescue_from. (See: response.headers, response.write)
64
+
65
+ def validate!(request, response)
66
+ response.headers["Content-Type"] = "application/json"
67
+ passphrase_check!(request.params, response)
68
+ room_check!(request.env, response)
69
+ @room
70
+ end
71
+
72
+ def passphrase_check!(params, response)
73
+ authenticated = params["passphrase"] == config.passphrase
74
+ result = { error: "Passphrase must be supplied correctly to use API." }
75
+ response.write(MultiJson.dump(result)) unless authenticated
76
+ end
77
+
78
+ def room_check!(env, response)
79
+ name = env["router.params"][:classroom]
80
+ if valid_room?(name)
81
+ redis.namespace = "handlers:debug_queue"
82
+ @room = RoomQueue.new(name, redis)
83
+ else
84
+ result = { error: "Couldn't find Slack channel '#{name}'" }
85
+ response.write(MultiJson.dump(result))
86
+ end
87
+ end
88
+
89
+ def valid_room?(name)
90
+ rooms = robot.config.handlers.debug_queue.classrooms
91
+ rooms.has_value?(name)
92
+ end
93
+
94
+ def send_message(username, message)
95
+ user = Lita::User.find_by_mention_name(username)
96
+ robot.send_message(user, message)
97
+ end
98
+ end
99
+
100
+ Lita.register_handler(DebugApi)
101
+ end
102
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-debug-queue"
3
- spec.version = "0.2.0"
3
+ spec.version = "0.3.0"
4
4
  spec.authors = ["Brit Butler"]
5
5
  spec.email = ["brit@kingcons.io"]
6
6
  spec.description = "Queue tracking of users who need debugging help with per-channel management"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-debug-queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brit Butler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-19 00:00:00.000000000 Z
11
+ date: 2016-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -109,6 +109,7 @@ files:
109
109
  - README.md
110
110
  - Rakefile
111
111
  - lib/lita-debug-queue.rb
112
+ - lib/lita/handlers/debug_api.rb
112
113
  - lib/lita/handlers/debug_queue.rb
113
114
  - lib/lita/handlers/room_finder.rb
114
115
  - lib/lita/handlers/room_queue.rb