module Rager::Utils::Http
Public Class Methods
Source
# File lib/rager/utils/http.rb 26 def self.download_binary(url, http_adapter: nil) 27 adapter = http_adapter || Rager.config.http_adapter 28 response = adapter.make_request( 29 Rager::Http::Request.new(url: url, headers: {}) 30 ) 31 32 return nil unless response.success? 33 body = response.body 34 return nil if body.nil? 35 36 if body.is_a?(String) 37 body 38 elsif body.respond_to?(:each) 39 body.to_a.join 40 else 41 body.to_s 42 end 43 end
Source
# File lib/rager/utils/http.rb 46 def self.download_file(url, path, http_adapter: nil) 47 content = download_binary(url, http_adapter: http_adapter) 48 return nil if content.nil? 49 50 FileUtils.mkdir_p(File.dirname(path)) 51 File.write(path, content) 52 path 53 end
Source
# File lib/rager/utils/http.rb 17 def self.sleep(duration) 18 if defined?(Async::Task) && (task = Async::Task.current?) 19 task.sleep(duration) 20 else 21 Kernel.sleep(duration) 22 end 23 end