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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14e73c9dda8860c812258e3210b1a0d7c0ba061d
4
- data.tar.gz: 99afae4938a5ce0930d69108925b8e22c68a2992
3
+ metadata.gz: 493c790fe1228f569420eef78cc6228c368fd6ba
4
+ data.tar.gz: c884983bea39c2304f4110377376077062eacbd7
5
5
  SHA512:
6
- metadata.gz: c3add36fb8a6b1645b8de7691a0dd580b353547ea16334c951afc5c83cd74adfd7cb146dc8eb8e27ab0dde185720712bdc84766a0bdf3734803ccd7f051bb3c3
7
- data.tar.gz: 714ea921fb6f31c3f3e72446f60d90da5797fae94c24139a96dfe055f12282445e5793376df301cdb555dc5578ad9bb94c16bff88f7e5a74e3535e9d6cb20651
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.go! # returns the meaning of the word
39
+ x.define! # returns the meaning of the word
31
40
 
32
41
  ## Contributing
33
42
 
@@ -1,3 +1,4 @@
1
1
  module WhatIs
2
2
  class NoApiKeyException < StandardError; end
3
+ class ReferenceUndefinedException < StandardError; end
3
4
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module WhatIs
2
- VERSION = "1.0.5"
2
+ VERSION = "2.0.0"
3
3
  end
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
- @has_definition = false
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
- thesaurus_endpoint = "http://www.dictionaryapi.com/api/v1/references/thesaurus/xml/#{@word}?key=#{WhatIs.configuration.thesaurus_api_key}"
32
- uri = URI.parse(thesaurus_endpoint)
33
- response = Net::HTTP.get_response(uri)
34
- doc = Nokogiri::XML(response.body)
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: 1.0.5
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-02 00:00:00.000000000 Z
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