Encode query with Ruby
From WABI
Contents |
Summary
Result may not be able to be retrieved normally, if query including non alphanumeric character is used with Ruby.
Description
You have to encode your query. If qPath is a query to be encoded, please do as follows.
require 'cgi' CGI.escape(qPath);
Sample program
This tutorial introduces a example that retrieve entries which feature-key is 'rRNA', qualifier name is 'product' and has '16s ribosomal RNA' in qualifier value with searchByXMLPath of ARSA.
Download this program
require "socket"
require 'cgi'
#set hostname
host = "xml.nig.ac.jp"
#set port
port = "80"
#set pass
path = "/rest/Invoke"
#set query
qPath = "/ENTRY/DDBJ/feature-table/feature/f_key=='rRNA' AND ";
qPath += "(/ENTRY/DDBJ/feature-table/feature{/f_key=='rRNA' AND ";
qPath += "/f_quals/qualifier{/q_name=='product' AND /q_value='16S ribosomal RNA'}}) ";
rPath = "/ENTRY/DDBJ/primary-accession,/ENTRY/DDBJ/definition";
CGI.escape(qPath);
CGI.escape(rPath);
offset = "1";
count = "10";
query = "service=ARSA&method=searchByXMLPath&queryPath=" + qPath + "&returnPath=" + rPath + "&offset=" + offset + "&count=" + count;
#make connection
socket = TCPSocket.open(host,port)
#send query
socket.write "POST "+ path + " HTTP/1.0\n"
socket.write "User-Agent: ruby/socket\n"
socket.write "Content-Type: application/x-www-form-urlencoded\n"
socket.write "Content-Length:" + query.size.to_s + "\n\n"
socket.write query
#get result
while s=socket.gets
print(s)
end
socket.close
