slack-ruby-client 0.5.1 → 0.5.2

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: bddd0a87e5708039190f6426332ea467d989f691
4
- data.tar.gz: 20b28016a329478c0dfcf1ebfb270c33e7c9e5b7
3
+ metadata.gz: 83beab009684f102b815d58a123f2a7dc50975fd
4
+ data.tar.gz: 151c2fc2b883a65ff6eaced3054b2db8e607b599
5
5
  SHA512:
6
- metadata.gz: 617b369a14e5c896000962d3c917ba05d07af9cffdb6c08891ceb389161ff0f5e2de568601e0460ac99bd1fc1cdcaf7ed91cb6ea647797e00600ef9fad348c7b
7
- data.tar.gz: 84bfc168239d0e7699b9f2192a5a1dde2c272a32910cc6867ed8ecb71a0ec83e9d7216a7cef3e3c7f66e67b79b8f5a5e9142f6c1b7a359e205be6e65575d088c
6
+ metadata.gz: 0c584024b15b6f07310702399dea5a0ae82c703821d5a33a447e749ce677bedc0b38d2e01d89ebb983fe14f4819fa2a295ec43ca94372f7b142686255ba660d3
7
+ data.tar.gz: c797d350c47ed7acf6eb942a723cb57ccb79897360677aa12bdece2fbce3298c6bec06139a8f0e3c27602e62e4bcfb2dac4b9f63e81904ba938b191d0cbe8789
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2015-12-06 15:38:34 -0500 using RuboCop version 0.35.0.
3
+ # on 2016-01-08 09:24:26 -0500 using RuboCop version 0.35.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -13,6 +13,13 @@ Lint/HandleExceptions:
13
13
  - 'spec/slack/real_time/concurrency/celluloid_spec.rb'
14
14
  - 'spec/slack/real_time/concurrency/eventmachine_spec.rb'
15
15
 
16
+ # Offense count: 1
17
+ # Cop supports --auto-correct.
18
+ # Configuration parameters: IgnoreEmptyBlocks.
19
+ Lint/UnusedBlockArgument:
20
+ Exclude:
21
+ - 'lib/slack/messages/formatting.rb'
22
+
16
23
  # Offense count: 2
17
24
  Metrics/AbcSize:
18
25
  Max: 20
@@ -22,22 +29,17 @@ Metrics/AbcSize:
22
29
  Metrics/ClassLength:
23
30
  Max: 112
24
31
 
25
- # Offense count: 324
32
+ # Offense count: 380
26
33
  # Configuration parameters: AllowURI, URISchemes.
27
34
  Metrics/LineLength:
28
35
  Max: 288
29
36
 
30
- # Offense count: 3
37
+ # Offense count: 4
31
38
  # Configuration parameters: CountComments.
32
39
  Metrics/MethodLength:
33
40
  Max: 15
34
41
 
35
- # Offense count: 1
36
- Style/AsciiComments:
37
- Exclude:
38
- - 'lib/slack/web/api/endpoints/team.rb'
39
-
40
- # Offense count: 41
42
+ # Offense count: 44
41
43
  # Configuration parameters: Exclude.
42
44
  Style/Documentation:
43
45
  Enabled: false
@@ -48,12 +50,12 @@ Style/FileName:
48
50
  Exclude:
49
51
  - 'lib/slack-ruby-client.rb'
50
52
 
51
- # Offense count: 74
53
+ # Offense count: 85
52
54
  # Configuration parameters: AllowedVariables.
53
55
  Style/GlobalVars:
54
56
  Enabled: false
55
57
 
56
- # Offense count: 11
58
+ # Offense count: 15
57
59
  # Configuration parameters: EnforcedStyle, SupportedStyles.
58
60
  Style/MethodName:
59
61
  Enabled: false
@@ -64,3 +66,9 @@ Style/ModuleFunction:
64
66
  - 'lib/slack/config.rb'
65
67
  - 'lib/slack/real_time/config.rb'
66
68
  - 'lib/slack/web/config.rb'
