Class: URL::NetHandler

Inherits:
RequestHandler show all
Defined in:
lib/url/handlers/net_handler.rb

Overview

Net::HTTP Handler

Instance Attribute Summary

Attributes inherited from RequestHandler

#url

Instance Method Summary collapse

Methods inherited from RequestHandler

#initialize

Constructor Details

This class inherits a constructor from URL::RequestHandler

Instance Method Details

#delete(args = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/url/handlers/net_handler.rb', line 25

def delete(args={})
  http = http_obj
  request = Net::HTTP::Delete.new(make_path + url.params.to_s)
  t = Time.now
  resp = http.request(request)
  make_str(resp,Time.now-t)
rescue Errno::ECONNREFUSED => e
  make_error
end

#get(args = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/url/handlers/net_handler.rb', line 4

def get(args={})
  http = http_obj
  request = Net::HTTP::Get.new(make_path + url.params.to_s)
  t = Time.now
  resp = http.request(request)
  make_str(resp,Time.now-t)
rescue Errno::ECONNREFUSED => e
  make_error
end

#post(args = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/url/handlers/net_handler.rb', line 14

def post(args={})
  http = http_obj
  request = Net::HTTP::Post.new(make_path)
  request.set_form_data(url.params)
  t = Time.now
  resp = http.request(request)
  make_str(resp,Time.now-t)
rescue Errno::ECONNREFUSED => e
  make_error
end

#put(args = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/url/handlers/net_handler.rb', line 35

def put(args={})
  http = http_obj
  request = Net::HTTP::Put.new(make_path)
  request.body = url.params.to_s(false)
  t = Time.now
  resp = http.request(request)
  make_str(resp,Time.now-t)
rescue Errno::ECONNREFUSED => e
  make_error
end