what_is 2.0.0 → 2.0.1
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/thesaurus.rb +10 -0
- data/lib/what_is/version.rb +1 -1
- data/lib/what_is.rb +0 -8
- data/spec/lib/what_is_spec.rb +1 -8
- 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: 34bc624eb749ecafe148dcdca1a217dc96d3e02d
|
4
|
+
data.tar.gz: 2e359470f56ec958947dfc805c108d74f2451fa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f675709b46bafe489dc364ed558813d16d5d6e2faf25777cdc9df449003e78f7a1cb657d6afca836022a8592869d69d08349c3b6275d0d4841af7e0e043ef364
|
7
|
+
data.tar.gz: 9eb513bb18a8dd4ba686312aed13f6bbfbd80016fe9c1924f93af4e931bb00f2c9e5c8fc1dca90ed9604a9b60b640fe4ea10aac91253a50c822c85ae8a1c3e8b
|
data/lib/what_is/thesaurus.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
require "nokogiri"
|
4
|
+
|
1
5
|
module WhatIs
|
2
6
|
class Thesaurus
|
3
7
|
BASE_URL = "http://www.dictionaryapi.com"
|
@@ -7,6 +11,8 @@ module WhatIs
|
|
7
11
|
end
|
8
12
|
|
9
13
|
def define!
|
14
|
+
raise WhatIs::NoApiKeyException unless api_key
|
15
|
+
|
10
16
|
uri = URI.parse(api_endpoint)
|
11
17
|
response = Net::HTTP.get_response(uri)
|
12
18
|
doc = Nokogiri::XML(response.body)
|
@@ -26,5 +32,9 @@ module WhatIs
|
|
26
32
|
def api_key
|
27
33
|
WhatIs.configuration.thesaurus_api_key
|
28
34
|
end
|
35
|
+
|
36
|
+
def no_api_key_exception_message
|
37
|
+
"ERROR: No api key provided for thesaurus."
|
38
|
+
end
|
29
39
|
end
|
30
40
|
end
|
data/lib/what_is/version.rb
CHANGED
data/lib/what_is.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
require "what_is/version"
|
2
2
|
require "what_is/configuration"
|
3
3
|
require "what_is/exceptions"
|
4
|
-
require "net/http"
|
5
|
-
require "uri"
|
6
|
-
require "nokogiri"
|
7
4
|
require "what_is/thesaurus"
|
8
5
|
|
9
6
|
module WhatIs
|
@@ -27,7 +24,6 @@ module WhatIs
|
|
27
24
|
end
|
28
25
|
|
29
26
|
def define!
|
30
|
-
raise WhatIs::NoApiKeyException unless WhatIs.configuration.thesaurus_api_key
|
31
27
|
|
32
28
|
case @reference
|
33
29
|
when :thesaurus
|
@@ -47,9 +43,5 @@ module WhatIs
|
|
47
43
|
def default_exception_message
|
48
44
|
"ERROR: Unable to define `#{@word}`"
|
49
45
|
end
|
50
|
-
|
51
|
-
def no_api_key_exception_message
|
52
|
-
"ERROR: No api key provided."
|
53
|
-
end
|
54
46
|
end
|
55
47
|
end
|
data/spec/lib/what_is_spec.rb
CHANGED
@@ -1,17 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe WhatIs do
|
4
|
-
context "initially" do
|
5
|
-
it "has no definition" do
|
6
|
-
result = WhatIs::Define.new("sample")
|
7
|
-
expect(result).not_to have_definition
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
4
|
context "defining a word" do
|
12
5
|
it "returns the meaning" do
|
13
6
|
definition = double("definition", body: "sample")
|
14
|
-
result = WhatIs::Define.new("house")
|
7
|
+
result = WhatIs::Define.new("house", :thesaurus)
|
15
8
|
|
16
9
|
Net::HTTP.stub(:get_response).and_return(definition)
|
17
10
|
expect(result.define!).to eq "sample"
|