Class: OxfordDictionary::Client

Inherits:
Object
  • Object
show all
Includes:
Endpoints::EntryEndpoint, Endpoints::InflectionEndpoint, Endpoints::SearchEndpoint, Endpoints::WordlistEndpoint
Defined in:
lib/oxford_dictionary/client.rb

Overview

The client object to interact with

Constant Summary

Constants included from Endpoints::WordlistEndpoint

Endpoints::WordlistEndpoint::ADVANCED_FILTERS, Endpoints::WordlistEndpoint::ENDPOINT

Constants included from DeprecatedRequest

DeprecatedRequest::ACCEPT_TYPE, DeprecatedRequest::ADVANCED_FILTERS, DeprecatedRequest::BASE, DeprecatedRequest::HTTP_OK

Constants included from Endpoints::SearchEndpoint

Endpoints::SearchEndpoint::ENDPOINT

Constants included from Endpoints::InflectionEndpoint

Endpoints::InflectionEndpoint::ENDPOINT

Constants included from Endpoints::EntryEndpoint

Endpoints::EntryEndpoint::ENDPOINT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Endpoints::WordlistEndpoint

#wordlist

Methods included from DeprecatedRequest

#request

Methods included from Endpoints::InflectionEndpoint

#inflection

Methods included from Endpoints::EntryEndpoint

#entry_antonyms, #entry_antonyms_synonyms, #entry_definitions, #entry_examples, #entry_pronunciations, #entry_sentences, #entry_synonyms, #entry_translations

Constructor Details

#initialize(params) ⇒ Client

Returns a new instance of Client.



25
26
27
28
29
30
31
32
# File 'lib/oxford_dictionary/client.rb', line 25

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.



23
24
25
# File 'lib/oxford_dictionary/client.rb', line 23

def app_id
  @app_id
end

#app_keyObject (readonly)

Returns the value of attribute app_key.



23
24
25
# File 'lib/oxford_dictionary/client.rb', line 23

def app_key
  @app_key
end

Instance Method Details

#entry(*args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/oxford_dictionary/client.rb', line 34

def entry(*args)
  if args.first.is_a?(Hash)
    args = args.first
    entry_endpoint.entry(
      word: args[:word],
      dataset: args[:dataset],
      params: args[:params]
    )
  else
    warn '''
      The V1 interface for this library is DEPRECATED and will become
      non-functional on June 30, 2019. Use the new V2 interface for this
      method instead. Reference github.com/swcraig/oxford-dictionary/pull/8
      for more information. Specifically check out
      OxfordDictionary::Endpoints::Entries#entry for the new interface.
    '''
    # Support V1 behaviour
    super(*args)
  end
end

#entry_snake_case(word:, dataset:, params: {}) ⇒ Object



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

def entry_snake_case(word:, dataset:, params: {})
  warn 'Client#entry_snake_case is DEPRECATED. Use Client#entry instead.'
  entry_endpoint.
    entry_snake_case(word: word, dataset: dataset, params: params)
end

#lemma(word:, language:, params: {}) ⇒ Object



61
62
63
# File 'lib/oxford_dictionary/client.rb', line 61

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

#search(*args) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/oxford_dictionary/client.rb', line 86

def search(*args)
  if args.first.is_a?(Hash)
    args = args.first
    search_endpoint.search(language: args[:language], params: args[:params])
  else
    warn '''
      Client#search without parameters is DEPRECATED.
      Using the method without named parameters will become
      non-functional on June 30, 2019. Use the new V2 interface for this
      method instead. Reference github.com/swcraig/oxford-dictionary/pull/15
      for more information. Specifically check out
      OxfordDictionary::Endpoints::Search#search for the new interface.
    '''
    if args[1].is_a?(Hash) && args[1][:translations]
      super(args[0], translations: args[1][:translations])
    else
      super(*args)
    end
  end
end

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



107
108
109
110
111
112
113
# File 'lib/oxford_dictionary/client.rb', line 107

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



74
75
76
# File 'lib/oxford_dictionary/client.rb', line 74

def sentence(word:, language:, params: {})
  sentence_endpoint.sentence(word: word, language: language, params: params)
end

#thesaurus(word:, language:, params: {}) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/oxford_dictionary/client.rb', line 78

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

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



65
66
67
68
69
70
71
72
# File 'lib/oxford_dictionary/client.rb', line 65

def translation(word:, source_language:, target_language:, params: {})
  translation_endpoint.translation(
    word: word,
    source_language: source_language,
    target_language: target_language,
    params: params
  )
end