69
+
70
+ # Offense count: 2
71
+ # Cop supports --auto-correct.
72
+ Style/SpecialGlobalVars:
73
+ Exclude:
74
+ - 'lib/slack/messages/formatting.rb'
data/CHANGELOG.md CHANGED
@@ -1,7 +1,12 @@
1
+ ### 0.5.2 (1/8/2015)
2
+
3
+ * [#41](https://github.com/dblock/slack-ruby-client/issues/41): Added `Slack::Messages::Formatting#unescape` - [@dblock](https://github.com/dblock).
4
+ * Added `files_comments` to Web API - [@dblock](https://github.com/dblock).
5
+
1
6
  ### 0.5.1 (1/4/2016)
2
7
 
3
- * Added `dnd_teamInfo`, `dnd_setSnooze`, `dnd_info`, `dnd_endSnooze` and `dnd_endDnd` - [@dblock](https://github.com/dblock).
4
- * The `files_upload` method now requires both `file` and `filename` - [@dblock](https://github.com/dblock).
8
+ * Added `dnd_teamInfo`, `dnd_setSnooze`, `dnd_info`, `dnd_endSnooze` and `dnd_endDnd` to Web API - [@dblock](https://github.com/dblock).
9
+ * The `files_upload` method now requires both `file` and `filename` to Web API - [@dblock](https://github.com/dblock).
5
10
 
6
11
  ### 0.5.0 (12/7/2015)
7
12
 
data/README.md CHANGED
@@ -18,7 +18,7 @@ A Ruby client for the Slack [Web](https://api.slack.com/web) and [RealTime Messa
18
18
 
19
19
  ## Stable Release
20
20
 
21
- You're reading the documentation for the **stable** release of slack-ruby-client, 0.5.1. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
21
+ You're reading the documentation for the **stable** release of slack-ruby-client, 0.5.2. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
22
22
 
23
23
  ## Installation
24
24
 
@@ -250,7 +250,7 @@ EM.run do
250
250
  end
251
251
  ```
252
252
 
253
- See a fullly working example in [examples/hi_real_time_async](examples/hi_real_time_async/hi.rb).
253
+ See a fully working example in [examples/hi_real_time_async](examples/hi_real_time_async/hi.rb).
254
254
 
255
255
  ##### Faye::Websocket with Eventmachine
256
256
 
@@ -268,6 +268,33 @@ Add the following to your Gemfile.
268
268
  gem 'celluloid-io'
269
269
  ```
270
270
 
271
+ ### Message Parsing
272
+
273
+ All text in Slack uses the same [system of escaping](https://api.slack.com/docs/formatting): chat messages, direct messages, file comments, etc. Use [Slack::Messages::Formatting](lib/slack/messages/formatting.rb) to unescape incoming messages. This comes handy, for example, you want to treat all input to a real time bot as plain text.
274
+
275
+ ```ruby
276
+ Slack::Messages::Formatting.unescape('Hello & <world>'))
277
+ # => 'Hello & <world>'
278
+ Slack::Messages::Formatting.unescape('Hey <@U024BE7LH|bob>, did you see my file?'))
279
+ # => 'Hey @bob, did you see my file?'
280
+ Slack::Messages::Formatting.unescape('Hey <@U02BEFY4U>'))
281
+ # => 'Hey @U02BEFY4U'
282
+ Slack::Messages::Formatting.unescape('This message contains a URL <http://foo.com/>'))
283
+ # => 'This message contains a URL http://foo.com/'
284
+ Slack::Messages::Formatting.unescape('So does this one: <http://www.foo.com|www.foo.com>'))
285
+ # => 'So does this one: www.foo.com'
286
+ Slack::Messages::Formatting.unescape('<mailto:bob@example.com|Bob>'))
287
+ # => 'Bob'
288
+ Slack::Messages::Formatting.unescape('Hello <@U123|bob>, say hi to <!everyone> in <#C1234|general>'))
289
+ # => 'Hello @bob, say hi to @everyone in #general'
290
+ Slack::Messages::Formatting.unescape('Hello <@U123|bob> &gt; file.txt'))
291
+ # => 'Hello @bob > file.txt'
292
+ Slack::Messages::Formatting.unescape('“hello”'))
293
+ # => '"hello"'
294
+ Slack::Messages::Formatting.unescape('‘hello’'))
295
+ # => "'hello'"
296
+ ```
297
+
271
298
  ### Command-Line Client
272
299
 
273
300
  The slack command-line client returns JSON data from the Slack API.
@@ -2,6 +2,17 @@
2
2
 
3
3
  desc 'Get info on files uploaded to Slack, upload new files to Slack.'
4
4
  command 'files' do |g|
5
+ g.desc 'Edit an existing comment on a file. Only the user who created a comment may make edits. Teams may configure a limited time window during which file comment edits are allowed.'
6
+ g.long_desc %( Edit an existing comment on a file. Only the user who created a comment may make edits. Teams may configure a limited time window during which file comment edits are allowed. )
7
+ g.command 'comments' do |c|
8
+ c.flag 'file', desc: 'File containing the comment to edit.'
9
+ c.flag 'id', desc: 'The comment to edit.'
10
+ c.flag 'comment', desc: 'Text of the comment to edit.'
11
+ c.action do |_global_options, options, _args|
12
+ puts JSON.dump($client.files_comments(options))
13
+ end
14
+ end
15
+
5
16
  g.desc 'This method deletes a file from your team.'
6
17
  g.long_desc %( This method deletes a file from your team. )
7
18
  g.command 'delete' do |c|
@@ -1,6 +1,9 @@
1
1
  require 'slack/version'
2
2
  require 'slack/config'
3
3
 
4
+ # Messages
5
+ require 'slack/messages/formatting'
6
+
4
7
  # Web API
5
8
  require 'faraday'
6
9
  require 'faraday_middleware'
@@ -0,0 +1,29 @@
1
+ module Slack
2
+ module Messages
3
+ module Formatting
4
+ class << self
5
+ #
6
+ # Unescape a message.
7
+ # @see https://api.slack.com/docs/formatting
8
+ #
9
+ def unescape(message)
10
+ CGI.unescapeHTML(message.gsub(/[“”]/, '"')
11
+ .gsub(/[‘’]/, "'")
12
+ .gsub(/<(?<sign>[?@#!]?)(?<dt>.*?)>/) do |match|
13
+ sign = $~[:sign]
14
+ dt = $~[:dt]
15
+ rhs = dt.split('|', 2).last
16
+ case sign
17
+ when '@', '!'
18
+ "@#{rhs}"
19
+ when '#'
20
+ "##{rhs}"
21
+ else
22
+ rhs
23
+ end
24
+ end)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/slack/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slack
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
@@ -5,6 +5,24 @@ module Slack
5
5
  module Api
6
6
  module Endpoints
7
7
  module Files
8
+ #
9
+ # Edit an existing comment on a file. Only the user who created a comment may make edits. Teams may configure a limited time window during which file comment edits are allowed.
10
+ #
11
+ # @option options [file] :file
12
+ # File containing the comment to edit.
13
+ # @option options [Object] :id
14
+ # The comment to edit.
15
+ # @option options [Object] :comment
16
+ # Text of the comment to edit.
17
+ # @see https://api.slack.com/methods/files.comments
18
+ # @see https://github.com/dblock/slack-api-ref/blob/master/methods/files.comments.json
19
+ def files_comments(options = {})
20
+ throw ArgumentError.new('Required arguments :file missing') if options[:file].nil?
21
+ throw ArgumentError.new('Required arguments :id missing') if options[:id].nil?
22
+ throw ArgumentError.new('Required arguments :comment missing') if options[:comment].nil?
23
+ post('files.comments', options)
24
+ end
25
+
8
26
  #
9
27
  # This method deletes a file from your team.
10
28
  #
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slack::Messages::Formatting do
4
+ subject do
5
+ Slack::Messages::Formatting
6
+ end
7
+ context '#unescape' do
8
+ it 'plain text' do
9
+ expect(subject.unescape('plain text')).to eq 'plain text'
10
+ end
11
+ it 'decodes an HTML-encoded message' do
12
+ expect(subject.unescape('Hello &amp; &lt;world&gt;')).to eq 'Hello & <world>'
13
+ end
14
+ it 'unescapes a user reference' do
15
+ expect(subject.unescape('Hey <@U024BE7LH|bob>, did you see my file?')).to eq 'Hey @bob, did you see my file?'
16
+ end
17
+ it 'unescapes a user reference without a name' do
18
+ expect(subject.unescape('<@U02BEFY4U> ^^^')).to eq '@U02BEFY4U ^^^'
19
+ end
20
+ it 'unescapes a URL without text' do
21
+ expect(subject.unescape('This message contains a URL <http://foo.com/>')).to eq 'This message contains a URL http://foo.com/'
22
+ end
23
+ it 'unescapes a URL with text' do
24
+ expect(subject.unescape('So does this one: <http://www.foo.com|www.foo.com>')).to eq 'So does this one: www.foo.com'
25
+ end
26
+ it 'removes mailto' do
27
+ expect(subject.unescape('<mailto:bob@example.com|Bob>')).to eq 'Bob'
28
+ end
29
+ it 'unlinkifies references' do
30
+ expect(subject.unescape('Hello <@U123|bob>, say hi to <!everyone> in <#C1234|general>')).to eq 'Hello @bob, say hi to @everyone in #general'
31
+ end
32
+ it 'can handle a lone &gt;' do
33
+ expect(subject.unescape('Hello <@U123|bob> &gt; file.txt')).to eq 'Hello @bob > file.txt'
34
+ end
35
+ it 'unescapes a double smart quote' do
36
+ expect(subject.unescape('“hello”')).to eq '"hello"'
37
+ end
38
+ it 'unescapes a single smart quote' do
39
+ expect(subject.unescape('‘hello’')).to eq "'hello'"
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -1,167 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-04 00:00:00.000000000 Z
11
+ date: 2016-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday_middleware
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: json
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: websocket-driver
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: gli
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: erubis
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: json-schema
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: vcr
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: webmock
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ">="
157
+ - - '>='
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">="
164
+ - - '>='
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
@@ -185,12 +185,12 @@ executables:
185
185
  extensions: []
186
186
  extra_rdoc_files: []
187
187
  files:
188
- - ".gitignore"
189
- - ".gitmodules"
190
- - ".rspec"
191
- - ".rubocop.yml"
192
- - ".rubocop_todo.yml"
193
- - ".travis.yml"
188
+ - .gitignore
189
+ - .gitmodules
190
+ - .rspec
191
+ - .rubocop.yml
192
+ - .rubocop_todo.yml
193
+ - .travis.yml
194
194
  - CHANGELOG.md
195
195
  - CONTRIBUTING.md
196
196
  - Gemfile
@@ -236,6 +236,7 @@ files:
236
236
  - lib/slack-ruby-client.rb
237
237
  - lib/slack.rb
238
238
  - lib/slack/config.rb
239
+ - lib/slack/messages/formatting.rb
239
240
  - lib/slack/real_time/api/message.rb
240
241
  - lib/slack/real_time/api/message_id.rb
241
242
  - lib/slack/real_time/api/ping.rb
@@ -294,6 +295,7 @@ files:
294
295
  - spec/fixtures/slack/web/users_list.yml
295
296
  - spec/integration/integration_spec.rb
296
297
  - spec/slack/config_spec.rb
298
+ - spec/slack/messages/formatting_spec.rb
297
299
  - spec/slack/real_time/api/message_spec.rb
298
300
  - spec/slack/real_time/api/ping_spec.rb
299
301
  - spec/slack/real_time/api/typing_spec.rb
@@ -322,17 +324,17 @@ require_paths:
322
324
  - lib
323
325
  required_ruby_version: !ruby/object:Gem::Requirement
324
326
  requirements:
325
- - - ">="
327
+ - - '>='
326
328
  - !ruby/object:Gem::Version
327
329
  version: '0'
328
330
  required_rubygems_version: !ruby/object:Gem::Requirement
329
331
  requirements:
330
- - - ">="
332
+ - - '>='
331
333
  - !ruby/object:Gem::Version
332
334
  version: 1.3.6
333
335
  requirements: []
334
336
  rubyforge_project:
335
- rubygems_version: 2.4.8
337
+ rubygems_version: 2.4.5
336
338
  signing_key:
337
339
  specification_version: 4
338
340
  summary: Slack Web and RealTime API client.
@@ -344,6 +346,7 @@ test_files:
344
346
  - spec/fixtures/slack/web/users_list.yml
345
347
  - spec/integration/integration_spec.rb
346
348
  - spec/slack/config_spec.rb
349
+ - spec/slack/messages/formatting_spec.rb
347
350
  - spec/slack/real_time/api/message_spec.rb
348
351
  - spec/slack/real_time/api/ping_spec.rb
349
352
  - spec/slack/real_time/api/typing_spec.rb