Class: Pubmedly::Client
- Inherits:
-
Object
- Object
- Pubmedly::Client
- Defined in:
- lib/pubmedly/client.rb
Overview
The Client class provides methods for accessing the NCBI’s eutils Pubmed API that return HTTP objects.
The NCBI eutils API provides access to many databases, but these out of the scope of pubmedly:
https://www.ncbi.nlm.nih.gov/books/NBK25497/table/chapter2.T._entrez_unique_identifiers_ui/?report=objectonly
Constant Summary collapse
- BASE_URL =
"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/"
- NCBI_DB =
"pubmed"
Instance Method Summary collapse
- #fetch(*ids, **kwargs) ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
-
#search(term, **kwargs) ⇒ Object
www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.ESearch For guidance on search terms: pubmed.ncbi.nlm.nih.gov/help/#how-do-i-search-pubmed To understand term mapping: pubmed.ncbi.nlm.nih.gov/help/#automatic-term-mapping List of all field tags: pubmed.ncbi.nlm.nih.gov/help/#search-tags Parameters for retrieval: www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.ESearch datetype parameter options: dataguide.nlm.nih.gov/eutilities/utilities.html#esearch-date-filter-parameters.
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
15 16 17 |
# File 'lib/pubmedly/client.rb', line 15 def initialize(api_key) @api_key = api_key end |
Instance Method Details
#fetch(*ids, **kwargs) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pubmedly/client.rb', line 43 def fetch(*ids, **kwargs) url = URI.parse("#{BASE_URL}efetch.fcgi") params = kwargs.merge( db: NCBI_DB, api_key: @api_key, id: ids.join(",") ) url.query = URI.encode_www_form(params) http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.request(Net::HTTP::Get.new(url.request_uri)) end |
#search(term, **kwargs) ⇒ Object
www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.ESearch For guidance on search terms: pubmed.ncbi.nlm.nih.gov/help/#how-do-i-search-pubmed To understand term mapping: pubmed.ncbi.nlm.nih.gov/help/#automatic-term-mapping List of all field tags: pubmed.ncbi.nlm.nih.gov/help/#search-tags Parameters for retrieval: www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.ESearch datetype parameter options: dataguide.nlm.nih.gov/eutilities/utilities.html#esearch-date-filter-parameters
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pubmedly/client.rb', line 25 def search(term, **kwargs) url = URI.parse("#{BASE_URL}esearch.fcgi") params = kwargs.merge({ db: NCBI_DB, api_key: @api_key, term: term, }) url.query = URI.encode_www_form(params) http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.request(Net::HTTP::Get.new(url.request_uri)) end |