Class: CommonChemistry::Client
- Inherits:
-
Object
- Object
- CommonChemistry::Client
- Includes:
- HTTParty
- Defined in:
- lib/commonchemistry.rb
Overview
Client class to interact with the Common Chemistry API
Instance Method Summary collapse
-
#detail(cas_rn: nil, uri: nil) ⇒ DetailResult
Retrieves detailed information about a substance.
-
#export(uri:, return_as_attachment: false) ⇒ String
Exports substance data.
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#search(q:, offset: nil, size: nil) ⇒ SearchResponse
Searches for substances matching the query.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
22 23 24 |
# File 'lib/commonchemistry.rb', line 22 def initialize # TODO end |
Instance Method Details
#detail(cas_rn: nil, uri: nil) ⇒ DetailResult
Retrieves detailed information about a substance
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/commonchemistry.rb', line 54 def detail(cas_rn: nil, uri: nil) params = {} params[:cas_rn] = cas_rn if cas_rn params[:uri] = uri if uri response = self.class.get('/detail', query: params) handle_response(response) do DetailResult.new(response.parsed_response) end end |
#export(uri:, return_as_attachment: false) ⇒ String
Exports substance data
73 74 75 76 77 78 79 |
# File 'lib/commonchemistry.rb', line 73 def export(uri:, return_as_attachment: false) params = { uri: uri, returnAsAttachment: } response = self.class.get('/export', query: params) handle_response(response) do response.body # Since the response is text/plain end end |
#search(q:, offset: nil, size: nil) ⇒ SearchResponse
Searches for substances matching the query
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/commonchemistry.rb', line 35 def search(q:, offset: nil, size: nil) params = { q: q } params[:offset] = offset if offset params[:size] = size if size response = self.class.get('/search', query: params) handle_response(response) do SearchResponse.new(response.parsed_response) end end |