oxford_dictionary 2.0.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/CHANGELOG.md +3 -0
  4. data/README.md +3 -0
  5. data/Rakefile +5 -1
  6. data/lib/oxford_dictionary/client.rb +8 -249
  7. data/lib/oxford_dictionary/deserialize.rb +10 -0
  8. data/lib/oxford_dictionary/endpoints/endpoint.rb +1 -0
  9. data/lib/oxford_dictionary/endpoints/entries.rb +14 -10
  10. data/lib/oxford_dictionary/endpoints/lemmas.rb +18 -0
  11. data/lib/oxford_dictionary/endpoints/search.rb +4 -0
  12. data/lib/oxford_dictionary/endpoints/sentences.rb +4 -0
  13. data/lib/oxford_dictionary/endpoints/thesaurus.rb +4 -0
  14. data/lib/oxford_dictionary/endpoints/translations.rb +4 -0
  15. data/lib/oxford_dictionary/request.rb +2 -0
  16. data/lib/oxford_dictionary/version.rb +1 -1
  17. data/oxford_dictionary.gemspec +1 -2
  18. metadata +9 -24
  19. data/fixtures/vcr_cassettes/v1_entry.yml +0 -526
  20. data/fixtures/vcr_cassettes/v1_entry_antonym_synonym.yml +0 -42
  21. data/fixtures/vcr_cassettes/v1_entry_antonyms.yml +0 -42
  22. data/fixtures/vcr_cassettes/v1_entry_definitions.yml +0 -228
  23. data/fixtures/vcr_cassettes/v1_entry_error.yml +0 -49
  24. data/fixtures/vcr_cassettes/v1_entry_es.yml +0 -108
  25. data/fixtures/vcr_cassettes/v1_entry_examples.yml +0 -242
  26. data/fixtures/vcr_cassettes/v1_entry_past_nouns.yml +0 -49
  27. data/fixtures/vcr_cassettes/v1_entry_pronunciations.yml +0 -156
  28. data/fixtures/vcr_cassettes/v1_entry_synonyms.yml +0 -42
  29. data/fixtures/vcr_cassettes/v1_entry_us.yml +0 -526
  30. data/fixtures/vcr_cassettes/v1_inflection.yml +0 -74
  31. data/fixtures/vcr_cassettes/v1_inflection_filters.yml +0 -52
  32. data/fixtures/vcr_cassettes/v1_search.yml +0 -42
  33. data/fixtures/vcr_cassettes/v1_search_prefix.yml +0 -42
  34. data/fixtures/vcr_cassettes/v1_search_translation.yml +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97d848d8c66972c3a1bb87b3e19c218912c80f360edba2bd1e991e099fddb613
4
- data.tar.gz: c324040796efe1973e520938c96a343df15d08312262a10f1bf2d72f7091e7f4
3
+ metadata.gz: 99377db60cc25d19b09832803710b6302a81809713f160ed25c91991dbade46d
4
+ data.tar.gz: 98b102cbf2c4751b4d801b39e4aa7adc4d2e6a7d21a1eb42f5c156db2413da23
5
5
  SHA512:
6
- metadata.gz: ec6b3db6c5b7722bb06a69b14c20393c0d24d7574efdaa640f676f03341783b63e692d024f3175bddb468ad91e5f5c28442f44d8d2b7c5ef8eaed00851746371
7
- data.tar.gz: 4254c3c440308c62a3152a218646f9fba9dd4026149e001e4835e5b85de95d76ed62b6805f9e9a2cc50340b33e9d32fb8dc5fd4679a674e79dddbff6106ad271
6
+ metadata.gz: '03392263ed3ec7ff17d9b3347b2334285b62563c81b7475576977a356308117826579aa5680a2da86f8da712d9e86e4fe874fba6e8dcb586428dcc472b503c8a'
7
+ data.tar.gz: 705ea67f3ca0a7d87b3a16fa776c321f78e35718dacb985478bbff08d9259656ecfa9fda5981fa81172762b0f82a7f58ad2e74f8933103d2f29bfbd49e5cf13e
@@ -0,0 +1,5 @@
1
+ Lint/ImplicitStringConcatenation:
2
+ Enabled: false
3
+
4
+ Style/DotPosition:
5
+ EnforcedStyle: trailing
@@ -1,5 +1,8 @@
1
1
  ## OxfordDictionary master (unreleased)
