Module: Biomart
- Defined in:
- lib/biomart.rb,
lib/biomart/filter.rb,
lib/biomart/server.rb,
lib/biomart/dataset.rb,
lib/biomart/version.rb,
lib/biomart/database.rb,
lib/biomart/attribute.rb
Defined Under Namespace
Classes: ArgumentError, Attribute, AttributeError, BiomartError, Database, Dataset, DatasetError, Filter, FilterError, HTTPError, Server
Constant Summary collapse
- VERSION =
"0.2.3"
Class Attribute Summary collapse
-
.proxy ⇒ Object
Returns the value of attribute proxy.
-
.timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#request(params) ⇒ String
Centralised request function for handling all of the HTTP requests to the biomart servers.
Class Attribute Details
.proxy ⇒ Object
Returns the value of attribute proxy.
105 106 107 |
# File 'lib/biomart.rb', line 105 def proxy @proxy end |
.timeout ⇒ Object
Returns the value of attribute timeout.
105 106 107 |
# File 'lib/biomart.rb', line 105 def timeout @timeout end |
Instance Method Details
#request(params) ⇒ String
Centralised request function for handling all of the HTTP requests to the biomart servers.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/biomart.rb', line 64 def request( params ) raise ArgumentError if !params.is_a?(Hash) || params.empty? if params[:url] =~ / / params[:url].gsub!(" ","+") end uri = URI.parse( params[:url] ) client = net_http_client() req = nil response = nil case params[:method] when 'post' req = Net::HTTP::Post.new(uri.path) req.form_data = { "query" => params[:query] } else req = Net::HTTP::Get.new(uri.request_uri) end client.start(uri.host, uri.port) do |http| if Biomart.timeout or params[:timeout] http.read_timeout = params[:timeout] ? params[:timeout] : Biomart.timeout http.open_timeout = params[:timeout] ? params[:timeout] : Biomart.timeout end response = http.request(req) end response_code = response.code response_body = response.body if defined? Encoding && response_body.encoding == Encoding::ASCII_8BIT response_body = response_body.force_encoding(Encoding::UTF_8).encode end check_response( response_body, response_code ) return response_body end |