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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e10c085c812db7ebb4c4882d2d29963c9b29941
4
- data.tar.gz: 8d4fcc5ce2622251a901d97b35d895819e874fbd
3
+ metadata.gz: 6c24545abd2bab75c557ad4699e423a2a8bd504e
4
+ data.tar.gz: 3e5c5fe08361695315dff88a9c72f304453801f5
5
5
  SHA512:
6
- metadata.gz: 3eb4f58e4f8cd344d133539ccf3413ff6fce1622fc3228a61ca77cff35c9ff8cbe25c288d4a4cf7425e99d62802efe4db58f191a01b8c85b32aa20416df63640
7
- data.tar.gz: f5094c0ede839359afed74c5726df6a2df7731b19317210e73b4f6d4d558653916f7a061a2a77168e377b7d80a98e8126483eca01e5c9d36818739222988613b
6
+ metadata.gz: 19adcd7bb6445da7e853792c835e282bae16e1967636b589dee43a3eb72825ce419168ec353891deac42367b68d003a516ab6b8b8d008a0b1331897a92a6e001
7
+ data.tar.gz: 5ea7f3cc21d0aac9d7378c092e13de7632722eb0382fedf333cfcdaae1a59b20b8792c04b08521d81a9911772be29df038bb3c2f120be8a130d9c9ba41f68d52
@@ -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
- channel_id = user_ids_dm_ids[user_id] ||= begin
258
+ user_ids_dm_ids[user_id] ||= begin
251
259
  response = api("im.open", user: user_id)
252
- raise ArgumentError, "Unable to direct message the user #{user_id.inspect}: #{response["error"]}" unless response["ok"]
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
@@ -1,3 +1,3 @@
1
1
  module Slacks
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slacks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail