slacks 0.2.1 → 0.2.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: 1385dd16f098666b0fa17c46fa177bcad2ae1602
4
- data.tar.gz: ee7310ebdbe83f6db147b4a73ec958e2db6e0afe
3
+ metadata.gz: 29bd178310f09e497ba17e74419960644e44cabd
4
+ data.tar.gz: 74366336ea39592f1cee2f977e32d8d38cb9dc61
5
5
  SHA512:
6
- metadata.gz: e0f15cfaa115fc220b53da103297e5c57933cc52c01f4b9ef1170b468d2227decb798ff76d407a370f03362069c2728ad3798c3af840aed8ec79e18408fda635
7
- data.tar.gz: 5c3b99a3fbd3776cdd47f4b4b60d8d8959f1df732735e1aaa19c628ff876296debb75b972da78a173a8f6f4910a2bb415e78315702f486a6cc44f202289a995a
6
+ metadata.gz: 871eeaba13d8348e75f6b95995d496c81d892f6feb1d12f8d40d590d6bd9748d0dd926f439bbcec9c705a32e5346b09133116ec265029e0de609e15def3e687f
7
+ data.tar.gz: f490281f500512607a9e6d617e5f48e2df9a7f1d63db9dbeadef2e47cb75eb3dc5152fc53b9355a630e7928be6e351661ae5187a272d2c678b384655e94988e7
@@ -47,6 +47,10 @@ module Slacks
47
47
  end
48
48
  end
49
49
 
50
+ def typing
51
+ slack.typing_on(self)
52
+ end
53
+
50
54
  def direct_message?
51
55
  type == :direct_message
52
56
  end
@@ -72,28 +72,29 @@ module Slacks
72
72
  end
73
73
  end
74
74
 
75
+ def typing_on(channel)
76
+ websocket.write MultiJson.dump(type: "typing", channel: to_channel_id(channel))
77
+ end
78
+
75
79
 
76
80
 
77
81
  def listen!(callbacks)
78
82
  response = api("rtm.start")
79
-
80
83
  unless response["ok"]
81
84
  raise MigrationInProgress if response["error"] == "migration_in_progress"
82
85
  raise ResponseError.new(response, response["error"])
83
86
  end
84
-
85
87
  store_context!(response)
86
88
 
89
+ @websocket = Slacks::Driver.new
90
+ websocket.connect_to websocket_url
87
91
  callbacks.connected
88
92
 
89
- client = Slacks::Driver.new
90
- client.connect_to websocket_url
91
-
92
- client.on(:error) do |event|
93
+ websocket.on(:error) do |event|
93
94
  raise ConnectionError.new(event)
94
95
  end
95
96
 
96
- client.on(:message) do |data|
97
+ websocket.on(:message) do |data|
97
98
  case data["type"]
98
99
  when EVENT_GROUP_JOINED
99
100
  group = data["channel"]
@@ -114,7 +115,7 @@ module Slacks
114
115
  end
115
116
  end
116
117
 
117
- client.main_loop
118
+ websocket.main_loop
118
119
 
119
120
  rescue EOFError
120
121
  # Slack hung up on us, we'll ask for a new WebSocket URL and reconnect.
@@ -180,7 +181,8 @@ module Slacks
180
181
  :group_id_by_name,
181
182
  :channels_by_id,
182
183
  :channel_id_by_name,
183
- :websocket_url
184
+ :websocket_url,
185
+ :websocket
184
186
 
185
187
 
186
188
 
@@ -204,6 +206,7 @@ module Slacks
204
206
 
205
207
 
206
208
  def to_channel_id(name)
209
+ return name.id if name.is_a?(Slacks::Channel)
207
210
  return name if name =~ /^[DGC]/ # this already looks like a channel id
208
211
  return get_dm_for_username(name) if name.start_with?("@")
209
212
  return to_group_id(name) unless name.start_with?("#")
data/lib/slacks/driver.rb CHANGED
@@ -66,6 +66,10 @@ module Slacks
66
66
  @has_been_init = true
67
67
  end
68
68
 
69
+ def write(message)
70
+ @driver.text(message)
71
+ end
72
+
69
73
  def connected?
70
74
  @connected || false
71
75
  end
data/lib/slacks/event.rb CHANGED
@@ -24,6 +24,10 @@ module Slacks
24
24
  channel.random_reply(*args)
25
25
  end
26
26
 
27
+ def typing
28
+ channel.typing
29
+ end
30
+
27
31
  def start_conversation!
28
32
  Conversation.new(session, channel, sender)
29
33
  end
@@ -1,3 +1,3 @@
1
1
  module Slacks
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slacks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-28 00:00:00.000000000 Z
11
+ date: 2016-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket-driver