urban_dict 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +6 -4
- data/lib/urban_dict.rb +33 -20
- data/lib/urban_dict/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWI4NzJkOWVlOGIzOWEwN2EzOGZmMDE4YWQ4YmJlY2RlNWJkYTgxMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Zjk0Y2JmZWQxNTM3NjQyMmZhMTNjZWEwN2E5YTljNmExMTZmNjg0Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzI0YTg4OTA3ZmQzN2Y5OTZmNDZmMTQzOTdiMDllMThhYjIwZDViNTQ4ZjRl
|
10
|
+
ZThhNGZjNTk4ODhhMjk1ZWUyZWVhNWUyMmFiNDYyZTU0OGEyODZlY2I4ODgz
|
11
|
+
ZGY1NDY0YjFiMzVhOGRkZDZmMGM2Nzc3NGVhYjY1MTVjMGI1YWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTU2N2ViODA2ODU5YjhkNGZjOWNjNzY1MGM0MmQ1YjQyMDBhMmRkNGIwN2Q2
|
14
|
+
YzFkMmU2Yzc0M2NmYjI0OTJhNzA1ZWEyZmE4ZTM5M2VjZjU0NjAyZDUyMTBh
|
15
|
+
MTczYzNiYjczZDM0MGViNmNlOWY3MzMzYzU0ZWMyZDFiYTZiNWQ=
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# UrbanDict
|
2
2
|
|
3
|
-
|
3
|
+
A simple ruby gem to look up word definitions on UrbanDictionary.com.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem '
|
9
|
+
gem 'urban_dict'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -18,7 +18,9 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
```
|
22
|
+
definition = UrbanDict.define("snapback")
|
23
|
+
```
|
22
24
|
|
23
25
|
## Contributing
|
24
26
|
|
data/lib/urban_dict.rb
CHANGED
@@ -5,37 +5,50 @@ require "json"
|
|
5
5
|
|
6
6
|
module UrbanDict
|
7
7
|
|
8
|
-
|
8
|
+
class UrbanResponse
|
9
|
+
attr_accessor :uri
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
if word.nil?
|
13
|
-
exit "a word is required to define"
|
11
|
+
def initialize(url)
|
12
|
+
@uri = URI.parse(url)
|
14
13
|
end
|
15
14
|
|
16
|
-
|
15
|
+
def get_response
|
16
|
+
response = Net::HTTP.get_response(@uri)
|
17
17
|
|
18
|
-
|
18
|
+
unless response.code == "200"
|
19
|
+
return { error: "There was a problem using the urban dictionary endpoint. Response code = #{ response.code }" }
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
body = JSON.parse(response.body)
|
23
|
+
|
24
|
+
definitions = body["list"]
|
23
25
|
|
24
|
-
|
26
|
+
unless definitions.count > 0
|
27
|
+
return { error: "No definition found for '#{ word }'." }
|
28
|
+
end
|
25
29
|
|
26
|
-
|
30
|
+
entry = definitions.first
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
return
|
32
|
+
#puts entry["definition"]
|
33
|
+
#puts "Example: #{ entry["example"]}"
|
31
34
|
end
|
35
|
+
end
|
32
36
|
|
33
|
-
entry = definitions.first
|
34
37
|
|
35
|
-
|
36
|
-
|
38
|
+
#
|
39
|
+
ENDPOINT = "http://api.urbandictionary.com/v0/"
|
40
|
+
|
41
|
+
def self.define(word = nil)
|
42
|
+
if word.nil?
|
43
|
+
random
|
44
|
+
else
|
45
|
+
UrbanResponse.new( [ENDPOINT, "define?term=", word].join ).get_response
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.random
|
50
|
+
UrbanResponse.new( [ENDPOINT, "random"].join ).get_response
|
51
|
+
end
|
37
52
|
|
38
|
-
return entry
|
39
|
-
end
|
40
53
|
|
41
54
|
end
|
data/lib/urban_dict/version.rb
CHANGED