slacks 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slacks/connection.rb +10 -4
- data/lib/slacks/errors.rb +9 -0
- data/lib/slacks/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c24545abd2bab75c557ad4699e423a2a8bd504e
|
4
|
+
data.tar.gz: 3e5c5fe08361695315dff88a9c72f304453801f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19adcd7bb6445da7e853792c835e282bae16e1967636b589dee43a3eb72825ce419168ec353891deac42367b68d003a516ab6b8b8d008a0b1331897a92a6e001
|
7
|
+
data.tar.gz: 5ea7f3cc21d0aac9d7378c092e13de7632722eb0382fedf333cfcdaae1a59b20b8792c04b08521d81a9911772be29df038bb3c2f120be8a130d9c9ba41f68d52
|
data/lib/slacks/connection.rb
CHANGED
@@ -43,6 +43,8 @@ module Slacks
|
|
43
43
|
params.merge!(options.select { |key, _| [:username, :as_user, :parse, :link_names,
|
44
44
|
:unfurl_links, :unfurl_media, :icon_url, :icon_emoji].member?(key) })
|
45
45
|
api("chat.postMessage", params)
|
46
|
+
rescue Slacks::ResponseError
|
47
|
+
$!.response
|
46
48
|
end
|
47
49
|
alias :say :send_message
|
48
50
|
|
@@ -51,6 +53,8 @@ module Slacks
|
|
51
53
|
channel: to_channel_id(channel),
|
52
54
|
timestamp: ts }
|
53
55
|
api("reactions.get", params)
|
56
|
+
rescue Slacks::ResponseError
|
57
|
+
$!.response
|
54
58
|
end
|
55
59
|
|
56
60
|
def update_message(ts, message, options={})
|
@@ -66,6 +70,8 @@ module Slacks
|
|
66
70
|
params.merge!(options.select { |key, _| [:username, :as_user, :parse, :link_names,
|
67
71
|
:unfurl_links, :unfurl_media, :icon_url, :icon_emoji].member?(key) })
|
68
72
|
api("chat.update", params)
|
73
|
+
rescue Slacks::ResponseError
|
74
|
+
$!.response
|
69
75
|
end
|
70
76
|
|
71
77
|
def add_reaction(emojis, message)
|
@@ -75,6 +81,8 @@ module Slacks
|
|
75
81
|
channel: message.channel.id,
|
76
82
|
timestamp: message.timestamp })
|
77
83
|
end
|
84
|
+
rescue Slacks::ResponseError
|
85
|
+
$!.response
|
78
86
|
end
|
79
87
|
|
80
88
|
def typing_on(channel)
|
@@ -247,13 +255,11 @@ module Slacks
|
|
247
255
|
end
|
248
256
|
|
249
257
|
def get_dm_for_user_id(user_id)
|
250
|
-
|
258
|
+
user_ids_dm_ids[user_id] ||= begin
|
251
259
|
response = api("im.open", user: user_id)
|
252
|
-
raise
|
260
|
+
raise UnableToDirectMessageError.new(response, user_id) unless response["ok"]
|
253
261
|
response["channel"]["id"]
|
254
262
|
end
|
255
|
-
raise ArgumentError, "Unable to direct message the user #{user_id.inspect}" unless channel_id
|
256
|
-
channel_id
|
257
263
|
end
|
258
264
|
|
259
265
|
|
data/lib/slacks/errors.rb
CHANGED
@@ -8,8 +8,11 @@ module Slacks
|
|
8
8
|
end
|
9
9
|
|
10
10
|
class ResponseError < RuntimeError
|
11
|
+
attr_reader :response
|
12
|
+
|
11
13
|
def initialize(response, message)
|
12
14
|
super message
|
15
|
+
@response = response
|
13
16
|
additional_information[:response] = response
|
14
17
|
end
|
15
18
|
end
|
@@ -32,4 +35,10 @@ module Slacks
|
|
32
35
|
super "The bot is not in the channel #{channel} and cannot reply"
|
33
36
|
end
|
34
37
|
end
|
38
|
+
|
39
|
+
class UnableToDirectMessageError < ResponseError
|
40
|
+
def initialize(response, user_id)
|
41
|
+
super response, "Unable to direct message the user #{user_id.inspect}: #{response["error"]}"
|
42
|
+
end
|
43
|
+
end
|
35
44
|
end
|
data/lib/slacks/version.rb
CHANGED