Page 185, last example
response = http.get('/book/ruby3/programming-ruby-1-9')
doesn’t work for me, the response.message
is Moved Permanently.
I have no knowledge about talking to networks.
I have no output with URI.open('http://pragprog.com')
on page 186, nor with https
.
So, that’s a very weird example, in that the code sample (which comes from the older version) hardcodes the output for some reason. Anyway, I didn’t fix it on first pass, because I didn’t have a URL for the new version, but I do have it now, and I should see what happens if I let it run for real. (the code also isn’t in line with Standard Ruby (single-quote strings) so I should clean that up as well.
Thanks
Actually, the whole code example is out of date, so the whole thing is being updated to
require "net/http"
uri = URI("https://pragprog.com/titles/ruby5/programming-ruby-3-2-5th-edition/")
Net::HTTP.start(
"pragprog.com",
Net::HTTP.https_default_port,
use_ssl: true
) do |http|
request = Net::HTTP::Get.new(uri)
response = http.request(request)
if response.code == "200"
puts response.body.scan(/<img class=".*?" src="(.*?)"/m).uniq[0, 3]
end
end
@noelrappin
It looks more complex as I don’t know this topic, but I got the 3 responses.
Thanks
Yeah, I get that, I may go into more detail about the code, but it also might wind up in the yet-to-be-written section. Thanks!