scsi 0.1.0 → 0.2.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: 72b52c20daefb5e48f29ea7a3669f062b9f2bb7d
4
- data.tar.gz: fdcfa0bf71e203f47be2204880242811dedefa6c
3
+ metadata.gz: 5c69377469572b51abb3d920f71f343e4531596b
4
+ data.tar.gz: 2188f305be3d6fcaa7883d743f18622d35cde308
5
5
  SHA512:
6
- metadata.gz: 65e4ee49682f37fdd0d15ea7890c80cb4981944b23142b54df3903ad77c22da92545e6db664e5a9d86ce801ad25501c324db21190454bab12b627b63f97aee25
7
- data.tar.gz: 5e0acb79d339383eee13ef48d1d3e64c43e5698ef9f6814b314ae1d8fd1556398d26d2bc0cbc6ef0bf3b161818d3f806b484d1d97a2e78f03a917c8a3fb6c496
6
+ metadata.gz: fa7ab4a897d6ac810ba967165fa098848b2208f47486f1a5f3baa95bf9c77dbd55d255f3d6a6c5334c2645ebe4706666e6bdb6593bb25f6f1c3487f532659bbf
7
+ data.tar.gz: 222c0f4bdfc6f19713b998638ddb4a1d12ef512b55d943ae90f9cfa63c5837ff45385bb587111f33ecf8677b56630a4070f2191fee91c65b6848dbdfa0d8242d
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # scsi
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/scsi.svg)](https://badge.fury.io/rb/scsi) [![Code Climate](https://codeclimate.com/github/propelfuels/scsi/badges/gpa.svg)](https://codeclimate.com/github/propelfuels/scsi) [![security](https://hakiri.io/github/propelfuels/scsi/master.svg)](https://hakiri.io/github/propelfuels/scsi/master)
4
+
3
5
  A Ruby server for receiving Slack Slash Command and responding with Slack info.
4
6
 
5
7
  ## Requirements
@@ -41,7 +43,7 @@ end
41
43
 
42
44
  ### Run
43
45
 
44
- In Slack, add a [Slash Command](https://my.slack.com/apps/A0F82E8CA-slash-commands) configuration. Set the URL to wherever you're exposing the SCSI server at. (Hint: setup an SSL front; Slack requires your server to talk HTTPS. E.g., NGINX reverse proxy, [Cloudflare](https://www.cloudflare.com/ssl/).)
46
+ In Slack, add a [Slash Command](https://my.slack.com/apps/A0F82E8CA-slash-commands) configuration. Set the URL to wherever you're exposing the SCSI server at. (Hint: setup an SSL front; Slack requires your server to talk HTTPS. E.g., NGINX reverse proxy, [Cloudflare](https://www.cloudflare.com/ssl/).) Also, turn on the "Escape channels, users, and links" setting.
45
47
 
46
48
  The minimum to start the SCSI server:
47
49
 
data/lib/scsi/helper.rb CHANGED
@@ -7,9 +7,9 @@ module SCSI
7
7
 
8
8
  def slash_keys
9
9
  return [
10
- :user_name, :user_id,
11
- :channel_name, :channel_id,
12
- :team_domain, :team_id
10
+ :user_id, :user_name,
11
+ :channel_id, :channel_name,
12
+ :team_id, :team_domain
13
13
  ]
14
14
  end
15
15
 
@@ -17,24 +17,57 @@ module SCSI
17
17
  return nil unless params.class == Hash
18
18
  info = {}
19
19
  slash_keys.each { |k| info[k] = params[k] }
20
+ info[:text] = params[:text]
20
21
  return info
21
22
  end
22
23
 
23
- def format_info(info)
24
+ def create_attachments(data:, keys:)
24
25
  attachments = []
25
26
  i = 0
26
- while i < slash_keys.count do
27
- a = slash_keys[i]
28
- b = slash_keys[i + 1]
27
+ while i < keys.count do
28
+ a = keys[i]
29
+ b = keys[i + 1]
29
30
  attachments << {fields: [
30
- {title: a, value: info[a], short: true},
31
- {title: b, value: info[b], short: true}
31
+ {title: a, value: data[a], short: true},
32
+ {title: b, value: data[b], short: true}
32
33
  ]}
33
34
  i += 2
34
35
  end
36
+ return attachments
37
+ end
38
+
39
+ def attachments_from_text(text)
40
+ attachments = []
41
+ text.scan(/<(.*?)>/) do |m|
42
+ case m[0][0]
43
+ when '#'
44
+ keys = [:channel_id, :channel_name]
45
+ when '@'
46
+ keys = [:user_id, :user_name]
47
+ when '!'
48
+ keys = [:special_command, :label]
49
+ else
50
+ keys = [:link, :label]
51
+ end
52
+ values = m[0].split('|')
53
+ data = {keys[0] => values[0][1..-1], keys[1] => values[1]}
54
+ attachments << create_attachments(data: data, keys: keys)[0]
55
+ end
56
+ return attachments
57
+ end
58
+
59
+ def format_info(info)
60
+ attachments = []
61
+ q = ''
62
+ attachments = attachments_from_text(info[:text]) if info[:text]
63
+ if attachments.empty?
64
+ attachments = create_attachments(data: info, keys: slash_keys)
65
+ else
66
+ q = " ?>> `#{info[:text]}`"
67
+ end
35
68
  return {
36
69
  response_type: "ephemeral",
37
- text: "SCSI: Slash Command Slack Info v#{SCSI::Version}",
70
+ text: "SCSI: Slash Command Slack Info v#{SCSI::Version}" + q,
38
71
  attachments: attachments
39
72
  }
40
73
  end
data/lib/scsi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module SCSI
2
2
 
3
- Version = '0.1.0'
3
+ Version = '0.2.0'
4
4
 
5
5
  end
data/scsi.gemspec CHANGED
@@ -16,6 +16,8 @@ Gem::Specification.new do |s|
16
16
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  s.require_paths = ['lib']
18
18
 
19
+ s.required_ruby_version = '>= 2.1'
20
+
19
21
  s.add_runtime_dependency 'kajiki', '~> 1.1'
20
22
  s.add_runtime_dependency 'sinatra', '~> 1.4'
21
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scsi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-02 00:00:00.000000000 Z
11
+ date: 2017-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kajiki
@@ -69,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: '0'
72
+ version: '2.1'
73
73
  required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - ">="