2
2
 
3
+ ## OxfordDictionary 3.0.0 (2019-08-13)
4
+ - Remove support for all V1 API calls
5
+
3
6
  ## OxfordDictionary 2.0.0 (2019-06-29)
4
7
  - Remove wordlist endpoint
5
8
  [\#20](https://github.com/swcraig/oxford-dictionary/pull/20)
data/README.md CHANGED
@@ -34,6 +34,9 @@ first_lexical_entry = entry.lexicalEntries.first
34
34
  filters = { lexicalCategory: 'Verb', domains: 'Art'}
35
35
  client.entry(word: 'truth', dataset: 'en-gb', params: filters)
36
36
 
37
+ # To have multiple values for a single filter use comma separated terms
38
+ filters = { lexicalCategory: 'Verb,Noun' }
39
+
37
40
  # You can also search for the results for different datasets
38
41
  # Refer to the Oxford Dictionaries documentation for all the
39
42
  # possible datasets
data/Rakefile CHANGED
@@ -3,4 +3,8 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task default: [:spec]
6
+ task default: [:spec, :rubocop]
7
+
8
+ task :rubocop do
9
+ sh 'rubocop'
10
+ end
@@ -8,7 +8,10 @@ require 'oxford_dictionary/endpoints/search'
8
8
  require 'oxford_dictionary/request'
9
9
 
10
10
  module OxfordDictionary
11
- # The client object to interact with
11
+ # Our client class to interface with the different API endpoints
12
+ # This should be, in general, the only touchpoint for library use
13
+ #
14
+ # OxfordDictionary::Client.new is also aliased to OxfordDictionary.new
12
15
  class Client
13
16
  attr_reader :app_id, :app_key
14
17
 
@@ -21,183 +24,8 @@ module OxfordDictionary
21
24
  end
22
25
  end
23
26
 
24
- def entry(*args)
25
- if args.first.is_a?(Hash)
26
- args = args.first
27
- entry_endpoint.entry(
28
- word: args[:word],
29
- dataset: args[:dataset],
30
- params: args[:params]
31
- )
32
- else
33
- warn '''
34
- The V1 interface for this library is DEPRECATED.
35
- Use the new V2 interface for this
36
- method instead. Reference github.com/swcraig/oxford-dictionary/pull/8
37
- for more information. Specifically check out
38
- OxfordDictionary::Endpoints::Entries#entry for the new interface.
39
- '''
40
- # Try our best
41
- dataset = args[1].is_a?(Hash) && args[1][:lang] || 'en-gb'
42
- has_lang = args[1].is_a?(Hash) && args[1][:lang]
43
- args[1].delete(:lang) if has_lang
44
-
45
- params = args[1]&.map do |key, value|
46
- if value.is_a?(Array)
47
- [key, value.join(',')]
48
- else
49
- [key, value]
50
- end
51
- end.to_h
52
- parameters = params || {}
53
- entry(word: args.first, dataset: dataset, params: parameters)
54
- end
55
- end
56
-
57
- def entry_definitions(*args)
58
- warn '''
59
- Client#entry_defintions is DEPRECATED.
60
- Use Client#entry instead. Reference
61
- https://github.com/swcraig/oxford-dictionary/pull/8 for more
62
- information. Check out OxfordDictionary::Endpoints::Entries for the
63
- interface to use. Specifically use it with
64
- params: { fields: \'definitions\' }
65
- '''
66
-
67
- dataset = args[1].is_a?(Hash) && args[1][:lang] || 'en-gb'
68
- entry(
69
- word: args.first,
70
- dataset: dataset,
71
- params: { fields: 'definitions' }
72
- )
73
- end
74
-
75
- def entry_examples(*args)
76
- warn '''
77
- Client#entry_examples is DEPRECATED. Use Client#entry instead. Reference
78
- https://github.com/swcraig/oxford-dictionary/pull/8 for more
79
- information. Check out OxfordDictionary::Endpoints::Entries for the
80
- interface to use. Specifically use it with
81
- params: { fields: \'examples\' }
82
- '''
83
-
84
- dataset = args[1].is_a?(Hash) && args[1][:lang] || 'en-gb'
85
- entry(
86
- word: args.first,
87
- dataset: dataset,
88
- params: { fields: 'examples' }
89
- )
90
- end
91
-
92
- def entry_pronunciations(*args)
93
- warn '''
94
- Client#entry_pronunciations is DEPRECATED.
95
- Use Client#entry instead. Reference
96
- https://github.com/swcraig/oxford-dictionary/pull/8 for more
97
- information. Check out OxfordDictionary::Endpoints::Entries for the
98
- interface to use. Specifically use it with
99
- params: { fields: \'pronunciations\' }
100
- '''
101
-
102
- dataset = args[1].is_a?(Hash) && args[1][:lang] || 'en-gb'
103
- entry(
104
- word: args.first,
105
- dataset: dataset,
106
- params: { fields: 'pronunciations' }
107
- )
108
- end
109
-
110
- def entry_sentences(*args)
111
- warn '''
112
- Client#entry_sentences is DEPRECATED.
113
- Use Client#sentence instead. Reference
114
- https://github.com/swcraig/oxford-dictionary/pull/13 for more
115
- information. Check out OxfordDictionary::Endpoints::Sentences for the
116
- interface to use.
117
- '''
118
-
119
- dataset = args[1].is_a?(Hash) && args[1][:lang] || 'en'
120
- sentence(
121
- word: args.first,
122
- language: dataset,
123
- params: {}
124
- )
125
- end
126
-
127
- def entry_antonyms(*args)
128
- warn '''
129
- Client#entry_antonyms is DEPRECATED.
130
- Use Client#thesaurus instead. Reference
131
- https://github.com/swcraig/oxford-dictionary/pull/13 for more
132
- information. Check out OxfordDictionary::Endpoints::Thesaurus for the
133
- interface to use. Specifically use it with
134
- params: { fields: \'antonyms\' }
135
- '''
136
-
137
- thesaurus(
138
- word: args.first,
139
- language: 'en',
140
- params: { fields: 'antonyms' }
141
- )
142
- end
143
-
144
- def entry_synonyms(*args)
145
- warn '''
146
- Client#entry_synonyms is DEPRECATED.
147
- Use Client#thesaurus instead. Reference
148
- https://github.com/swcraig/oxford-dictionary/pull/13 for more
149
- information. Check out OxfordDictionary::Endpoints::Thesaurus for the
150
- interface to use. Specifically use it with
151
- params: { fields: \'synonyms\' }
152
- '''
153
-
154
- thesaurus(
155
- word: args.first,
156
- language: 'en',
157
- params: { fields: 'synonyms' }
158
- )
159
- end
160
-
161
- def entry_antonyms_synonyms(*args)
162
- warn '''
163
- Client#entry_antonyms_synonyms is DEPRECATED.
164
- Use Client#thesaurus instead. Reference
165
- https://github.com/swcraig/oxford-dictionary/pull/14 for more
166
- information. Check out OxfordDictionary::Endpoints::Thesaurus for the
167
- interface to use. Specifically use it with
168
- params: { fields: \'synonyms,antonyms\' }
169
- '''
170
-
171
- thesaurus(
172
- word: args.first,
173
- language: 'en',
174
- params: { fields: 'antonyms,synonyms' }
175
- )
176
- end
177
-
178
- def entry_translations(*args)
179
- warn '''
180
- Client#entry_translations is DEPRECATED.
181
- Use Client#translation instead. Reference
182
- https://github.com/swcraig/oxford-dictionary/pull/12 for more
183
- information. Check out OxfordDictionary::Endpoints::Translations for the
184
- interface to use.
185
- '''
186
-
187
- language = args[1] && args[1][:translations] || 'es'
188
- translation(
189
- word: args.first,
190
- source_language: 'en-us',
191
- target_language: language,
192
- params: {}
193
- )
194
- end
195
-
196
- def entry_snake_case(word:, dataset:, params: {})
197
- warn 'Client#entry_snake_case is DEPRECATED. Use Client#entry instead.'
198
-
199
- entry_endpoint.
200
- entry_snake_case(word: word, dataset: dataset, params: params)
27
+ def entry(word:, dataset:, params:)
28
+ entry_endpoint.entry(word: word, dataset: dataset, params: params)
201
29
  end
202
30
 
203
31
  def lemma(word:, language:, params: {})
@@ -225,52 +53,8 @@ module OxfordDictionary
225
53
  )
