Skip to content

Commit

Permalink
Add OxfordDictionary::Client#thesaurus
Browse files Browse the repository at this point in the history
Oxford Dictionaries is updating their API to a new version which
includes quite a few changes:
https://developer.oxforddictionaries.com/version2

They are moving the thesaurus functionality to its own endpoint
(instead of having part of the entries endpoint).

Use this instead of `Client#entry_synonyms`, `Client#entry_antonyms`,
and `Client#entry_antonyms_synonyms`.
  • Loading branch information
swcraig committed Jun 23, 2019
1 parent 55376d5 commit 944a093
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/oxford_dictionary/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'oxford_dictionary/endpoints/lemmas'
require 'oxford_dictionary/endpoints/translations'
require 'oxford_dictionary/endpoints/sentences'
require 'oxford_dictionary/endpoints/thesaurus'

module OxfordDictionary
# The client object to interact with
Expand Down Expand Up @@ -71,6 +72,14 @@ def sentence(word:, language:, params: {})
sentence_endpoint.sentence(word: word, language: language, params: params)
end

def thesaurus(word:, language:, params: {})
thesaurus_endpoint.thesaurus(
word: word,
language: language,
params: params
)
end

private

def lemma_endpoint
Expand All @@ -95,6 +104,12 @@ def sentence_endpoint
)
end

def thesaurus_endpoint
@thesaurus_endpoint ||= OxfordDictionary::Endpoints::Thesaurus.new(
request_client: request_client
)
end

def request_client
@request_client ||=
OxfordDictionary::Request.new(app_id: @app_id, app_key: @app_key)
Expand Down
15 changes: 15 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@
end
end

describe '#thesaurus' do
subject { client.thesaurus(word: word, language: language, params: params) }
let(:word) { 'ace' }
let(:language) { 'en' }
let(:params) { {} }

it 'calls the Thesaurus endpoint with correct arguments' do
expect_any_instance_of(OxfordDictionary::Endpoints::Thesaurus).
to receive(:thesaurus).
with(word: word, language: language, params: params)

subject
end
end

describe '#entry_snake_case' do
let(:client) { described_class.new(app_id: app_id, app_key: app_key) }
subject do
Expand Down

0 comments on commit 944a093

Please sign in to comment.