Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OxfordDictionary::Endpoints::Lemmas #10

Merged
merged 5 commits into from
Jun 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task default: [:spec, :rubocop]

task :rubocop do
sh 'rubocop'
end
task default: [:spec]
95 changes: 95 additions & 0 deletions fixtures/vcr_cassettes/lemmas_lemma-es.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions fixtures/vcr_cassettes/lemmas_lemma-verbs.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions fixtures/vcr_cassettes/lemmas_lemma.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lib/oxford_dictionary/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
require 'oxford_dictionary/endpoints/search_endpoint'
require 'oxford_dictionary/endpoints/wordlist_endpoint'

require 'oxford_dictionary/endpoints/entries'
require 'oxford_dictionary/endpoints/lemmas'

module OxfordDictionary
# The client object to interact with
class Client
Expand Down Expand Up @@ -49,8 +52,17 @@ def entry_snake_case(word:, dataset:, params: {})
entry_snake_case(word: word, dataset: dataset, params: params)
end

def lemma(word:, language:, params: {})
lemma_endpoint.lemma(word: word, language: language, params: params)
end

private

def lemma_endpoint
@lemma_endpoint ||=
OxfordDictionary::Endpoints::Lemmas.new(request_client: request_client)
end

def entry_endpoint
@entry_endpoint ||=
OxfordDictionary::Endpoints::Entries.new(request_client: request_client)
Expand Down
7 changes: 7 additions & 0 deletions lib/oxford_dictionary/endpoints/inflection_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ module InflectionEndpoint
ENDPOINT = 'inflections'.freeze

def inflection(query, params = {})
warn '''
Client#inflection is DEPRECATED and will become non-functional
on June 30, 2019. Use Client#lemma instead. Reference
github.com/swcraig/oxford-dictionary/pull/10 for for more information.
Check out OxfordDictionary::Endpoints::Lemmas#lemma for the interface
to use.
'''
EntryResponse.new(request(ENDPOINT, query, params)['results'][0])
end
end
Expand Down
31 changes: 31 additions & 0 deletions lib/oxford_dictionary/endpoints/lemmas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'oxford_dictionary/deserialize'

module OxfordDictionary
module Endpoints
class Lemmas
ENDPOINT = 'lemmas'.freeze

def initialize(request_client:)
@request_client = request_client
end

def lemma(word:, language:, params: {})
query_string = "#{ENDPOINT}/#{language}/#{word}"
uri = URI(query_string)

unless params.empty?
uri.query = URI.encode_www_form(params)
end

response = @request_client.get(uri: uri)
deserialize.call(response.body)
end

private

def deserialize
@deserialize ||= OxfordDictionary::Deserialize.new
end
end
end
end
Loading