Module: TinyHttpClient
- Defined in:
- lib/tiny_http_client.rb
Class Method Summary collapse
Class Method Details
.get(url, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tiny_http_client.rb', line 7 def get(url, &block) uri = URI(url) http_opts = { use_ssl: uri.scheme == 'https' } Net::HTTP.start uri.host, uri.port, http_opts do |https| req = Net::HTTP::Get.new(uri) yield(req) if block_given? case res = https.request(req) when Net::HTTPSuccess res.body else res.error! end end end |