No release in over a year
This client sends a request and waits for a response, just like HTTP communication.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 2.6.1
~> 3.0.0
~> 0.2.0
~> 0.11.0
~> 1.2.9
 Project Readme

catch-websocket-client

This client sends a request and waits for a response, just like HTTP communication.

Usage

Case. 1

require 'catch-websocket-client'

cws = CatchWebSocket::Client.new 'wss://example.com'

response = cws.request({
  command: :auth,
  params: {
    user: 'username',
    pass: 'password'
  }
})

result = JSON.parse(response)

puts JSON.pretty_generate(result)

Case. 2

require 'catch-websocket-client'

result = nil
CatchWebSocket::Client.open('wss://example.com') { |socket|
  socket.request({
  }) { |result|
    result = JSON.parse(result)
    if result['chunk']
      results = []
      while true
        results[result['seq']] = result['chunk']
        break if result['last']
        result = JSON.parse(socket.receive)
      end
      result = JSON.parse(results.join)
    end
  }
}

puts JSON.pretty_generate(result)

Copyright

Copyright c 2022 neirouter.com LICENSE: MIT License