Class: E621::HTTP
- Inherits:
-
Object
- Object
- E621::HTTP
- Defined in:
- lib/standard/http.rb
Instance Method Summary collapse
-
#get(url, request) ⇒ Object
Small wrapper function for get calls.
-
#geti(url, request) ⇒ Object
#geti gives an immediate response in the form of bytes downloaded.
-
#initialize(host = "e621.net", port = 443) ⇒ HTTP
constructor
A new instance of HTTP.
-
#post(url, request) ⇒ Object
Small wrapper function for post calls.
Constructor Details
#initialize(host = "e621.net", port = 443) ⇒ HTTP
Returns a new instance of HTTP.
24 25 26 27 |
# File 'lib/standard/http.rb', line 24 def initialize(host="e621.net",port=443) @http = Net::HTTP.new(host,port) @http.use_ssl = true if port == 443 end |
Instance Method Details
#get(url, request) ⇒ Object
Small wrapper function for get calls. This way a proper logging is guaranteed.
35 36 37 |
# File 'lib/standard/http.rb', line 35 def get(url,request) return parse_body(@http.get("#{url}?#{request}")) end |
#geti(url, request) ⇒ Object
#geti gives an immediate response in the form of bytes downloaded. This won’t be included in the gems though.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/standard/http.rb', line 40 def geti(url,request) uri = "#{url}?#{request}" count = (@http.head(uri)["content-length"].to_i/1024.0).round(1) clength, = count.to_s.length,String.new @http.get("#{url}?#{request}") do |body| += body mlength = (.length/1024.0).round(1) print "Downloaded #{" "*(clength-mlength.to_s.length)}#{mlength}/#{count}kB\r" end return {"body"=>} end |
#post(url, request) ⇒ Object
Small wrapper function for post calls. This way a proper logging is guaranteed.
30 31 32 |
# File 'lib/standard/http.rb', line 30 def post(url,request) return parse_body(@http.post(url,request)) end |