226
54
  end
227
55
 
228
- def search(*args)
229
- if args.first.is_a?(Hash)
230
- args = args.first
231
- search_endpoint.search(language: args[:language], params: args[:params])
232
- else
233
- warn '''
234
- Client#search without parameters is DEPRECATED.
235
- Use the new V2 interface for this
236
- method instead. Reference github.com/swcraig/oxford-dictionary/pull/15
237
- for more information. Specifically check out
238
- OxfordDictionary::Endpoints::Search#search for the new interface.
239
- '''
240
-
241
- language_parameter = args[1].is_a?(Hash) && args[1][:lang]
242
- language = language_parameter || 'en-gb'
243
- args[1].delete(:lang) if language_parameter
244
-
245
- if args[1].is_a?(Hash) && args[1][:translations]
246
- target_language = args[1][:translations]
247
- args[1].delete(:translations)
248
-
249
- params = args[1]&.map do |key, value|
250
- if value.is_a?(Array)
251
- [key, value.join(',')]
252
- else
253
- [key, value]
254
- end
255
- end.to_h
256
- parameters = params&.merge(q: args[0]) || {}
257
- search_translation(
258
- source_language: language,
259
- target_language: target_language,
260
- params: parameters
261
- )
262
- else
263
- params = args[1]&.map do |key, value|
264
- if value.is_a?(Array)
265
- [key, value.join(',')]
266
- else
267
- [key, value]
268
- end
269
- end.to_h
270
- parameters = params&.merge(q: args[0]) || {}
271
- search_endpoint.search(language: language, params: parameters)
272
- end
273
- end
56
+ def search(language:, params:)
57
+ search_endpoint.search(language: language, params: params)
274
58
  end
