Module: Bioroebe::Biomart
- Defined in:
- lib/bioroebe/biomart/filter.rb,
lib/bioroebe/biomart/server.rb,
lib/bioroebe/biomart/biomart.rb,
lib/bioroebe/biomart/dataset.rb,
lib/bioroebe/biomart/database.rb,
lib/bioroebe/biomart/attribute.rb
Defined Under Namespace
Classes: ArgumentError, Attribute, AttributeError, BiomartError, Database, Dataset, DatasetError, Filter, FilterError, HTTPError, Server
Class Attribute Summary collapse
-
.proxy ⇒ Object
Bioroebe::Biomart.proxy = “proxy.example.com/”.
-
.timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#request(params) ⇒ String
# === request.
Class Attribute Details
.proxy ⇒ Object
Bioroebe::Biomart.proxy = “proxy.example.com/”
209 210 211 |
# File 'lib/bioroebe/biomart/biomart.rb', line 209 def proxy @proxy end |
.timeout ⇒ Object
Returns the value of attribute timeout.
210 211 212 |
# File 'lib/bioroebe/biomart/biomart.rb', line 210 def timeout @timeout end |
Instance Method Details
#request(params) ⇒ String
#
request
Centralised request function for handling all of the HTTP requests to the biomart servers.
#
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/bioroebe/biomart/biomart.rb', line 167 def request(params) raise ArgumentError if !params.is_a?(Hash) || params.empty? require 'uri' 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) { |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) } 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 |