urbandict 1.0.2 → 1.1.1

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.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +6 -0
  3. data/lib/urbandict.rb +15 -2
  4. metadata +6 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e3a862fc395dec0a2cb0f166dc360759941375de
4
- data.tar.gz: 7933b0da821f5d0853d5b937f11595ef5265afbf
2
+ SHA256:
3
+ metadata.gz: 934b74ffaf40fbd3777aa02996131b8c3776bbf19f828cb023d3eaee4cebe380
4
+ data.tar.gz: 2855ee7125f40af14b7e974086a6b029fa2628a00c3981f48a8a56c8d45f881b
5
5
  SHA512:
6
- metadata.gz: 4983ae12cc282b273335ca76fbb6bd7d27ebd570afd22f06e6d3b70a1d55b04fbe5394be5a16ba3d0e0ea2cc7e14126504facf89a9070eb12581960aa86c6d67
7
- data.tar.gz: 13fa2fcd83bcf122812dbc21066ed4971d9602ba712cc86996e09b79ac62c0885a59758aeb4908deabf2e5c409cb544a602a3b7e5ada5fcb5fd203b330e2f78f
6
+ metadata.gz: 94ad97e8f2d22572e5a3ec12af53a35aaec168aae552a6a1e0fb302c8ed2cae403f135ff0a45c8570e5a7baa6c2de01f69cc8cd03c3223c5b03ae2261d549d7d
7
+ data.tar.gz: b9afd808b9c76dae011163c091707d6b5f90bc285ce97a59647d459ff1c5ddcf52d4726315c114930fe0a91d9d1640c9ccbc1783672df5d880cc7f16a7e74a8d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
  ## Version 1
3
+ ### 1.1.1
4
+ * Update URL to use HTTPS, fixes no response body
5
+
6
+ ### 1.1.0
7
+ * New `UrbanDictError` is raised when the API returns an error.
8
+
3
9
  ### 1.0.2
4
10
  * Bump HTTPClient version.
5
11
  * Use pessimistic version requirements.
data/lib/urbandict.rb CHANGED
@@ -5,21 +5,34 @@ require_relative 'slang'
5
5
  module UrbanDictionary
6
6
  module_function
7
7
 
8
- URL = 'http://api.urbandictionary.com/v0/define'
8
+ URL = 'https://api.urbandictionary.com/v0/define'
9
9
 
10
10
  # Gets the definitions for the word.
11
11
  # @param word [String] The word to define.
12
12
  # @return [Array<Slang>] An array of #{Slang} objects.
13
+ # @raise [UrbanDictError]
13
14
  def define(word)
14
15
  params = {
15
16
  term: word
16
17
  }
17
18
  @client = HTTPClient.new if @client.nil?
18
19
  response = JSON.parse(@client.get(URI.parse(URL), params).body)
20
+ if response.key?('error')
21
+ raise UrbanDictError.new
22
+ end
19
23
  ret = []
20
24
  response['list'].each do |hash|
21
25
  ret << Slang.new(hash)
22
26
  end
23
27
  ret
24
28
  end
25
- end
29
+
30
+ # Urban Dictionary does not provide any useful information, so we provide a note about alphanumeric characters which
31
+ # is the only error I have encountered to date (1/18/2021).
32
+ class UrbanDictError < StandardError
33
+ def message
34
+ 'An error occurred. This could be because of issues with non-alphanumeric characters which are not handled ' \
35
+ 'properly by the Urban Dictionary API.'
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: urbandict
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eli Foster
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-02 00:00:00.000000000 Z
11
+ date: 2024-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -38,7 +38,7 @@ licenses:
38
38
  - MIT
39
39
  metadata:
40
40
  issue_tracker: https://github.com/elifoster/urbandict-rb/issues
41
- post_install_message:
41
+ post_install_message:
42
42
  rdoc_options: []
43
43
  require_paths:
44
44
  - lib
@@ -53,9 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  requirements: []
56
- rubyforge_project:
57
- rubygems_version: 2.5.1
58
- signing_key:
56
+ rubygems_version: 3.5.3
57
+ signing_key:
59
58
  specification_version: 4
60
59
  summary: An interface to the Urban Dictionary API
61
60
  test_files: []