275
59
 
276
60
  def search_translation(source_language:, target_language:, params: {})
@@ -281,31 +65,6 @@ module OxfordDictionary
281
65
  )
282
66
  end
283
67
 
284
- def inflection(*args)
285
- warn '''
286
- Client#inflection is DEPRECATED.
287
- Use Client#lemma instead. Reference
288
- github.com/swcraig/oxford-dictionary/pull/10 for for more information.
289
- Check out OxfordDictionary::Endpoints::Lemmas#lemma for the interface
290
- to use.
291
- '''
292
-
293
- language_parameter = args[1].is_a?(Hash) && args[1][:lang]
294
- language = language_parameter || 'en'
295
- args[1].delete(:lang) if language_parameter
296
-
297
- params = args[1]&.map do |key, value|
298
- if value.is_a?(Array)
299
- [key, value.join(',')]
300
- else
301
- [key, value]
302
- end
303
- end.to_h
304
- parameters = params || {}
305
-
306
- lemma(word: args.first, language: language, params: parameters)
307
- end
308
-
309
68
  private
310
69
 
311
70
  def lemma_endpoint
@@ -1,7 +1,17 @@
1
1
  require 'json'
2
2
 
3
3
  module OxfordDictionary
4
+ # A small service object that parses a JSON payload into
5
+ # an OpenStruct recursively. The keys of the OpenStruct
6
+ # are in camelCase, not snake_case. This keeps the struct
7
+ # more representative of the JSON in the response.
4
8
  class Deserialize
9
+ # Parses a JSON payload into an OpenStruct
10
+ # Nested objects are also parsed into OpenStructs
11
+ #
12
+ # @param [String] payload a JSON string
13
+ #
14
+ # @return [OpenStruct] the JSON parsed into OpenStructs recursively
5
15
  def call(payload)
6
16
  JSON.parse(payload, object_class: OpenStruct)
7
17
  end
@@ -2,6 +2,7 @@ require 'oxford_dictionary/deserialize'
2
2
 
