embiggen 1.5.0 → 1.7.0
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.
- 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 +1190 -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 +41 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69f8ac1c0eb0aef13e8eeba8fc0f221c585ff3320f63dfe2435705313ad9e8c5
|
4
|
+
data.tar.gz: 448daaffc9709b857ba9800ac9f04011abde20410750895fc13fb9cfac12d453
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b11c31be2eb16103312bc0c69d397145001cabab566b43cca9f287cd11b3cff446f964743088867f140ed679753011373fd50d17297a2959a7de1e220ca4f32
|
7
|
+
data.tar.gz: ca096318601a7b30dbb6a0a29d0555071e0b910debbd96a943f0712342e3f77be49870add459b4d4e4ceb05b6c5c122f33330c9ba87383b9b323381af696a6d3
|
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.7.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.7'
|
12
12
|
```
|
13
13
|
|
14
14
|
Or, in your `Gemfile`:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem 'embiggen', '~> 1.
|
17
|
+
gem 'embiggen', '~> 1.7'
|
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
|