Module: MstdnIvory::Stream
- Included in:
- Api
- Defined in:
- lib/mstdn_ivory/stream.rb
Instance Method Summary collapse
- #connect(request) ⇒ Object
- #stream(path, options = {}, &block) ⇒ Object
- #stream_request(method, path, params, &block) ⇒ Object
- #to_url_params(params) ⇒ Object
Instance Method Details
#connect(request) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mstdn_ivory/stream.rb', line 27 def connect(request) client = TCPSocket.open(request.socket_host, request.socket_port) ssl_client = OpenSSL::SSL::SSLSocket.new(client) ssl_client.connect request.stream(ssl_client) ssl_client end |
#stream(path, options = {}, &block) ⇒ Object
9 10 11 |
# File 'lib/mstdn_ivory/stream.rb', line 9 def stream(path, = {}, &block) stream_request(:get, path, , &block) end |
#stream_request(method, path, params, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mstdn_ivory/stream.rb', line 13 def stream_request(method, path, params, &block) uri = Addressable::URI.parse(self.base_url + path) request = HTTP::Request.new(verb: method, uri: uri + '?' + to_url_params(params), headers: self.headers) client = connect(request) parser = MstdnIvory::Parser.new(&block) while (body = client.readpartial(4096)) parser << body end end |
#to_url_params(params) ⇒ Object
38 39 40 41 42 |
# File 'lib/mstdn_ivory/stream.rb', line 38 def to_url_params(params) work = Addressable::URI.new work.query_values = params work.query end |