Class: YoudaoFanyi::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/youdao-fanyi/request.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(q, doctype) ⇒ Request

Returns a new instance of Request.



12
13
14
15
# File 'lib/youdao-fanyi/request.rb', line 12

def initialize(q, doctype)
	@query = q
	@doctype = doctype
end

Class Method Details

.get(q, doctype) ⇒ Object



8
9
10
# File 'lib/youdao-fanyi/request.rb', line 8

def self.get(q, doctype)
	new(q, doctype).request
end

Instance Method Details

#requestObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/youdao-fanyi/request.rb', line 17

def request
	#open(url) do |f|
	#	f.read
	#end
	uri = URI.parse(url)
	http = Net::HTTP.new(uri.host, uri.port)
	request = Net::HTTP::Get.new(uri.request_uri)
	response = http.request(request)
	raise_errors(response)
	response.body
end