Class: KirinHttp::BasicClient

Inherits:
Client
  • Object
show all
Defined in:
lib/kirin_http/http_client.rb

Instance Method Summary collapse

Instance Method Details

#send(request) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kirin_http/http_client.rb', line 14

def send(request)
	http = Net::HTTP.new request.host, request.port
	http.use_ssl = request.ssl
	case request.method
		when :get
			type = Net::HTTP::Get
		when :post
			type = Net::HTTP::Post
		when :put
			type = Net::HTTP::Put
		when :patch
			type = Net::HTTP::Patch
		when :delete
			type = Net::HTTP::Delete
		when :head
			type = Net::HTTP::Head
		else
			raise NoMethodError "Unknown HTTP verb #{request.method.to_s}"
	end
	req = type.new(request.path, request.header)
	req.body = request.content unless request.content.nil?
	resp = http.request(req)
	Response.new(resp.body, resp.to_hash, resp.code.to_i)
end