oxford_dictionary 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 181397797e822f74e2ffd2904834d9d057f611f166c3f1b4cc717f79ed899ad3
4
- data.tar.gz: 14ed048797dafe19066a7fb9ad94ec21d6f776a8512dab20c389bead210da32b
3
+ metadata.gz: 78ec18e159b5cbee6d642ed69123ce7478c2d578c9a8cac8ebc87462eb9f44fe
4
+ data.tar.gz: fd8b47b41a3693f5dcd55c9fa97b260ae9278405a12b596ad3fd9276b2e7ab1c
5
5
  SHA512:
6
- metadata.gz: e6d27d507afb9196658b8c07faa4170f1d2ccf3fe3fa5e216095eae04d027a87b04f189d390b898eebf40e6cf793179582d9b66408e691606f4830b92eb1969a
7
- data.tar.gz: 47cf60f38d246938585962dd2d8aeead434337331cef0fd4c49e1cb40eb4b34b206475973db9503203f71b3ad2836f0a9197929852925172fad12ee73e5ff058
6
+ metadata.gz: 1e6eeb2e17ceb1be3473863ac38a94f44a0f4f4ae6101a31ccf00504d84d90380484c51a33e3e20f066dae77a70840930c334165b4689848bb27b92701d0e7e0
7
+ data.tar.gz: 1d57ef61a92b985d85d8ca5be8890852c8c734c7dea76f9e96c6761a03d01c15b0f1f5bf8ff58af0137138d4aad98897efedf9e8c40849597a1de0b1449df4c6
@@ -1,5 +1,16 @@
1
1
  ## OxfordDictionary master (unreleased)
2
2
 
3
+ ## OxfordDictionary 1.3.0 (2019-06-22)
4
+
5
+ - Add V2 translations support
6
+ [\#10](https://github.com/swcraig/oxford-dictionary/pull/12)
7
+ - Add V2 sentences support
8
+ [\#10](https://github.com/swcraig/oxford-dictionary/pull/13)
9
+ - Add V2 thesaurus support
10
+ [\#10](https://github.com/swcraig/oxford-dictionary/pull/14)
11
+ - Add V2 search support
12
+ [\#10](https://github.com/swcraig/oxford-dictionary/pull/15)
13
+
3
14
  ## OxfordDictionary 1.2.0 (2019-06-22)
4
15
 
5
16
  - Add V2 lemmas support
@@ -5,6 +5,10 @@ require 'oxford_dictionary/endpoints/wordlist_endpoint'
5
5
 
6
6
  require 'oxford_dictionary/endpoints/entries'
7
7
  require 'oxford_dictionary/endpoints/lemmas'
8
+ require 'oxford_dictionary/endpoints/translations'
9
+ require 'oxford_dictionary/endpoints/sentences'
10
+ require 'oxford_dictionary/endpoints/thesaurus'
11
+ require 'oxford_dictionary/endpoints/search'
8
12
 
9
13
  module OxfordDictionary
10
14
  # The client object to interact with
@@ -28,11 +32,11 @@ module OxfordDictionary
28
32
  def entry(*args)
29
33
  if args.first.is_a?(Hash)
30
34
  args = args.first
31
- entry_endpoint.entry(
32
- word: args[:word],
33
- dataset: args[:dataset],
34
- params: args[:params]
35
- )
35
+ entry_endpoint.entry(
36
+ word: args[:word],
37
+ dataset: args[:dataset],
38
+ params: args[:params]
39
+ )
36
40
  else
37
41
  warn '''
38
42
  The V1 interface for this library is DEPRECATED and will become
@@ -56,6 +60,57 @@ module OxfordDictionary
56
60
  lemma_endpoint.lemma(word: word, language: language, params: params)
57
61
  end
58
62
 
63
+ def translation(word:, source_language:, target_language:, params: {})
64
+ translation_endpoint.translation(
65
+ word: word,
66
+ source_language: source_language,
67
+ target_language: target_language,
68
+ params: params
69
+ )
70
+ end
71
+
72
+ def sentence(word:, language:, params: {})
73
+ sentence_endpoint.sentence(word: word, language: language, params: params)
74
+ end
75
+
76
+ def thesaurus(word:, language:, params: {})
77
+ thesaurus_endpoint.thesaurus(
78
+ word: word,
79
+ language: language,
80
+ params: params
81
+ )
82
+ end
83
+
84
+ def search(*args)
85
+ if args.first.is_a?(Hash)
86
+ args = args.first
87
+ search_endpoint.search(language: args[:language], params: args[:params])
88
+ else
89
+ warn '''
90
+ Client#search without parameters is DEPRECATED.
91
+ Using the method without named parameters will become
92
+ non-functional on June 30, 2019. Use the new V2 interface for this
93
+ method instead. Reference github.com/swcraig/oxford-dictionary/pull/15
94
+ for more information. Specifically check out
95
+ OxfordDictionary::Endpoints::Search#search for the new interface.
96
+ '''
97
+ if args[1].is_a?(Hash) && args[1][:translations]
98
+ super(args[0], translations: args[1][:translations])
99
+ else
100
+ super(*args)
101
+ end
102
+ end
103
+ end
104
+
105
+ def search_translation(source_language:, target_language:, params: {})
106
+ search_endpoint.search_translation(
107
+ source_language: source_language,
108
+ target_language: target_language,
109
+ params: params
110
+ )
111
+ end
112
+
113
+
59
114
  private
60
115
 
61
116
  def lemma_endpoint
@@ -63,11 +118,35 @@ module OxfordDictionary
63
118
  OxfordDictionary::Endpoints::Lemmas.new(request_client: request_client)
64
119
  end
65
120
 
121
+ def translation_endpoint
122
+ @translation_endpoint ||= OxfordDictionary::Endpoints::Translations.new(
123
+ request_client: request_client
124
+ )
125
+ end
126
+
66
127
  def entry_endpoint
67
128
  @entry_endpoint ||=
68
129
  OxfordDictionary::Endpoints::Entries.new(request_client: request_client)
69
130
  end
70
131
 
132
+ def sentence_endpoint
133
+ @sentence_endpoint ||= OxfordDictionary::Endpoints::Sentences.new(
134
+ request_client: request_client
135
+ )
136
+ end
137
+
138
+ def search_endpoint
139
+ @search_endpoint ||= OxfordDictionary::Endpoints::Search.new(
140
+ request_client: request_client
141
+ )
142
+ end
143
+
144
+ def thesaurus_endpoint
145
+ @thesaurus_endpoint ||= OxfordDictionary::Endpoints::Thesaurus.new(
146
+ request_client: request_client
147
+ )
148
+ end
149
+
71
150
  def request_client
72
151
  @request_client ||=
73
152
  OxfordDictionary::Request.new(app_id: @app_id, app_key: @app_key)
@@ -0,0 +1,17 @@
1
+ require 'oxford_dictionary/deserialize'
2
+
3
+ module OxfordDictionary
4
+ module Endpoints
5
+ class Endpoint
6
+ def initialize(request_client:)
7
+ @request_client = request_client
8
+ end
9
+
10
+ private
11
+
12
+ def deserialize
13
+ @deserialize ||= OxfordDictionary::Deserialize.new
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,15 +1,11 @@
1
- require 'oxford_dictionary/deserialize'
1
+ require 'oxford_dictionary/endpoints/endpoint'
2
2
  require 'plissken'
3
3
 
4
4
  module OxfordDictionary
5
5
  module Endpoints
6
- class Entries
6
+ class Entries < Endpoint
7
7
  ENDPOINT = 'entries'.freeze
8
8
 
9
- def initialize(request_client:)
10
- @request_client = request_client
11
- end
12
-
13
9
  def entry(word:, dataset:, params: {})
14
10
  query_string = "#{ENDPOINT}/#{dataset}/#{word}"
15
11
  uri = URI(query_string)
@@ -34,12 +30,6 @@ module OxfordDictionary
34
30
  snake_keys = JSON.parse(response.body).to_snake_keys
35
31
  deserialize.call(JSON.generate(snake_keys))
36
32
  end
37
-
38
- private
39
-
40
- def deserialize
41
- @deserialize ||= OxfordDictionary::Deserialize.new
42
- end
43
33
  end
44
34
  end
45
35
  end
@@ -13,41 +13,110 @@ module OxfordDictionary
13
13
  end
14
14
 
15
15
  def entry_definitions(query, params = {})
16
+ warn '''
17
+ Client#entry_defintions is DEPRECATED and will become non-functional
18
+ on June 30, 2019. Use Client#entry instead. Reference
19
+ https://github.com/swcraig/oxford-dictionary/pull/8 for more
20
+ information. Check out OxfordDictionary::Endpoints::Entries for the
21
+ interface to use. Specifically use it with
22
+ params: { fields: \'definitions\' }
23
+ '''
24
+
16
25
  params[:end] = 'definitions'
17
26
  entry_request(query, params)
18
27
  end
19
28
 
20
29
  def entry_examples(query, params = {})
30
+ warn '''
31
+ Client#entry_examples is DEPRECATED and will become non-functional
32
+ on June 30, 2019. Use Client#entry instead. Reference
33
+ https://github.com/swcraig/oxford-dictionary/pull/8 for more
34
+ information. Check out OxfordDictionary::Endpoints::Entries for the
35
+ interface to use. Specifically use it with
36
+ params: { fields: \'examples\' }
37
+ '''
38
+
21
39
  params[:end] = 'examples'
22
40
  entry_request(query, params)
23
41
  end
24
42
 
25
43
  def entry_pronunciations(query, params = {})
44
+ warn '''
45
+ Client#entry_pronunciations is DEPRECATED and will become non-functional
46
+ on June 30, 2019. Use Client#entry instead. Reference
47
+ https://github.com/swcraig/oxford-dictionary/pull/8 for more
48
+ information. Check out OxfordDictionary::Endpoints::Entries for the
49
+ interface to use. Specifically use it with
50
+ params: { fields: \'pronunciations\' }
51
+ '''
52
+
26
53
  params[:end] = 'pronunciations'
27
54
  entry_request(query, params)
28
55
  end
29
56
 
30
57
  def entry_sentences(query, params = {})
58
+ warn '''
59
+ Client#entry_sentences is DEPRECATED and will become non-functional
60
+ on June 30, 2019. Use Client#sentence instead. Reference
61
+ https://github.com/swcraig/oxford-dictionary/pull/13 for more
62
+ information. Check out OxfordDictionary::Endpoints::Sentences for the
63
+ interface to use.
64
+ '''
65
+
31
66
  params[:end] = 'sentences'
32
67
  entry_request(query, params)
33
68
  end
34
69
 
35
70
  def entry_antonyms(query, params = {})
71
+ warn '''
72
+ Client#entry_antonyms is DEPRECATED and will become non-functional
73
+ on June 30, 2019. Use Client#thesaurus instead. Reference
74
+ https://github.com/swcraig/oxford-dictionary/pull/13 for more
75
+ information. Check out OxfordDictionary::Endpoints::Thesaurus for the
76
+ interface to use. Specifically use it with
77
+ params: { fields: \'antonyms\' }
78
+ '''
79
+
36
80
  params[:end] = 'antonyms'
37
81
  entry_request(query, params)
38
82
  end
39
83
 
40
84
  def entry_synonyms(query, params = {})
85
+ warn '''
86
+ Client#entry_synonyms is DEPRECATED and will become non-functional
87
+ on June 30, 2019. Use Client#thesaurus instead. Reference
88
+ https://github.com/swcraig/oxford-dictionary/pull/13 for more
89
+ information. Check out OxfordDictionary::Endpoints::Thesaurus for the
90
+ interface to use. Specifically use it with
91
+ params: { fields: \'synonyms\' }
92
+ '''
93
+
41
94
  params[:end] = 'synonyms'
42
95
  entry_request(query, params)
43
96
  end
44
97
 
45
98
  def entry_antonyms_synonyms(query, params = {})
99
+ warn '''
100
+ Client#entry_antonyms_synonyms is DEPRECATED and will be non-functional
101
+ on June 30, 2019. Use Client#thesaurus instead. Reference
102
+ https://github.com/swcraig/oxford-dictionary/pull/14 for more
103
+ information. Check out OxfordDictionary::Endpoints::Thesaurus for the
104
+ interface to use. Specifically use it with
105
+ params: { fields: \'synonyms,antonyms\' }
106
+ '''
107
+
46
108
  params[:end] = 'synonyms;antonyms'
47
109
  entry_request(query, params)
48
110
  end
49
111
 
50
112
  def entry_translations(query, params = {})
113
+ warn '''
114
+ Client#entry_translations is DEPRECATED and will become non-functional
115
+ on June 30, 2019. Use Client#translation instead. Reference
116
+ https://github.com/swcraig/oxford-dictionary/pull/12 for more
117
+ information. Check out OxfordDictionary::Endpoints::Translations for the
118
+ interface to use.
119
+ '''
51
120
  params.key?(:translations) || params[:translations] = 'es'
52
121
  entry_request(query, params)
53
122
  end
@@ -1,14 +1,10 @@
1
- require 'oxford_dictionary/deserialize'
1
+ require 'oxford_dictionary/endpoints/endpoint'
2
2
 
3
3
  module OxfordDictionary
4
4
  module Endpoints
5
- class Lemmas
5
+ class Lemmas < Endpoint
6
6
  ENDPOINT = 'lemmas'.freeze
7
7
 
8
- def initialize(request_client:)
9
- @request_client = request_client
10
- end
11
-
12
8
  def lemma(word:, language:, params: {})
13
9
  query_string = "#{ENDPOINT}/#{language}/#{word}"
14
10
  uri = URI(query_string)
@@ -20,12 +16,6 @@ module OxfordDictionary
20
16
  response = @request_client.get(uri: uri)
21
17
  deserialize.call(response.body)
22
18
  end
23
-
24
- private
25
-
26
- def deserialize
27
- @deserialize ||= OxfordDictionary::Deserialize.new
28
- end
29
19
  end
30
20
  end
31
21
  end
@@ -0,0 +1,34 @@
1
+ require 'oxford_dictionary/endpoints/endpoint'
2
+
3
+ module OxfordDictionary
4
+ module Endpoints
5
+ class Search < Endpoint
6
+ ENDPOINT = 'search'.freeze
7
+
8
+ def search(language:, params: {})
9
+ query_string = "#{ENDPOINT}/#{language}"
10
+ uri = URI(query_string)
11
+
12
+ unless params.empty?
13
+ uri.query = URI.encode_www_form(params)
14
+ end
15
+
16
+ response = @request_client.get(uri: uri)
17
+ deserialize.call(response.body)
18
+ end
19
+
20
+ def search_translation(source_language:, target_language:, params: {})
21
+ query_string =
22
+ "#{ENDPOINT}/translations/#{source_language}/#{target_language}"
23
+ uri = URI(query_string)
24
+
25
+ unless params.empty?
26
+ uri.query = URI.encode_www_form(params)
27
+ end
28
+
29
+ response = @request_client.get(uri: uri)
30
+ deserialize.call(response.body)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -9,6 +9,15 @@ module OxfordDictionary
9
9
  ENDPOINT = 'search'.freeze
10
10
 
11
11
  def search(query, params = {})
12
+ warn '''
13
+ Client#search without using named parameters is DEPRECATED and will
14
+ become non-functional on June 30, 2019 (it uses the V1 interface which
15
+ Oxford Dictionaries is taking offline). Reference
16
+ https://github.com/swcraig/oxford-dictionary/pull/15 for more
17
+ information. Check out OxfordDictionary::Endpoints::Search for the
18
+ interface to use.
19
+ '''
20
+
12
21
  params[:q] = query
13
22
  ListResponse.new(request(ENDPOINT, query, params))
14
23
  end
@@ -0,0 +1,21 @@
1
+ require 'oxford_dictionary/endpoints/endpoint'
2
+
3
+ module OxfordDictionary
4
+ module Endpoints
5
+ class Sentences < Endpoint
6
+ ENDPOINT = 'sentences'.freeze
7
+
8
+ def sentence(word:, language:, params: {})
9
+ query_string = "#{ENDPOINT}/#{language}/#{word}"
10
+ uri = URI(query_string)
11
+
12
+ unless params.empty?
13
+ uri.query = URI.encode_www_form(params)
14
+ end
15
+
16
+ response = @request_client.get(uri: uri)
17
+ deserialize.call(response.body)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'oxford_dictionary/endpoints/endpoint'
2
+
3
+ module OxfordDictionary
4
+ module Endpoints
5
+ class Thesaurus < Endpoint
6
+ ENDPOINT = 'thesaurus'.freeze
7
+
8
+ def thesaurus(word:, language:, params: {})
9
+ query_string = "#{ENDPOINT}/#{language}/#{word}"
10
+ uri = URI(query_string)
11
+
12
+ unless params.empty?
13
+ uri.query = URI.encode_www_form(params)
14
+ end
15
+
16
+ response = @request_client.get(uri: uri)
17
+ deserialize.call(response.body)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ require 'oxford_dictionary/endpoints/endpoint'
2
+
3
+ module OxfordDictionary
4
+ module Endpoints
5
+ class Translations < Endpoint
6
+ ENDPOINT = 'translations'.freeze
7
+
8
+ def translation(word:, source_language:, target_language:, params: {})
9
+ query_string =
10
+ "#{ENDPOINT}/#{source_language}/#{target_language}/#{word}"
11
+ uri = URI(query_string)
12
+
13
+ unless params.empty?
14
+ uri.query = URI.encode_www_form(params)
15
+ end
16
+
17
+ response = @request_client.get(uri: uri)
18
+ deserialize.call(response.body)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module OxfordDictionary
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxford_dictionary
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - swcraig
@@ -171,11 +171,16 @@ files:
171
171
  - lib/oxford_dictionary/client.rb
172
172
  - lib/oxford_dictionary/deprecated_request.rb
173
173
  - lib/oxford_dictionary/deserialize.rb
174
+ - lib/oxford_dictionary/endpoints/endpoint.rb
174
175
  - lib/oxford_dictionary/endpoints/entries.rb
175
176
  - lib/oxford_dictionary/endpoints/entry_endpoint.rb
176
177
  - lib/oxford_dictionary/endpoints/inflection_endpoint.rb
177
178
  - lib/oxford_dictionary/endpoints/lemmas.rb
179
+ - lib/oxford_dictionary/endpoints/search.rb
178
180
  - lib/oxford_dictionary/endpoints/search_endpoint.rb
181
+ - lib/oxford_dictionary/endpoints/sentences.rb
182
+ - lib/oxford_dictionary/endpoints/thesaurus.rb
183
+ - lib/oxford_dictionary/endpoints/translations.rb
179
184
  - lib/oxford_dictionary/endpoints/wordlist_endpoint.rb
180
185
  - lib/oxford_dictionary/error.rb
181
186
  - lib/oxford_dictionary/request.rb