urbandict 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +4 -0
  3. data/lib/slang.rb +61 -0
  4. data/lib/urbandict.rb +25 -0
  5. metadata +61 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1135ac26088eeecd1842ba4883b0138d9fbab3e3
4
+ data.tar.gz: e6f240767d5dd62e67db88fc1a6b6a8918c80861
5
+ SHA512:
6
+ metadata.gz: de87ef03cb9a9344e9ec49dce0b9e79a8cab23ba9ad8992bb3dbca2bc06234d60b991651e70bf6cce14987fcefbf89b2e0cb672a5de40aef1f5e4b9254985242
7
+ data.tar.gz: ea520d303882176d34437b2cf639625f27f00202262926aa4a7d4141f757f337893b67cf52c28ce18af049f55918e77e8456373379058cd3283eb20c8d277a87
@@ -0,0 +1,4 @@
1
+ # Changelog
2
+ ## Version 1
3
+ ### 1.0.0
4
+ * Initial release.
@@ -0,0 +1,61 @@
1
+ class Slang
2
+ # @return [Integer] The UrbanDictionary definition ID.
3
+ attr_reader :id
4
+
5
+ # @return [String] The word being defined.
6
+ attr_reader :word
7
+
8
+ # @return [String] The author of the definition.
9
+ attr_reader :author
10
+
11
+ # @return [String] A permalink to the definition.
12
+ attr_reader :permalink
13
+
14
+ # @return [String] The actual definition.
15
+ attr_reader :definition
16
+
17
+ # @return [String] An example of the word's usage.
18
+ attr_reader :example
19
+
20
+ # @return [Integer] The number of thumbs-up the definition has received.
21
+ attr_reader :upvotes
22
+
23
+ # @return [Integer] The number of thumbs-down the definition has received.
24
+ attr_reader :downvotes
25
+
26
+ # Creates a new Slang object.
27
+ # @param opts [Hash] The options hash.
28
+ # @option opts [Integer] :id The definition ID.
29
+ # @option opts [String] :word The word being defined.
30
+ # @option opts [String] :author The author of the definition.
31
+ # @option opts [String] :permalink The permalink for the definition.
32
+ # @option opts [String] :definition The definition for the :word
33
+ # @option opts [String] :example An example of its usage.
34
+ # @option opts [Integer] :thumbs_up The number of upvotes the definition has received.
35
+ # @option opts [Integer] :thumbs_down The number of downvotes the definition has received.
36
+ def initialize(opts = {})
37
+ @id = opts['defid'] || opts[:defid]
38
+ @word = opts['word'] || opts[:word]
39
+ @author = opts['author'] || opts[:author]
40
+ @permalink = opts['permalink'] || opts[:permalink]
41
+ @definition = opts['definition'] || opts[:definition]
42
+ @example = opts['example'] || opts[:example]
43
+ @upvotes = opts['thumbs_up'] || opts[:thumbs_up]
44
+ @downvotes = opts['thumbs_down'] || opts[:thumbs_down]
45
+ end
46
+
47
+ # Returns a hash representation of this Slang object.
48
+ # @return [Hash<Symbol, Integer/String>] See the source for details.
49
+ def to_h
50
+ {
51
+ id: @id,
52
+ word: @word,
53
+ author: @author,
54
+ permalink: @permalink,
55
+ definition: @definition,
56
+ example: @example,
57
+ upvotes: @upvotes,
58
+ downvotes: @downvotes
59
+ }
60
+ end
61
+ end
@@ -0,0 +1,25 @@
1
+ require 'httpclient'
2
+ require 'json'
3
+ require_relative 'slang'
4
+
5
+ module UrbanDictionary
6
+ module_function
7
+
8
+ URL = 'http://api.urbandictionary.com/v0/define'
9
+
10
+ # Gets the definitions for the word.
11
+ # @param word [String] The word to define.
12
+ # @return [Array<Slang>] An array of #{Slang} objects.
13
+ def define(word)
14
+ params = {
15
+ term: word
16
+ }
17
+ @client = HTTPClient.new if @client.nil?
18
+ response = JSON.parse(@client.get(URI.parse(URL), params).body)
19
+ ret = []
20
+ response['list'].each do |hash|
21
+ ret << Slang.new(hash)
22
+ end
23
+ ret
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: urbandict
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eli Foster
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.7.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.7.1
27
+ description: An interface to the Urban Dictionary API
28
+ email: elifosterwy@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - CHANGELOG.md
34
+ - lib/slang.rb
35
+ - lib/urbandict.rb
36
+ homepage: https://github.com/elifoster/urbandict-rb
37
+ licenses:
38
+ - CC-BY-ND-4.0
39
+ metadata:
40
+ issue_tracker: https://github.com/elifoster/urbandict-rb/issues
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.5.1
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: An interface to the Urban Dictionary API
61
+ test_files: []