embiggen 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +6 -5
- data/lib/embiggen/configuration.rb +1 -2
- data/lib/embiggen/http_client.rb +7 -2
- data/lib/embiggen/shortener_list.rb +0 -1
- data/lib/embiggen/uri.rb +14 -7
- data/lib/embiggen.rb +3 -2
- data/shorteners.txt +1189 -1
- data/spec/embiggen/configuration_spec.rb +2 -2
- data/spec/embiggen/shortener_list_spec.rb +10 -10
- data/spec/embiggen/uri_spec.rb +8 -8
- metadata +44 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 819be81e4674987a3cf53836dc3942c1c32ae8a8a3b1abf55f68f33e40110ecf
|
4
|
+
data.tar.gz: eca3eb40c14880fd279a7c14a9c06111d3628a215e36aebb24eab351b88d4306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a065ac340825abbbd3e8d1198522a5cb66709e92f579f4815912baee6d09adfc15062d0adf596760f010d441c7595b71ead73789e66d02ce9b33db4ece24e720
|
7
|
+
data.tar.gz: a0469f86536c7353659ca8f64a7714b1d9320e31973b6e1b991cdd1dd31131562852d52ea2d79455bca4ea82ee1e9f1dadc1dcb269935ac53437440f68b88593
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
A Ruby library to expand shortened URLs.
|
4
4
|
|
5
|
-
**Current version:** 1.
|
6
|
-
**Supported Ruby versions:**
|
5
|
+
**Current version:** 1.6.0
|
6
|
+
**Supported Ruby versions:** >= 2.7
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
10
10
|
```
|
11
|
-
gem install embiggen -v '~> 1.
|
11
|
+
gem install embiggen -v '~> 1.6'
|
12
12
|
```
|
13
13
|
|
14
14
|
Or, in your `Gemfile`:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem 'embiggen', '~> 1.
|
17
|
+
gem 'embiggen', '~> 1.6'
|
18
18
|
```
|
19
19
|
|
20
20
|
## Usage
|
@@ -203,11 +203,12 @@ Override the following settings:
|
|
203
203
|
* [Bit.do's](http://bit.do/list-of-url-shorteners.php) curated list
|
204
204
|
* [Hongkiat's](http://www.hongkiat.com/blog/url-shortening-services-the-ultimate-list/)
|
205
205
|
curated list
|
206
|
+
* [PeterDaveHello's](https://github.com/PeterDaveHello/url-shorteners) curated list
|
206
207
|
* A list of branded [Bitly](https://bitly.com/) domains collected by Altmetric
|
207
208
|
|
208
209
|
## License
|
209
210
|
|
210
|
-
Copyright © 2015-
|
211
|
+
Copyright © 2015-2024 Altmetric LLP
|
211
212
|
|
212
213
|
Distributed under the MIT License.
|
213
214
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'set'
|
3
2
|
require 'embiggen/shortener_list'
|
4
3
|
|
5
4
|
module Embiggen
|
@@ -22,7 +21,7 @@ module Embiggen
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def self.shorteners_from_file
|
25
|
-
file_path = File.expand_path('
|
24
|
+
file_path = File.expand_path('../../shorteners.txt', __dir__)
|
26
25
|
File.readlines(file_path).map(&:chomp)
|
27
26
|
end
|
28
27
|
end
|
data/lib/embiggen/http_client.rb
CHANGED
@@ -22,9 +22,14 @@ module Embiggen
|
|
22
22
|
return unless response.is_a?(::Net::HTTPRedirection)
|
23
23
|
|
24
24
|
response.fetch('Location')
|
25
|
-
rescue
|
25
|
+
rescue ::Timeout::Error => e
|
26
26
|
raise NetworkError.new(
|
27
|
-
"could not follow #{uri}: #{e.message}", uri
|
27
|
+
"Timeout::Error: could not follow #{uri}: #{e.message}", uri
|
28
|
+
)
|
29
|
+
rescue StandardError => e
|
30
|
+
raise NetworkError.new(
|
31
|
+
"StandardError: could not follow #{uri}: #{e.message}", uri
|
32
|
+
)
|
28
33
|
end
|
29
34
|
|
30
35
|
private
|
data/lib/embiggen/uri.rb
CHANGED
@@ -19,8 +19,8 @@ module Embiggen
|
|
19
19
|
redirects = extract_redirects(request_options)
|
20
20
|
location = follow(request_options)
|
21
21
|
|
22
|
-
self.class.new(location)
|
23
|
-
expand(request_options.merge(:
|
22
|
+
self.class.new(location)
|
23
|
+
.expand(request_options.merge(redirects: redirects - 1))
|
24
24
|
end
|
25
25
|
|
26
26
|
def shortened?
|
@@ -31,8 +31,11 @@ module Embiggen
|
|
31
31
|
|
32
32
|
def extract_redirects(request_options = {})
|
33
33
|
redirects = request_options.fetch(:redirects) { Configuration.redirects }
|
34
|
-
|
35
|
-
|
34
|
+
if redirects.zero?
|
35
|
+
fail TooManyRedirects.new(
|
36
|
+
"following #{uri} reached the redirect limit", uri
|
37
|
+
)
|
38
|
+
end
|
36
39
|
|
37
40
|
redirects
|
38
41
|
end
|
@@ -41,8 +44,11 @@ module Embiggen
|
|
41
44
|
timeout = request_options.fetch(:timeout) { Configuration.timeout }
|
42
45
|
|
43
46
|
location = http_client.follow(timeout)
|
44
|
-
|
45
|
-
|
47
|
+
unless followable?(location)
|
48
|
+
fail BadShortenedURI.new(
|
49
|
+
"following #{uri} did not redirect", uri
|
50
|
+
)
|
51
|
+
end
|
46
52
|
|
47
53
|
location
|
48
54
|
end
|
@@ -53,7 +59,8 @@ module Embiggen
|
|
53
59
|
Addressable::URI.parse(location).absolute?
|
54
60
|
rescue Addressable::URI::InvalidURIError => e
|
55
61
|
raise BadShortenedURI.new(
|
56
|
-
"following #{uri} returns an invalid URI: #{e}", uri
|
62
|
+
"following #{uri} returns an invalid URI: #{e}", uri
|
63
|
+
)
|
57
64
|
end
|
58
65
|
end
|
59
66
|
end
|
data/lib/embiggen.rb
CHANGED
@@ -2,7 +2,7 @@ require 'embiggen/configuration'
|
|
2
2
|
require 'embiggen/uri'
|
3
3
|
|
4
4
|
module Embiggen
|
5
|
-
def URI(uri)
|
5
|
+
def URI(uri) # rubocop:disable Naming/MethodName
|
6
6
|
uri.is_a?(URI) ? uri : URI.new(uri)
|
7
7
|
end
|
8
8
|
|
@@ -10,5 +10,6 @@ module Embiggen
|
|
10
10
|
yield(Configuration)
|
11
11
|
end
|
12
12
|
|
13
|
-
module_function :URI
|
13
|
+
module_function :URI
|
14
|
+
module_function :configure
|
14
15
|
end
|