Class: BioChEMBL::REST
- Inherits:
-
Object
show all
- Defined in:
- lib/bio-chembl/rest_client.rb,
lib/bio-chembl/rest_api_server.rb
Defined Under Namespace
Modules: ChEMBL_URI
Classes: Server
Constant Summary
collapse
- HOST_NAME =
"www.ebi.ac.uk"
- API_ROOT =
"chemblws"
- BASE_URI =
"https://" + HOST_NAME + "/" + API_ROOT
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(uri = BASE_URI) ⇒ REST
142
143
144
145
146
147
148
|
# File 'lib/bio-chembl/rest_client.rb', line 142
def initialize(uri = BASE_URI)
uri = URI.parse(uri) unless uri.kind_of?(URI)
@header = {
'User-Agent' => "BioChEMBL, BioRuby/#{Bio::BIORUBY_VERSION_ID}"
}
@debug = false
end
|
Instance Attribute Details
#debug ⇒ Object
If true, shows debug information to $stderr.
151
152
153
|
# File 'lib/bio-chembl/rest_client.rb', line 151
def debug
@debug
end
|
Class Method Details
.up? ⇒ Boolean
BioChEMBL::REST.up? #=> true/false
132
133
134
135
136
137
138
|
# File 'lib/bio-chembl/rest_client.rb', line 132
def self.up?
if new.status == "UP"
true
else
false
end
end
|
.usage ⇒ Object
123
124
125
126
127
128
129
|
# File 'lib/bio-chembl/rest_client.rb', line 123
def self.usage
["a = Bio::DB::ChEMBL::REST.new",
"a.status => https://www.ebi.ac.uk/chembldb/index.php/ws#serviceStatus",
'a.compounds("CHEMBL1") => http://www.ebi.ac.uk/chemblws/compounds/CHEMBL1',
'a.compounds.stdinchikey("QFFGVLORLPOAEC-SNVBAGLBSA-N") => http://www.ebi.ac.uk/chemblws/compounds/stdinchikey/QFFGVLORLPOAEC-SNVBAGLBSA-N'
].join("\n")
end
|
.website ⇒ Object
118
119
120
|
# File 'lib/bio-chembl/rest_client.rb', line 118
def self.website
"https://www.ebi.ac.uk/chembldb/index.php/ws"
end
|
Instance Method Details
#address(path) ⇒ Object
189
190
191
|
# File 'lib/bio-chembl/rest_client.rb', line 189
def address(path)
"#{BASE_URI}/#{path}"
end
|
#assays(chemblId = nil, action = nil) ⇒ Object
259
260
261
|
# File 'lib/bio-chembl/rest_client.rb', line 259
def assays(chemblId = nil, action = nil)
get_body(current_method_name, [chemblId, action])
end
|
#compounds(chemblId = nil, action = nil, params = nil) ⇒ Object
227
228
229
|
# File 'lib/bio-chembl/rest_client.rb', line 227
def compounds(chemblId = nil, action = nil, params = nil)
get_body(current_method_name, [chemblId, action, params])
end
|
#compounds_similarity(smiles) ⇒ Object
243
244
245
|
# File 'lib/bio-chembl/rest_client.rb', line 243
def compounds_similarity(smiles)
get_body(current_method_name, [smiles])
end
|
#compounds_smiles(smiles) ⇒ Object
235
236
237
|
# File 'lib/bio-chembl/rest_client.rb', line 235
def compounds_smiles(smiles)
get_body(current_method_name, [smiles])
end
|
#compounds_stdinchikey(stdinchikey) ⇒ Object
231
232
233
|
# File 'lib/bio-chembl/rest_client.rb', line 231
def compounds_stdinchikey(stdinchikey)
get_body(current_method_name, [stdinchikey])
end
|
#compounds_substructure(smiles) ⇒ Object
239
240
241
|
# File 'lib/bio-chembl/rest_client.rb', line 239
def compounds_substructure(smiles)
get_body(current_method_name, [smiles])
end
|
#get(url) ⇒ Object
154
155
156
157
158
159
160
161
162
|
# File 'lib/bio-chembl/rest_client.rb', line 154
def get(url)
easy = Curl::Easy.new(url) do |c|
@header.each do |k,v|
c.[k] = v
end
end
easy.perform
easy
end
|
#prepare_return_value(response) ⇒ Object
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/bio-chembl/rest_client.rb', line 165
def prepare_return_value(response)
if @debug then
$stderr.puts "ChEMBL: #{response.inspect}"
end
case response.response_code
when 200
response.body_str
when 400
raise Exception, "400 Bad request #{response.inspect}"
when 404
raise Exception, "404 Not found #{response.inspect}"
when 500
raise Exception, "500 Service unavailable"
else
nil
end
end
|
#status ⇒ Object
223
224
225
|
# File 'lib/bio-chembl/rest_client.rb', line 223
def status
get_body(current_method_name)
end
|
#targets(chemblId = nil, action = nil) ⇒ Object
247
248
249
|
# File 'lib/bio-chembl/rest_client.rb', line 247
def targets(chemblId = nil, action = nil)
get_body(current_method_name, [chemblId, action])
end
|
#targets_refseq(refseq_id) ⇒ Object
255
256
257
|
# File 'lib/bio-chembl/rest_client.rb', line 255
def targets_refseq(refseq_id)
get_body(current_method_name, [refseq_id])
end
|
#targets_uniprot(uniprot_id) ⇒ Object
251
252
253
|
# File 'lib/bio-chembl/rest_client.rb', line 251
def targets_uniprot(uniprot_id)
get_body(current_method_name, [uniprot_id])
end
|
#uri ⇒ Object
184
185
186
|
# File 'lib/bio-chembl/rest_client.rb', line 184
def uri
ChEMBL_URI
end
|