3
3
  module OxfordDictionary
4
4
  module Endpoints
5
+ # The common functionality (and dependency initialization) of all endpoints
5
6
  class Endpoint
6
7
  def initialize(request_client:)
7
8
  @request_client = request_client
@@ -1,11 +1,24 @@
1
1
  require 'oxford_dictionary/endpoints/endpoint'
2
- require 'plissken'
3
2
 
4
3
  module OxfordDictionary
5
4
  module Endpoints
5
+ # Interface for the /entries endpoint
6
+ #
7
+ # API documentation can be found here:
8
+ # https://developer.oxforddictionaries.com/documentation
6
9
  class Entries < Endpoint
7
10
  ENDPOINT = 'entries'.freeze
8
11
 
12
+ # Return all the entries for a word
13
+ #
14
+ # @param [String] word the word to search for
15
+ # @param [String] dataset the dataset to search in
16
+ # @param [Hash] params the query parameters in the request
17
+ #
18
+ # @example Search for all domains of 'vapid' from the en-gb dataset
19
+ # entry(word: 'vapid', dataset: 'en-gb', params: { fields: 'domains' })
20
+ #
21
+ # @return [OpenStruct] the JSON response parsed into an OpenStruct
9
22
  def entry(word:, dataset:, params: {})
10
23
  path = "#{ENDPOINT}/#{dataset}/#{word}"
11
24
  uri = request_uri(path: path, params: params)
@@ -13,15 +26,6 @@ module OxfordDictionary
13
26
  response = @request_client.get(uri: uri)
14
27
  deserialize.call(response.body)
15
28
  end
16
-
17
- def entry_snake_case(word:, dataset:, params: {})
18
- path = "#{ENDPOINT}/#{dataset}/#{word}"
19
- uri = request_uri(path: path, params: params)
20
-
21
- response = @request_client.get(uri: uri)
22
- snake_keys = JSON.parse(response.body).to_snake_keys
23
- deserialize.call(JSON.generate(snake_keys))
24
- end
25
29
  end
26
30
  end
27
31
  end
@@ -2,9 +2,27 @@ require 'oxford_dictionary/endpoints/endpoint'
2
2
 
3
3
  module OxfordDictionary
4
4
  module Endpoints
5
+ # Interface for the /lemmas endpoint
6
+ #
7
+ # API documentation can be found here:
8
+ # https://developer.oxforddictionaries.com/documentation
5
9
  class Lemmas < Endpoint
6
10
  ENDPOINT = 'lemmas'.freeze
7
11
 
12
+ # Returns all possible lemmas for a word
13
+ #
14
+ # @param [String] word the inflected word to search for
15
+ # @param [String] language the language to search in
16
+ # @param [Hash] params the query parameters in the request
17
+ #
18
+ # @example Search for the verb lemmas of 'running' in 'en'
19
+ # lemma(
20
+ # word: 'running',
21
+ # language: 'en',
22
+ # params: { lexicalCategory: 'verb' }
23
+ # )
24
+ #
25
+ # @return [OpenStruct] the JSON response parsed into an OpenStruct
8
26
  def lemma(word:, language:, params: {})
9
27
  path = "#{ENDPOINT}/#{language}/#{word}"
10
28
  uri = request_uri(path: path, params: params)
@@ -2,6 +2,10 @@ require 'oxford_dictionary/endpoints/endpoint'
2
2
 
3
3
  module OxfordDictionary
4
4
  module Endpoints
5
+ # Interface for the /search endpoint
6
+ #
7
+ # API documentation can be found here:
8
+ # https://developer.oxforddictionaries.com/documentation
5
9
  class Search < Endpoint
6
10
  ENDPOINT = 'search'.freeze
7
11
 
@@ -2,6 +2,10 @@ require 'oxford_dictionary/endpoints/endpoint'
2
2
 
3
3
  module OxfordDictionary
4
4
  module Endpoints
5
+ # Interface for the /sentences endpoint
6
+ #
7
+ # API documentation can be found here:
8
+ # https://developer.oxforddictionaries.com/documentation
5
9
  class Sentences < Endpoint
6
10
  ENDPOINT = 'sentences'.freeze
7
11