what_is 1.0.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/lib/what_is/exceptions.rb +1 -0
- data/lib/what_is/thesaurus.rb +30 -0
- data/lib/what_is/version.rb +1 -1
- data/lib/what_is.rb +11 -13
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 493c790fe1228f569420eef78cc6228c368fd6ba
|
4
|
+
data.tar.gz: c884983bea39c2304f4110377376077062eacbd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a26c4b47795866d12904b353650ae7e1eee23019564afc14e32082460fdf0ceafc67c0025ff8fd342a964c3d6101b28d4c31ab05c208d53ae3977b1724dff73
|
7
|
+
data.tar.gz: 4bfa06ede5bf98d9c416c11ad2c65a2838aa6fc34051104e5f6cbc263cad9cd8e520137f3dff7ecebda5f63b5a23e5f340440c2b5287628723b41ccbe96955ed
|
data/README.md
CHANGED
@@ -26,8 +26,17 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
+
Configure your api keys first.
|
30
|
+
|
31
|
+
WhatIs.configure do |config|
|
32
|
+
config.thesaurus_api_key = "<api key here>"
|
33
|
+
config.dictionary_api_key = "<api key here>"
|
34
|
+
end
|
35
|
+
|
36
|
+
Implementation.
|
37
|
+
|
29
38
|
x = WhatIs::Define.new("<insert word to define>")
|
30
|
-
x.
|
39
|
+
x.define! # returns the meaning of the word
|
31
40
|
|
32
41
|
## Contributing
|
33
42
|
|
data/lib/what_is/exceptions.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
module WhatIs
|
2
|
+
class Thesaurus
|
3
|
+
BASE_URL = "http://www.dictionaryapi.com"
|
4
|
+
|
5
|
+
def initialize(word)
|
6
|
+
@word = word
|
7
|
+
end
|
8
|
+
|
9
|
+
def define!
|
10
|
+
uri = URI.parse(api_endpoint)
|
11
|
+
response = Net::HTTP.get_response(uri)
|
12
|
+
doc = Nokogiri::XML(response.body)
|
13
|
+
|
14
|
+
doc.xpath("//mc").first.text
|
15
|
+
|
16
|
+
rescue NoApiKeyException => e
|
17
|
+
no_api_key_exception_message
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def api_endpoint
|
23
|
+
"#{BASE_URL}/api/v1/references/thesaurus/xml/#{@word}?key=#{api_key}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def api_key
|
27
|
+
WhatIs.configuration.thesaurus_api_key
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/what_is/version.rb
CHANGED
data/lib/what_is.rb
CHANGED
@@ -4,6 +4,7 @@ require "what_is/exceptions"
|
|
4
4
|
require "net/http"
|
5
5
|
require "uri"
|
6
6
|
require "nokogiri"
|
7
|
+
require "what_is/thesaurus"
|
7
8
|
|
8
9
|
module WhatIs
|
9
10
|
|
@@ -20,30 +21,27 @@ module WhatIs
|
|
20
21
|
end
|
21
22
|
|
22
23
|
class Define
|
23
|
-
def initialize(word)
|
24
|
+
def initialize(word, reference)
|
24
25
|
@word = word.to_s
|
25
|
-
@
|
26
|
+
@reference = reference.to_sym
|
26
27
|
end
|
27
28
|
|
28
29
|
def define!
|
29
30
|
raise WhatIs::NoApiKeyException unless WhatIs.configuration.thesaurus_api_key
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
case @reference
|
33
|
+
when :thesaurus
|
34
|
+
WhatIs::Thesaurus.new(@word).define!
|
35
|
+
when :dictionary
|
36
|
+
|
37
|
+
else
|
38
|
+
raise WhatIs::ReferenceUndefinedException
|
39
|
+
end
|
35
40
|
|
36
|
-
doc.xpath("//mc").first.text
|
37
|
-
rescue NoApiKeyException => e
|
38
|
-
no_api_key_exception_message
|
39
41
|
rescue Exception => e
|
40
42
|
default_exception_message
|
41
43
|
end
|
42
44
|
|
43
|
-
def has_definition?
|
44
|
-
@has_definition
|
45
|
-
end
|
46
|
-
|
47
45
|
private
|
48
46
|
|
49
47
|
def default_exception_message
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: what_is
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Chavez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/what_is.rb
|
83
83
|
- lib/what_is/configuration.rb
|
84
84
|
- lib/what_is/exceptions.rb
|
85
|
+
- lib/what_is/thesaurus.rb
|
85
86
|
- lib/what_is/version.rb
|
86
87
|
- spec/lib/what_is_spec.rb
|
87
88
|
- spec/spec_helper.rb
|