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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28469725b7fb68767bb0d61bee21ba57d07981c2
4
- data.tar.gz: 25b5846794a969010cda1b67e562db4ee3f5a057
3
+ metadata.gz: 2ed91bd167a9937bfb461ebc2d8698b0ec8c3eee
4
+ data.tar.gz: ca6fe355afd2a7539a0fbd78b8179d7d722cce2f
5
5
  SHA512:
6
- metadata.gz: 62ce637e1393b02ed343fd6b4aa4a3cff6bcc8f553c1262fffda5c579a9a53f804c5f16ea7f7d9abae927bacf7fb3b94cfa47dda289f46069b964815f4ba1b51
7
- data.tar.gz: ce9e95208c481471fda11f018d5edc917ec2df6d1554a2fe1b1bc8181873abe6c401460705b907187eae4014c592608cd5a8fe683b30c71d4e75f4241edc0e65
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
- t = Thread.new do
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
- reader, _writer, _exception = IO.select([response_reader, command_reader])
98
- case reader.first
99
- when response_reader
100
- buf << response_reader.readpartial(1024)
101
- begin
102
- res = JSON.parse(buf, symbolize_names: true)
103
- rescue JSON::ParserError
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
- buf = ""
108
- if res[:result] == "success"
109
- res[:events].each do |event|
110
- last_event_id = event[:id]
111
- if event_types.empty? || event_types.include?(event[:type])
112
- yield event
113
- end
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
- when command_reader
119
- break
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
@@ -1,5 +1,5 @@
1
1
  module Zulip
2
2
  class Client
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
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.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-09 00:00:00.000000000 Z
11
+ date: 2017-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday