what_is 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/what_is.rb +2 -1
- data/lib/what_is/dictionary.rb +41 -0
- data/lib/what_is/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4373e66ea330f1d617483cb469f5ec9095b0a7cc
|
4
|
+
data.tar.gz: e13da9b4a6b062442b99066c47877eb10ed7a6f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f1677729d318c020a5192361567a4f021b997cce30c73116232bfc4089ee9a56a77393800e4b215472d1346e1e4b16c5cbad5898e3728820c24f73b055dd18d
|
7
|
+
data.tar.gz: a43c03bcf69da892514e66db9910fe22577df74361bc3197704cc135d71cbb5c94d3dd3f5990f44d01dc6bffde9f9ea6dfcfcef44d1ef8f78bf77ceb72eba49c
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ Configure your api keys first.
|
|
35
35
|
|
36
36
|
Implementation.
|
37
37
|
|
38
|
-
x = WhatIs::Define.new("<insert word to define>")
|
38
|
+
x = WhatIs::Define.new("<insert word to define>", <reference>) # where reference can be :thesaurus or :dictionary
|
39
39
|
x.define! # returns the meaning of the word
|
40
40
|
|
41
41
|
## Contributing
|
data/lib/what_is.rb
CHANGED
@@ -2,6 +2,7 @@ require "what_is/version"
|
|
2
2
|
require "what_is/configuration"
|
3
3
|
require "what_is/exceptions"
|
4
4
|
require "what_is/thesaurus"
|
5
|
+
require "what_is/dictionary"
|
5
6
|
|
6
7
|
module WhatIs
|
7
8
|
|
@@ -29,7 +30,7 @@ module WhatIs
|
|
29
30
|
when :thesaurus
|
30
31
|
WhatIs::Thesaurus.new(@word).define!
|
31
32
|
when :dictionary
|
32
|
-
|
33
|
+
WhatIs::Dictionary.new(@word).define!
|
33
34
|
else
|
34
35
|
raise WhatIs::ReferenceUndefinedException
|
35
36
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
require "nokogiri"
|
4
|
+
|
5
|
+
module WhatIs
|
6
|
+
class Dictionary
|
7
|
+
BASE_URL = "http://www.dictionaryapi.com"
|
8
|
+
|
9
|
+
def initialize(word)
|
10
|
+
@word = word
|
11
|
+
end
|
12
|
+
|
13
|
+
def define!
|
14
|
+
raise WhatIs::NoApiKeyException unless api_key
|
15
|
+
|
16
|
+
uri = URI.parse(api_endpoint)
|
17
|
+
response = Net::HTTP.get_response(uri)
|
18
|
+
doc = Nokogiri::XML(response.body)
|
19
|
+
|
20
|
+
|
21
|
+
doc.xpath("//dt").first.text
|
22
|
+
|
23
|
+
rescue NoApiKeyException => e
|
24
|
+
no_api_key_exception_message
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def api_endpoint
|
30
|
+
"#{BASE_URL}/api/v1/references/collegiate/xml/#{@word}?key=#{api_key}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def api_key
|
34
|
+
WhatIs.configuration.dictionary_api_key
|
35
|
+
end
|
36
|
+
|
37
|
+
def no_api_key_exception_message
|
38
|
+
"ERROR: No api key provided for dictionary."
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/what_is/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: what_is
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Chavez
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- lib/what_is.rb
|
83
83
|
- lib/what_is/configuration.rb
|
84
|
+
- lib/what_is/dictionary.rb
|
84
85
|
- lib/what_is/exceptions.rb
|
85
86
|
- lib/what_is/thesaurus.rb
|
86
87
|
- lib/what_is/version.rb
|