what_is 2.0.1 → 2.2.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
  SHA1:
3
- metadata.gz: 34bc624eb749ecafe148dcdca1a217dc96d3e02d
4
- data.tar.gz: 2e359470f56ec958947dfc805c108d74f2451fa2
3
+ metadata.gz: 4373e66ea330f1d617483cb469f5ec9095b0a7cc
4
+ data.tar.gz: e13da9b4a6b062442b99066c47877eb10ed7a6f1
5
5
  SHA512:
6
- metadata.gz: f675709b46bafe489dc364ed558813d16d5d6e2faf25777cdc9df449003e78f7a1cb657d6afca836022a8592869d69d08349c3b6275d0d4841af7e0e043ef364
7
- data.tar.gz: 9eb513bb18a8dd4ba686312aed13f6bbfbd80016fe9c1924f93af4e931bb00f2c9e5c8fc1dca90ed9604a9b60b640fe4ea10aac91253a50c822c85ae8a1c3e8b
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module WhatIs
2
- VERSION = "2.0.1"
2
+ VERSION = "2.2.0"
3
3
  end
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.1
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