Class: OxfordDictionary::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/oxford_dictionary/client.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
24
25
# 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

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id.



16
17
18
# File 'lib/oxford_dictionary/client.rb', line 16

def app_id
  @app_id
end

#app_keyObject (readonly)

Returns the value of attribute app_key.



16
17
18
# File 'lib/oxford_dictionary/client.rb', line 16

def app_key
  @app_key
end

Instance Method Details

#entry(word:, dataset:, params:) ⇒ Object



27
28
29
# 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: {}) ⇒ Object



31
32
33
# File 'lib/oxford_dictionary/client.rb', line 31

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

#search(language:, params:) ⇒ Object



56
57
58
# File 'lib/oxford_dictionary/client.rb', line 56

def search(language:, params:)
  search_endpoint.search(language: language, params: params)
end

#search_translation(source_language:, target_language:, params: {}) ⇒ Object



60
61
62
63
64
65
66
# 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: {}) ⇒ Object



44
45
46
# 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: {}) ⇒ Object



48
49
50
51
52
53
54
# 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: {}) ⇒ Object



35
36
37
38
39
40
41
42
# 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