Syconium
Syconium is a Ruby wrapper on the OpenAlex API. Code follow the spirit/approach of the Gem serrano, and indeed much of the wrapping utility is copied 1:1 from that repo, thanks @sckott.
Installation
Add this line to your application's Gemfile:
gem 'syconium'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install syconium
Usage
To use the OpenAlex API via the Syconium Ruby gem, you must supply either your email address or your api_key. Providing your email helps OpenAlex get in touch with your if there is a problem with your software.
Pagination
For pagination, you can browse up to 10,000 results with the page and per_page parameters:
Syconium.works(email: "your_email@example.com", page: 5, per_page:25) # => Hash
Beyond 10,000 results it is strongly recommended to use the data snapshot instead of the API, but you can also use a cursor, which you can request with a *:
Syconium.works(email: "your_email@example.com", per_page:1, cursor="*") # => Hash
The metadata will contain the next_cursor to browse the next page:
Syconium.works(email: "your_email@example.com", per_page:1, cursor="IlsxMDAuMCwgNTM2NCwgJ2h0dHBzOi8vb3BlbmFsZXgub3JnL1czMDEwNDQxNzMyJ10i")
Endpoints
All of the endpoints (authors, funders, keywords, institutions, publishers, sources, topics, works) are wrapped and function similarly.
List authors:
Syconium.authors() # => Hash
Search authors:
Syconium.authors(email: "your_email@example.com", search: "Smith") # => Hash
For autocomplete, use the q parameter as the autocomplete field and also optionally you can use the filter and search parameters:
Syconium.authors(email: "your_email@example.com", autocomplete: true, q: "Smi") # => Hash
Syconium.authors(email: "your_email@example.com", autocomplete: true, q: "Smi", search: "John") # => Hash
Filter authors by attributes:
Syconium.authors(email: "your_email@example.com", filter: 'has_orcid:true') # => Hash
Group results by attributes:
Syconium.authors(email: "your_email@example.com", group_by: 'has_orcid') # => Hash
Get an author by ID:
Syconium.authors(email: "your_email@example.com", id: 'A1234567') # => Hash
Syconium.authors(email: "your_email@example.com", id: 'orcid:0000-0000-0000-0000') # => Hash
Get a random author:
Syconium.authors(email: "your_email@example.com", random: true) # => Hash
Get a random sample of 25 authors:
Syconium.authors(email: "your_email@example.com", sample: 25) # => Hash
The concepts endpoints should work, but they are depreciated/unmaintained so it is recommended to use Topics instead.
List funders:
Syconium.funders() # => Hash
Search funders:
Syconium.funders(email: "your_email@example.com", search: "Smith") # => Hash
For autocomplete, use the q parameter as the autocomplete field and also optionally you can use the filter and search parameters:
Syconium.funders(email: "your_email@example.com", autocomplete: true, q: "Nationa") # => Hash
Syconium.funders(email: "your_email@example.com", autocomplete: true, q: "Nationa", search: "Biodiversity") # => Hash
Filter funders by attributes:
Syconium.funders(email: "your_email@example.com", filter: 'country_code:ca') # => Hash
Group results by attributes:
Syconium.funders(email: "your_email@example.com", group_by: 'country_code') # => Hash
Get a funder by ID:
Syconium.funders(email: "your_email@example.com", id: 'F4320306076') # => Hash
Syconium.funders(email: "your_email@example.com", id: 'ror:021nxhr62') # => Hash
Get a random funders:
Syconium.funders(email: "your_email@example.com", random: true) # => Hash
Get a random sample of 25 funders:
Syconium.funders(email: "your_email@example.com", sample: 25) # => Hash
List institutions:
Syconium.institutions() # => Hash
Search institutions:
Syconium.institutions(email: "your_email@example.com", search: "biodiversity") # => Hash
For autocomplete, use the q parameter as the autocomplete field and also optionally you can use the filter and search parameters:
Syconium.institutions(email: "your_email@example.com", autocomplete: true, q: "biodiv") # => Hash
Syconium.institutions(email: "your_email@example.com", autocomplete: true, q: "greenhou", search: "frogs") # => Hash
Filter institutions by attributes:
Syconium.institutions(email: "your_email@example.com", filter: 'is_oa:true') # => Hash
Group results by attributes:
Syconium.institutions(email: "your_email@example.com", group_by: 'oa_status') # => Hash
Get an institution by ID:
Syconium.institutions(email: "your_email@example.com", id: 'I157725225') # => Hash
Syconium.institutions(email: "your_email@example.com", id: 'ror:047426m28') # => Hash
Get a random institution:
Syconium.institutions(email: "your_email@example.com", random: true) # => Hash
Get a random sample of 25 institutions:
Syconium.institutions(email: "your_email@example.com", sample: 25) # => Hash
List keywords:
Syconium.keywords() # => Hash
Search keywords:
Syconium.keywords(email: "your_email@example.com", search: "biodiversity") # => Hash
For autocomplete, use the q parameter as the autocomplete field and also optionally you can use the filter and search parameters:
Syconium.keywords(email: "your_email@example.com", autocomplete: true, q: "biodiv") # => Hash
Syconium.keywords(email: "your_email@example.com", autocomplete: true, q: "ani", search: "evolution")) # => Hash
Filter keywords by attributes:
Syconium.keywords(email: "your_email@example.com", filter: 'works_count:1') # => Hash
Group results by attributes:
Syconium.keywords(email: "your_email@example.com", group_by: 'cited_by_count') # => Hash
Get a keywords by ID:
Syconium.keywords(email: "your_email@example.com", id: 'biodiversity-conservation') # => Hash
Get a random sample of 5 keywords:
Syconium.keywords(email: "your_email@example.com", sample: 25) # => Hash
List publishers:
Syconium.publishers() # => Hash
Search publishers:
Syconium.publishers(email: "your_email@example.com", search: "biodiversity") # => Hash
For autocomplete, use the q parameter as the autocomplete field and also optionally you can use the filter and search parameters:
Syconium.publishers(email: "your_email@example.com", autocomplete: true, q: "biodiv") # => Hash
Syconium.publishers(email: "your_email@example.com", autocomplete: true, q: "greenhou", search: "frogs") # => Hash
Filter publishers by attributes:
Syconium.publishers(email: "your_email@example.com", filter: 'hierarchy_level:0') # => Hash
Group results by attributes:
Syconium.publishers(email: "your_email@example.com", group_by: 'country_codes') # => Hash
Get a publishers by ID:
Syconium.publishers(email: "your_email@example.com", id: 'P4310315930') # => Hash
Syconium.publishers(email: "your_email@example.com", id: 'ror:047426m28') # => Hash
Get a random publishers:
Syconium.publishers(email: "your_email@example.com", random: true) # => Hash
Get a random sample of 25 publishers:
Syconium.publishers(email: "your_email@example.com", sample: 25) # => Hash
Sources are where works are hosted and include several types: conferences, journals, preprint repositories, institutional repositories, etc.
List sources:
Syconium.sources() # => Hash
Search sources:
Syconium.sources(email: "your_email@example.com", search: "biodiversity") # => Hash
For autocomplete, use the q parameter as the autocomplete field and also optionally you can use the filter and search parameters:
Syconium.sources(email: "your_email@example.com", autocomplete: true, q: "eco") # => Hash
Syconium.sources(email: "your_email@example.com", autocomplete: true, q: "eco", search: "biodiversity") # => Hash
Filter sources by attributes:
Syconium.sources(email: "your_email@example.com", filter: 'is_oa:true') # => Hash
Group results by attributes:
Syconium.sources(email: "your_email@example.com", group_by: 'oa_status') # => Hash
Get a sources by ID:
Syconium.sources(email: "your_email@example.com", id: 'S4306402618') # => Hash
Syconium.sources(email: "your_email@example.com", id: 'issn:1314-2828') # => Hash
Get a random source:
Syconium.sources(email: "your_email@example.com", random: true) # => Hash
Get a random sample of 25 sources:
Syconium.sources(email: "your_email@example.com", sample: 25) # => Hash
List topics:
Syconium.topics() # => Hash
Search topics:
Syconium.topics(email: "your_email@example.com", search: "biodiversity") # => Hash
For autocomplete, use the q parameter as the autocomplete field and also optionally you can use the filter and search parameters:
Syconium.topics(email: "your_email@example.com", autocomplete: true, q: "biodiv") # => Hash
Syconium.topics(email: "your_email@example.com", autocomplete: true, q: "greenhou", search: "frogs") # => Hash
Filter topics by attributes:
Syconium.topics(email: "your_email@example.com", filter: 'subfield.id:1311') # => Hash
Group results by attributes:
Syconium.topics(email: "your_email@example.com", group_by: 'subfield.id') # => Hash
Get a topics by ID:
Syconium.topics(email: "your_email@example.com", id: 'T10319') # => Hash
Get a random topics:
Syconium.topics(email: "your_email@example.com", random: true) # => Hash
Get a random sample of 25 works:
Syconium.topics(email: "your_email@example.com", sample: 25) # => Hash
List works:
Syconium.works() # => Hash
Search works:
Syconium.works(email: "your_email@example.com", search: "biodiversity") # => Hash
For autocomplete, use the q parameter as the autocomplete field and also optionally you can use the filter and search parameters:
Syconium.works(email: "your_email@example.com", autocomplete: true, q: "biodiv") # => Hash
Syconium.works(email: "your_email@example.com", autocomplete: true, q: "greenhou", search: "frogs") # => Hash
Filter works by attributes:
Syconium.works(email: "your_email@example.com", filter: 'is_oa:true') # => Hash
Group results by attributes:
Syconium.works(email: "your_email@example.com", group_by: 'oa_status') # => Hash
Get a work by ID:
Syconium.works(email: "your_email@example.com", id: 'pmid:33982150') # => Hash
Syconium.works(email: "your_email@example.com", id: 'doi:10.48550/arXiv.2205.01833') # => Hash
Syconium.works(email: "your_email@example.com", id: 'https://doi.org/10.48550/arXiv.2205.01833') # => Hash
Get a random work:
Syconium.works(email: "your_email@example.com", random: true) # => Hash
Get a random sample of 25 works:
Syconium.works(email: "your_email@example.com", sample: 25) # => Hash
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, update the CHANGELOG.md
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/SpeciesFileGroup/syconium. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT license. You can learn more about the MIT license on Wikipedia and compare it with other open source licenses at the Open Source Initiative.
Code of Conduct
Everyone interacting in the Syconium project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.