class OxfordDictionary::Client

Our client class to interface with the different API endpoints This should be, in general, the only touchpoint for library use

OxfordDictionary::Client.new is also aliased to OxfordDictionary.new

Attributes

app_id[R]
app_key[R]

Public Class Methods

new(params) click to toggle source
# File lib/oxford_dictionary/client.rb, line 18
def initialize(params)
  unless params.is_a?(Hash) && params.key?(:app_id) && params.key?(:app_key)
    raise(ArgumentError, 'API id and key required.')
  end
  params.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Public Instance Methods

entry(word:, dataset:, params:) click to toggle source
# File lib/oxford_dictionary/client.rb, line 27
def entry(word:, dataset:, params:)
  entry_endpoint.entry(word: word, dataset: dataset, params: params)
end
lemma(word:, language:, params: {}) click to toggle source
# File lib/oxford_dictionary/client.rb, line 31
def lemma(word:, language:, params: {})
  lemma_endpoint.lemma(word: word, language: language, params: params)
end
search_translation(source_language:, target_language:, params: {}) click to toggle source
# File lib/oxford_dictionary/client.rb, line 60
def search_translation(source_language:, target_language:, params: {})
  search_endpoint.search_translation(
    source_language: source_language,
    target_language: target_language,
    params: params
  )
end
sentence(word:, language:, params: {}) click to toggle source
# File lib/oxford_dictionary/client.rb, line 44
def sentence(word:, language:, params: {})
  sentence_endpoint.sentence(word: word, language: language, params: params)
end
thesaurus(word:, language:, params: {}) click to toggle source
# File lib/oxford_dictionary/client.rb, line 48
def thesaurus(word:, language:, params: {})
  thesaurus_endpoint.thesaurus(
    word: word,
    language: language,
    params: params
  )
end
translation(word:, source_language:, target_language:, params: {}) click to toggle source
# File lib/oxford_dictionary/client.rb, line 35
def translation(word:, source_language:, target_language:, params: {})
  translation_endpoint.translation(
    word: word,
    source_language: source_language,
    target_language: target_language,
    params: params
  )
end

Private Instance Methods

entry_endpoint() click to toggle source
# File lib/oxford_dictionary/client.rb, line 81
def entry_endpoint
  @entry_endpoint ||=
    OxfordDictionary::Endpoints::Entries.new(request_client: request_client)
end
lemma_endpoint() click to toggle source
# File lib/oxford_dictionary/client.rb, line 70
def lemma_endpoint
  @lemma_endpoint ||=
    OxfordDictionary::Endpoints::Lemmas.new(request_client: request_client)
end
request_client() click to toggle source
# File lib/oxford_dictionary/client.rb, line 104
def request_client
  @request_client ||=
    OxfordDictionary::Request.new(app_id: @app_id, app_key: @app_key)
end
search_endpoint() click to toggle source
# File lib/oxford_dictionary/client.rb, line 92
def search_endpoint
  @search_endpoint ||= OxfordDictionary::Endpoints::Search.new(
    request_client: request_client
  )
end
sentence_endpoint() click to toggle source
# File lib/oxford_dictionary/client.rb, line 86
def sentence_endpoint
  @sentence_endpoint ||= OxfordDictionary::Endpoints::Sentences.new(
    request_client: request_client
  )
end
thesaurus_endpoint() click to toggle source
# File lib/oxford_dictionary/client.rb, line 98
def thesaurus_endpoint
  @thesaurus_endpoint ||= OxfordDictionary::Endpoints::Thesaurus.new(
    request_client: request_client
  )
end
translation_endpoint() click to toggle source
# File lib/oxford_dictionary/client.rb, line 75
def translation_endpoint
  @translation_endpoint ||= OxfordDictionary::Endpoints::Translations.new(
    request_client: request_client
  )
end