https://github.com/swcraig/oxford_dictionary
:orange_book: A Ruby wrapper for the Oxford Dictionary API
https://github.com/swcraig/oxford_dictionary
api-wrapper dictionary oxford-dictionary ruby-wrapper wrapper
Last synced: 7 months ago
JSON representation
:orange_book: A Ruby wrapper for the Oxford Dictionary API
- Host: GitHub
- URL: https://github.com/swcraig/oxford_dictionary
- Owner: swcraig
- License: mit
- Created: 2016-11-28T00:31:11.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2021-01-15T23:55:26.000Z (about 5 years ago)
- Last Synced: 2024-10-31T08:26:12.435Z (over 1 year ago)
- Topics: api-wrapper, dictionary, oxford-dictionary, ruby-wrapper, wrapper
- Language: Ruby
- Homepage:
- Size: 145 KB
- Stars: 26
- Watchers: 2
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://travis-ci.org/swcraig/oxford_dictionary)
[](https://codeclimate.com/github/swcraig/oxford-dictionary/coverage)
[](https://codeclimate.com/github/swcraig/oxford-dictionary)
[](https://badge.fury.io/rb/oxford_dictionary)
# OxfordDictionary
Ruby wrapper to consume the [Oxford Dictionary API](https://developer.oxforddictionaries.com/documentation)
## Getting Started
$ gem install oxford_dictionary
# To use in your script/application
require 'oxford_dictionary'
After registering for an API key, setup the client:
```ruby
client = OxfordDictionary::Client.new(app_id: 'ID', app_key: 'SECRET')
client = OxfordDictionary.new(app_id: 'ID', app_key: 'SECRET')
```
### Usage Examples
This wrapper follows the schema laid out by the API quite closely. The data
schema for the different API calls can be found [here](https://developer.oxforddictionaries.com/documentation).
###### Entries
```ruby
entry = client.entry(word: 'vapid', dataset: 'en-gb', params: {})
# Access the first entry
# Refer to the API documentation for the schema of the returned data structure
first_lexical_entry = entry.lexicalEntries.first
# With some filters
filters = { lexicalCategory: 'Verb', domains: 'Art'}
client.entry(word: 'truth', dataset: 'en-gb', params: filters)
# To have multiple values for a single filter use comma separated terms
filters = { lexicalCategory: 'Verb,Noun' }
# You can also search for the results for different datasets
# Refer to the Oxford Dictionaries documentation for all the
# possible datasets
client.entry(word: 'ace', dataset: 'es', params: {})
# You can query for results from a specific "field"
# Refer to the Oxford Dictionaries documentation for all the
# possible fields
client.entry(word: 'explain', dataset: 'en-gb', params: { fields: 'examples' })
```
###### Lemmas
```ruby
client.lemma(word: 'condition', language: 'en', params: {})
```
###### Translations
```ruby
client.translation(
word: 'condition',
source_language: 'en',
target_language: 'es',
params: {}
)
```
###### Sentences
```ruby
client.sentence(word: 'paraphrase', language: 'en', params: {})
```
###### Search
```ruby
client.search(language: 'en-gb', params: { q: 'vapid' })
```
###### Thesaurus
```ruby
client.thesaurus(
word: 'book',
language: 'en',
params: { fields: 'synonyms,antonyms'}
)
# Or use { fields: 'synonyms' } for just synonyms
```
## Development
After checking out the repo, run `bin/setup` to install dependencies.
Run `bin/console` for an interactive prompt that will allow you to experiment.
## Contributing
Bug reports and pull requests are more than welcome!
Please make tests for anything that is added.
`bundle exec rake` will run rspec/rubocop.
#### Pull Requests
- Read [this often cited resource on contributing to open source projects on GitHub](https://gun.io/blog/how-to-github-fork-branch-and-pull-request)
- Fork the project
- Code and commit in your own feature branch
- Open a PR and nag me to close it!
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).