what_is 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -4
- data/lib/what_is/version.rb +1 -1
- data/lib/what_is.rb +11 -1
- data/spec/lib/what_is_spec.rb +3 -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: 3777280267634b44ee778b97a4e4a437442a0de6
|
4
|
+
data.tar.gz: f9a65caaab2c15997a99add79e3eaacad7eb330a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea906355fd3ab959172cd53f10622350a3bacc390418b54f6c3981cf01482ed3d8001d947ec1af8b2a3bc47a94d220f5302ed83366b5a551895f23ee7f986f61
|
7
|
+
data.tar.gz: 649020d5be74e79d59d3149259c309d7a6291d362b6cf5f8431807531a6a9d092e3f43088c37670f787b194a8a600381c4fe088b6e45e06a93305d1354b5a9f1
|
data/README.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# What Is
|
2
2
|
|
3
|
-
|
3
|
+
What the hell is this gem for? To put simply, this library enables us (developers) to define a given word. Think "dictionary". It uses the Merriam-Webster's API as the reference for giving the definitions.
|
4
|
+
|
5
|
+
# Setup
|
6
|
+
|
7
|
+
Register an account on http://www.dictionaryapi.com/ and make sure you request an api key for
|
8
|
+
Collegiate Dictionary and Collegiate Thesaurus. These are the two references that this library supports for now.
|
9
|
+
|
10
|
+
After registration, you should already have two api keys; one for the dictionary and other is for the thesaurus
|
11
|
+
version.
|
4
12
|
|
5
13
|
## Installation
|
6
14
|
|
@@ -18,11 +26,12 @@ Or install it yourself as:
|
|
18
26
|
|
19
27
|
## Usage
|
20
28
|
|
21
|
-
|
29
|
+
x = WhatIs::Define.new("<insert word to define>")
|
30
|
+
x.go! # returns the meaning of the word
|
22
31
|
|
23
32
|
## Contributing
|
24
33
|
|
25
|
-
1. Fork it ( http://github.com/<my-github-username
|
34
|
+
1. Fork it ( http://github.com/<my-github-username>what_is/fork )
|
26
35
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
36
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
37
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/what_is/version.rb
CHANGED
data/lib/what_is.rb
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
require "what_is/version"
|
2
|
+
require "net/http"
|
3
|
+
require "uri"
|
2
4
|
|
3
5
|
module WhatIs
|
4
6
|
class Define
|
7
|
+
DICT_API_KEY = "ae396fba-2435-4197-b780-c4b5485fec22"
|
8
|
+
THES_API_KEY = "c80b99cc-421c-4f86-bc50-45ef40b371fe"
|
9
|
+
|
5
10
|
def initialize(word)
|
11
|
+
@word = word
|
6
12
|
@has_definition = false
|
7
13
|
end
|
8
14
|
|
9
15
|
def define!
|
10
|
-
"
|
16
|
+
thesaurus_endpoint = "http://www.dictionaryapi.com/api/v1/references/thesaurus/xml/#{@word}?key=#{THES_API_KEY}"
|
17
|
+
uri = URI.parse(thesaurus_endpoint)
|
18
|
+
response = Net::HTTP.get_response(uri)
|
19
|
+
|
20
|
+
response.body
|
11
21
|
end
|
12
22
|
|
13
23
|
def has_definition?
|
data/spec/lib/what_is_spec.rb
CHANGED
@@ -10,7 +10,10 @@ describe WhatIs do
|
|
10
10
|
|
11
11
|
context "defining a word" do
|
12
12
|
it "returns the meaning" do
|
13
|
+
definition = double("definition", body: "sample")
|
13
14
|
result = WhatIs::Define.new("house")
|
15
|
+
|
16
|
+
Net::HTTP.stub(:get_response).and_return(definition)
|
14
17
|
expect(result.define!).to eq "sample"
|
15
18
|
end
|
16
19
|
end
|