Module: Sylfy::Service::ENSEMBL::REST

Defined in:
lib/sylfy/service/hgncrest.rb,
lib/sylfy/service/ensemblrest.rb,
lib/sylfy/service/ensemblrest/xrefs.rb,
lib/sylfy/service/ensemblrest/comparative.rb

Defined Under Namespace

Modules: Alignment, Genetree, Homology, Xrefs

Constant Summary collapse

BASEURI =
URI.parse("http://beta.rest.ensembl.org")
HTTP =
Net::HTTP.new(BASEURI.host, BASEURI.port)

Class Method Summary collapse

Class Method Details

.infoarray of Hash

internal method supporting all ENSEMBLREST service

Parameters:

Returns:

  • (array of Hash)

    results



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sylfy/service/hgncrest.rb', line 31

def info()
	request = Net::HTTP::Get.new(get_path, {'Content-Type' => option.has_key?('content-type') ? option['content-type'] : 'application/json'})
	response = HTTP.request(request)
	
	if response.code != "200"
		#raise ParameterError, "Invalid response: #{response.code}"
	else
		#return YAML::dump(JSON.parse(response.body))
		if option.has_key?('content-type') && option['content-type'] != 'application/json'
			return response.body
		else
			return JSON.parse(response.body)
		end
	end
end

.service(get_path, option_type = [], option = {}) ⇒ array of Hash

internal method supporting all ENSEMBLREST service

Parameters:

Returns:

  • (array of Hash)

    results



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sylfy/service/ensemblrest.rb', line 35

def service(get_path, option_type = [], option={})
	
	optionList = []
		
	option.each do |k, v|
		optionList.push("#{k}=#{v}") if option_type.include?(k.to_sym)
	end
	
	
	get_path += "?#{optionList.join(";")}" if !optionList.empty?
	
	request = Net::HTTP::Get.new(get_path, {'Content-Type' => option.has_key?('content-type') ? option['content-type'] : 'application/json'})
	response = HTTP.request(request)
	
	if response.code != "200"
		#raise ParameterError, "Invalid response: #{response.code}"
	else
		if option.has_key?('content-type') && option['content-type'] != 'application/json'
			return response.body
		else
			return JSON.parse(response.body)
		end
	end
	
end