class GeneNames::HTTP
Public Class Methods
fetch(value, type)
click to toggle source
# File lib/gene_names/http.rb, line 8 def self.fetch(value, type) do_request('/' + ['',:fetch, type, value].collect(&:to_s).join('/'))['response']['docs'].collect{|doc| GeneNames::Record.new(doc)} end
info()
click to toggle source
# File lib/gene_names/http.rb, line 12 def self.info do_request('/info') end
search()
click to toggle source
# File lib/gene_names/http.rb, line 16 def self.search #TODO end
searchable_fields()
click to toggle source
# File lib/gene_names/http.rb, line 24 def self.searchable_fields return @search_fields || load_searchable_fields end
searchable_fields=(*fields)
click to toggle source
# File lib/gene_names/http.rb, line 20 def self.searchable_fields=(*fields) @searchable_fields = fields end
stored_fields()
click to toggle source
# File lib/gene_names/http.rb, line 32 def self.stored_fields return @stored_fields || load_stored_fields end
stored_fields=(*fields)
click to toggle source
# File lib/gene_names/http.rb, line 28 def self.stored_fields=(*fields) @searchable_fields = fields end
Private Class Methods
accept_for_type(response_type)
click to toggle source
# File lib/gene_names/http.rb, line 78 def self.accept_for_type(response_type) case response_type when :json, 'json' 'application/json' when :xml, xml 'text/xml' else raise "Unknown response type: '#{response_type.to_s}'" end end
build_http()
click to toggle source
# File lib/gene_names/http.rb, line 52 def self.build_http url = URI.parse(GeneNames::SERVER) Net::HTTP.new(url.host, url.port) end
build_request(path, response_type)
click to toggle source
# File lib/gene_names/http.rb, line 63 def self.build_request(path, response_type) Net::HTTP::Get.new(path, {'Accept' => accept_for_type(response_type)}) end
do_request(path, response_type = :json)
click to toggle source
# File lib/gene_names/http.rb, line 46 def self.do_request(path, response_type = :json) http = build_http response = get_response(http, path, response_type) return parse_response(response) end
get_response(http, path, response_type)
click to toggle source
# File lib/gene_names/http.rb, line 57 def self.get_response(http, path, response_type) response = http.request(self.build_request(path, response_type)) raise InvalidResponse, "Invalid response: #{response.code}" unless response.code == '200' return response end
load_searchable_fields()
click to toggle source
# File lib/gene_names/http.rb, line 38 def self.load_searchable_fields self.searchable_fields = self.info['searchableFields'] end
load_stored_fields()
click to toggle source
# File lib/gene_names/http.rb, line 42 def self.load_stored_fields self.searchable_fields = self.info['storedFields'] end
parse_response(response)
click to toggle source
# File lib/gene_names/http.rb, line 67 def self.parse_response(response) return case response.content_type when 'application/json' JSON.parse(response.body) when 'text/xml' #TODO else raise "Unknown content type: '#{response.content_type.to_s}'" end end