I was recently writing some (stand-alone) Ruby code that hit several servers with REST/API HTTP calls. IOW, using http to retrieve data (json) from a server.
All of it was done with the Ruby Net::HTTP library (2.5, 2.2) over ssl. I wrote the code using Ruby 2.7.0dev, but it works fine in SU 2018 with Ruby 2.2.4.
Back in the old days of SketchUp (SU), the Net::HTTP library had issues, and the SU team added Sketchup::Http as a replacement.
I think that if one is targeting SU versions with Ruby 2.2 or later, one should consider using Net::HTTP.
Pros:
-
If one is doing multiple requests, and given that many connections are using ssl (https), using Net:HTTP.start allows one to negotiate a single ssl connection and perform multiple requests, assuming the conections are done in quick succession.
-
Net:HTTP.start’s options parameter allows more control over the connection.
-
Net:HTTP can be used in stand-alone Ruby, allowing one to write and test code there.
Cons:
- Net:HTTP uses the OpenSSL library that Ruby is packaged with. OpenSSL 1.0.2 and earlier takes a second or two to intialize itself on the first connection. Subsequent connections are faster. This may not be an issue with Sketchup::Http.
Misc:
To see what version of OpenSSL is used:
require 'openssl' ; puts OpenSSL::OPENSSL_LIBRARY_VERSION