zulip-client 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zulip/client.rb +20 -50
- data/lib/zulip/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ed91bd167a9937bfb461ebc2d8698b0ec8c3eee
|
4
|
+
data.tar.gz: ca6fe355afd2a7539a0fbd78b8179d7d722cce2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7950360517f5f47f448c8e944869bb0bd3367fabee10d920036cb1590cfd54530c4a700d27859d491d061ec8da2e6f269296137defc49ac8c3b5040f7678dff6
|
7
|
+
data.tar.gz: 9ec7af9c69102d606b2b3cb2d881c9b3b5c02835ab85e92b36add9e91bc9e8de9cbdf3988e14c46b2752850da2f96a6f16eddb44a143d40b6977a77527beeb29
|
data/lib/zulip/client.rb
CHANGED
@@ -80,47 +80,34 @@ module Zulip
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def stream_event(event_types: [], narrow: [])
|
83
|
-
queue_id, last_event_id = register(event_types: event_types, narrow: narrow)
|
84
|
-
response_reader, response_writer = IO.pipe
|
85
|
-
command_reader, @command_writer = IO.pipe
|
86
83
|
@running = true
|
87
|
-
|
88
|
-
loop do
|
89
|
-
break unless @running
|
90
|
-
response = get_events(queue_id: queue_id, last_event_id: last_event_id)
|
91
|
-
response_writer.write(response)
|
92
|
-
sleep(1)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
buf = ""
|
84
|
+
queue_id, last_event_id = register(event_types: event_types, narrow: narrow)
|
96
85
|
loop do
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
# Ignore error because buf is incomplete JSON
|
105
|
-
next
|
86
|
+
break unless @running
|
87
|
+
response = nil
|
88
|
+
@connection.in_parallel do
|
89
|
+
response = @connection.get do |request|
|
90
|
+
request.url("/api/v1/events")
|
91
|
+
request.params["queue_id"] = queue_id
|
92
|
+
request.params["last_event_id"] = last_event_id
|
106
93
|
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
94
|
+
end
|
95
|
+
|
96
|
+
if response.success?
|
97
|
+
res = JSON.parse(response.body, symbolize_names: true)
|
98
|
+
raise Zulip::ResponseError, res[:msg] unless res[:result] == "success"
|
99
|
+
res[:events].each do |event|
|
100
|
+
last_event_id = event[:id]
|
101
|
+
if event_types.empty? || event_types.include?(event[:type])
|
102
|
+
yield event
|
114
103
|
end
|
115
|
-
else
|
116
|
-
raise Zulip::ResponseError, res[:msg]
|
117
104
|
end
|
118
|
-
|
119
|
-
|
105
|
+
else
|
106
|
+
raise Zulip::ResponseError, response.reason_phrase
|
120
107
|
end
|
121
108
|
end
|
109
|
+
ensure
|
122
110
|
unregister(queue_id)
|
123
|
-
t.join
|
124
111
|
end
|
125
112
|
|
126
113
|
def stream_message(narrow: [])
|
@@ -131,23 +118,6 @@ module Zulip
|
|
131
118
|
|
132
119
|
def close_stream
|
133
120
|
@running = false
|
134
|
-
@command_writer.write("q") if @command_writer
|
135
|
-
end
|
136
|
-
|
137
|
-
private
|
138
|
-
|
139
|
-
def get_events(queue_id:, last_event_id:)
|
140
|
-
response = @connection.get do |request|
|
141
|
-
request.url("/api/v1/events")
|
142
|
-
request.params["queue_id"] = queue_id
|
143
|
-
request.params["last_event_id"] = last_event_id
|
144
|
-
request.params["dont_block"] = true
|
145
|
-
end
|
146
|
-
if response.success?
|
147
|
-
response.body
|
148
|
-
else
|
149
|
-
raise Zulip::ResponseError, response.reason_phrase
|
150
|
-
end
|
151
121
|
end
|
152
122
|
end
|
153
123
|
end
|
data/lib/zulip/client/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zulip-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okkez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|