ud 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/bin/ud +3 -3
- data/lib/ud.rb +12 -5
- data/lib/ud/formatting.rb +1 -1
- data/tests/query_tests.rb +5 -5
- metadata +35 -46
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: da20a8c734f36a7a31f9a27c069390bde91207d30420f4dc90d1299c1cff6fc9
|
4
|
+
data.tar.gz: 4b2efbe5e2cc596e6da5b4cf35d757395946a2357c4d90921262da045b5f13d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b82fbc1da03bf072abebc2afad46c9e065f082741b92435afff61fd4949b070b9b9289523fc6a65da4bc0e9838bc7945a320e3d55d4888d3afa18f24f1ab08a0
|
7
|
+
data.tar.gz: 26e8d65aa79a1b76a021306a3a4cb7cfabedfec3385868fee5174f1585234a7570ba5c87bb779c04065bcdad235785d59ed987a4b48432a342f815a261abfd66
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/bin/ud
CHANGED
@@ -4,10 +4,10 @@
|
|
4
4
|
# clean interrupt
|
5
5
|
trap("INT") { abort }
|
6
6
|
|
7
|
-
require "
|
7
|
+
require "optimist"
|
8
8
|
require "ud"
|
9
9
|
|
10
|
-
opts =
|
10
|
+
opts = Optimist.options do
|
11
11
|
version "ud #{UD.version}"
|
12
12
|
banner <<-EOS
|
13
13
|
UD is a command-line tool to scrape definitions from the Urban Dictionary.
|
@@ -23,7 +23,7 @@ EOS
|
|
23
23
|
opt :browser, "Open the results in a browser window", :short => "-b"
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
Optimist.die :count, "must be non-negative" if opts[:count] < 0
|
27
27
|
|
28
28
|
if !opts[:random] && ARGV.empty?
|
29
29
|
puts "Error: No word provided. Use -h or --help to see the help."
|
data/lib/ud.rb
CHANGED
@@ -12,9 +12,12 @@ module UD
|
|
12
12
|
class << self
|
13
13
|
# @return [String] the current gem's version
|
14
14
|
def version
|
15
|
-
"0.3.
|
15
|
+
"0.3.1"
|
16
16
|
end
|
17
17
|
|
18
|
+
API_ROOT = "https://api.urbandictionary.com/v0"
|
19
|
+
WWW_ROOT = "https://www.urbandictionary.com"
|
20
|
+
|
18
21
|
# Get the search URL to query for a given term.
|
19
22
|
# @param term [String] the term to search for. It must be a string, spaces
|
20
23
|
# are allowed.
|
@@ -24,18 +27,19 @@ module UD
|
|
24
27
|
param = URI.encode_www_form("term" => term)
|
25
28
|
|
26
29
|
if opts[:api] != false
|
27
|
-
"
|
30
|
+
"#{API_ROOT}/define?#{param}"
|
28
31
|
else
|
29
|
-
"
|
32
|
+
"#{WWW_ROOT}/define.php?#{param}"
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
36
|
+
# Return a URL for a random definition.
|
33
37
|
# @param opts [Hash] options.
|
34
38
|
def random_url(opts = {})
|
35
39
|
if opts[:api] != false
|
36
|
-
"
|
40
|
+
"#{API_ROOT}/random"
|
37
41
|
else
|
38
|
-
"
|
42
|
+
"#{WWW_ROOT}/random.php"
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
@@ -63,10 +67,13 @@ module UD
|
|
63
67
|
parse_response(open(search_url(term)).read, opts)
|
64
68
|
end
|
65
69
|
|
70
|
+
# Return a random definition
|
71
|
+
# @param opts [Hash] options.
|
66
72
|
def random(opts = {})
|
67
73
|
parse_response(open(random_url).read, opts)
|
68
74
|
end
|
69
75
|
|
76
|
+
# Parse a response from the Urban Dictionnary website.
|
70
77
|
# @param opts [Hash] options. This is used by the command-line tool.
|
71
78
|
# +:count+ is the maximum number of results to return
|
72
79
|
# @return [Array<Hash>]
|
data/lib/ud/formatting.rb
CHANGED
@@ -11,7 +11,7 @@ module UD
|
|
11
11
|
def fit(txt, width = 79)
|
12
12
|
return [] if width < 1
|
13
13
|
|
14
|
-
# from
|
14
|
+
# from https://stackoverflow.com/a/7567210/735926
|
15
15
|
r = /(.{1,#{width}})(?:\s|$)/m
|
16
16
|
txt.split("\n").map { |l| l.scan(r) }.flatten
|
17
17
|
end
|
data/tests/query_tests.rb
CHANGED
@@ -5,15 +5,15 @@ require File.dirname(__FILE__) + '/fake_responses'
|
|
5
5
|
|
6
6
|
class UD_Query_test < Test::Unit::TestCase
|
7
7
|
|
8
|
-
API_URL = '
|
9
|
-
ROOT_URL = '
|
8
|
+
API_URL = 'https://api.urbandictionary.com/v0/define'
|
9
|
+
ROOT_URL = 'https://www.urbandictionary.com/define.php'
|
10
10
|
|
11
11
|
def setup
|
12
12
|
@foo, @bar = [
|
13
13
|
{
|
14
14
|
:id => 1,
|
15
15
|
:author => 'a1',
|
16
|
-
:permalink => '
|
16
|
+
:permalink => 'https://example.com/1',
|
17
17
|
:word => 'foo',
|
18
18
|
:definition => 'A',
|
19
19
|
:example => 'AA',
|
@@ -24,7 +24,7 @@ class UD_Query_test < Test::Unit::TestCase
|
|
24
24
|
{
|
25
25
|
:id => 2,
|
26
26
|
:author => 'a2',
|
27
|
-
:permalink => '
|
27
|
+
:permalink => 'https://example.com/2',
|
28
28
|
:word => 'bar',
|
29
29
|
:definition => 'B',
|
30
30
|
:example => 'BB',
|
@@ -59,7 +59,7 @@ class UD_Query_test < Test::Unit::TestCase
|
|
59
59
|
# == UD#random_url == #
|
60
60
|
|
61
61
|
def test_random_url
|
62
|
-
assert_equal("
|
62
|
+
assert_equal("https://api.urbandictionary.com/v0/random", UD.random_url)
|
63
63
|
end
|
64
64
|
|
65
65
|
# == UD#query == #
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Baptiste Fontaine
|
@@ -10,56 +10,46 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
13
|
+
MIIEPDCCAqSgAwIBAgIBATANBgkqhkiG9w0BAQsFADAkMSIwIAYDVQQDDBliL0RD
|
14
|
+
PXB0aXN0ZWZvbnRhaW5lL0RDPWZyMB4XDTE4MTIwODAwMDU0MFoXDTE5MTIwODAw
|
15
|
+
MDU0MFowJDEiMCAGA1UEAwwZYi9EQz1wdGlzdGVmb250YWluZS9EQz1mcjCCAaIw
|
16
|
+
DQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBAKdjTwN/gnJ3WHxKeusaRN1o902Q
|
17
|
+
BmIRgdtbhpsHtgUruKNujutEBpmhG1fka8+mujhqh885blckeC8hXgqpHGK1MsJU
|
18
|
+
tgsNB2F2Nvof/uGBzi+OZ76HPLmfvJFb/KUiwrh08jTbFftMBCmuekbxBajt2N2F
|
19
|
+
shF6DFEqO2hl/itVt5UeIZhpIZvO7qSZ9FtLRXs0q2O27h4QfAv6XobNDwH5TBs5
|
20
|
+
z+EYufgTtupf26xW0v6z2NDG6z36Eap7QAwoivuPCuXO+IPgxhubtGvFYSo7ygP4
|
21
|
+
RbYsaGucRneCCzezTD+i1LnhGt9TCbQjdvidgM+i616JC/HRXglM0apgBZSjayoI
|
22
|
+
XHoajIajnU+570cu01Wsa+SF9m4stKao0hLnCUMeYybmA/Ilk58nJ2xZJWMULu76
|
23
|
+
7Ttzead1Ah25ZdWefKG5FIGkpezEp4z/YihGEJt+hxS7Aa2xYiIlnYFwUno530/8
|
24
|
+
So5Ibqdd3pMKJDUQJvGIBhsQIXF4Iogk4txoPwIDAQABo3kwdzAJBgNVHRMEAjAA
|
25
|
+
MAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUsV1eKnEFtVRwyz6/nTuharH3G+UwHgYD
|
26
|
+
VR0RBBcwFYETYkBwdGlzdGVmb250YWluZS5mcjAeBgNVHRIEFzAVgRNiQHB0aXN0
|
27
|
+
ZWZvbnRhaW5lLmZyMA0GCSqGSIb3DQEBCwUAA4IBgQBm1mthI2xc/jfKApZigdhO
|
28
|
+
j2X3h5wnBKu/EPU1be0RuFigUGlZCMaM4S8nk5pBJxRv1FHUtR4utP7vcqEWGaE1
|
29
|
+
9RklitOhNSXOeFfFukjUzZXFGUrcSe68BW9dh/KhIt84li13pdDLSNRmO0TzaRdb
|
30
|
+
G7ZRTVIhGqBCY3KJrMwrbjnOH/VK5XwO0hzFZ2/ClWeK+VuJ98bKWpiu2ZSHZCgK
|
31
|
+
nkcbCuzmx0/6UwqUhPEl4i+QLTVr8+Gk3jdxYSBBEUMXyNF6fPM6JJdIui/WjJIx
|
32
|
+
gtCh7AePlEbyxbx4d+oDvo/uzNFfHNNuI4TfkuBNDGLstPbJfyHgk7oPyfvD5dlO
|
33
|
+
yxO7L6A6ZNC1bI3P8tQq+qgDNpkRJ8pqynfF7DxMVOzvlhO5qhV23if7tYaRjqV5
|
34
|
+
T1ACML6wkYk8FexGDaL0txwG/y+b+3sHyUArpv8/rLGqpo+g2TYlqJhdwuA10W2k
|
35
|
+
H0Dpo4eQ8PCwqU7AgGTli19gHcox4Ne0O+6QaiB4eSw=
|
32
36
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
37
|
+
date: 2018-12-08 00:00:00.000000000 Z
|
34
38
|
dependencies:
|
35
39
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
40
|
+
name: optimist
|
37
41
|
requirement: !ruby/object:Gem::Requirement
|
38
42
|
requirements:
|
39
43
|
- - "~>"
|
40
44
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
45
|
+
version: '3.0'
|
42
46
|
type: :runtime
|
43
47
|
prerelease: false
|
44
48
|
version_requirements: !ruby/object:Gem::Requirement
|
45
49
|
requirements:
|
46
50
|
- - "~>"
|
47
51
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: trollop
|
51
|
-
requirement: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - "~>"
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '2.1'
|
56
|
-
type: :runtime
|
57
|
-
prerelease: false
|
58
|
-
version_requirements: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - "~>"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '2.1'
|
52
|
+
version: '3.0'
|
63
53
|
- !ruby/object:Gem::Dependency
|
64
54
|
name: colored
|
65
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,19 +107,19 @@ dependencies:
|
|
117
107
|
- !ruby/object:Gem::Version
|
118
108
|
version: '2.5'
|
119
109
|
- !ruby/object:Gem::Dependency
|
120
|
-
name:
|
110
|
+
name: webmock
|
121
111
|
requirement: !ruby/object:Gem::Requirement
|
122
112
|
requirements:
|
123
113
|
- - "~>"
|
124
114
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
115
|
+
version: '3.4'
|
126
116
|
type: :development
|
127
117
|
prerelease: false
|
128
118
|
version_requirements: !ruby/object:Gem::Requirement
|
129
119
|
requirements:
|
130
120
|
- - "~>"
|
131
121
|
- !ruby/object:Gem::Version
|
132
|
-
version: '
|
122
|
+
version: '3.4'
|
133
123
|
- !ruby/object:Gem::Dependency
|
134
124
|
name: coveralls
|
135
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,7 +135,7 @@ dependencies:
|
|
145
135
|
- !ruby/object:Gem::Version
|
146
136
|
version: '0.7'
|
147
137
|
description: Get words' definitions from Urban Dictionary on the command-line.
|
148
|
-
email:
|
138
|
+
email: b@ptistefontaine.fr
|
149
139
|
executables:
|
150
140
|
- ud
|
151
141
|
extensions: []
|
@@ -177,12 +167,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
167
|
version: '0'
|
178
168
|
requirements: []
|
179
169
|
rubyforge_project:
|
180
|
-
rubygems_version: 2.
|
170
|
+
rubygems_version: 2.7.7
|
181
171
|
signing_key:
|
182
172
|
specification_version: 4
|
183
173
|
summary: Urban Dictionary unofficial scrapper
|
184
174
|
test_files:
|
185
|
-
- tests/formatting_tests.rb
|
186
|
-
- tests/query_tests.rb
|
187
175
|
- tests/tests.rb
|
188
|
-
|
176
|
+
- tests/query_tests.rb
|
177
|
+
- tests/formatting_tests.rb
|
metadata.gz.sig
CHANGED
Binary file
|