Hi Ely, great call on this! response.read_body is exactly what I was missing. I really appreciate you pointing me to the right place in the docs! :)
response.read_body
In the end, here's the listener_controller code I used:
require 'net/http' class ListenerController < ApplicationController def index url = URI.parse('http://localhost:3000/broadcaster') Net::HTTP.start(url.host, url.port) do |http| request = Net::HTTP::Get.new(url.to_s) http.request(request) do |response| puts <<-READOUT res.read_body: ============================== READOUT response.read_body do |data_str| if data_str != "" data_hash = eval(data_str.slice!(6..-1)) # slice to remove leading "data: " substring char_hash = data_hash[:character] Character.create("uuid": char_hash[:uuid], "name": char_hash[:name], "hp": char_hash[:hp], "magic": char_hash[:magic]) end end end end end end
Thank you again!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Ely, great call on this!
response.read_body
is exactly what I was missing. I really appreciate you pointing me to the right place in the docs! :)In the end, here's the listener_controller code I used:
Thank you again!