what_is 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/what_is/configuration.rb +0 -5
- data/lib/what_is/version.rb +1 -1
- data/lib/what_is.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02323142fd6f70554516e9a31aef2f8b712ff242
|
4
|
+
data.tar.gz: 54cfa98a19c07eafba6bcdc30d463aecad2cc0b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d962ab8c1b034f6f682e61920b397d9f28444768f3a2a96811b92af6bd3e69bd418c926748f026d04803c40be14951081f7266aa3b5e61f70b13787558e88ec
|
7
|
+
data.tar.gz: 69a59df41d797c249f3d699ecded139d1bd6aa079a8076c6468d13547852cdd8aebb8876cc77d03cd0f311d943a4ee7ae5dcea7f555f663367fd9d086c746cbe
|
data/lib/what_is/version.rb
CHANGED
data/lib/what_is.rb
CHANGED
@@ -25,12 +25,16 @@ module WhatIs
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def define!
|
28
|
+
raise NoApiKeyException unless WhatIs.configuration.thesaurus_api_key
|
29
|
+
|
28
30
|
thesaurus_endpoint = "http://www.dictionaryapi.com/api/v1/references/thesaurus/xml/#{@word}?key=#{WhatIs.configuration.thesaurus_api_key}"
|
29
31
|
uri = URI.parse(thesaurus_endpoint)
|
30
32
|
response = Net::HTTP.get_response(uri)
|
31
33
|
doc = Nokogiri::XML(response.body)
|
32
34
|
|
33
35
|
doc.xpath("//mc").first.text
|
36
|
+
rescue NoApiKeyException => e
|
37
|
+
no_api_key_exception_message
|
34
38
|
rescue Exception => e
|
35
39
|
default_exception_message
|
36
40
|
end
|
@@ -44,5 +48,9 @@ module WhatIs
|
|
44
48
|
def default_exception_message
|
45
49
|
"Oops! Something happened while defining this word."
|
46
50
|
end
|
51
|
+
|
52
|
+
def no_api_key_exception_message
|
53
|
+
"No api key provided."
|
54
|
+
end
|
47
55
|
end
|
48
56
|
end
|