argh_ss 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/lib/argh_ss/resolve_url.rb +19 -0
- data/lib/argh_ss/version.rb +1 -1
- data/lib/argh_ss.rb +2 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6c677377b4509e88a84daec6bd878144278d40c
|
4
|
+
data.tar.gz: '0513209f985af376a7f075555bc00bd83d67f86b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 381e350ee0d910ba36f1889a6c3c7ca335a49f44e15a0e370ffd868f6e2c8ff089c6e1087c1f8b6d4e63238d63ff52fbaa4e7d6175b0efce4d4c1a3044c7627d
|
7
|
+
data.tar.gz: 9a3f9e48b09b06ab1d3433e2c06fcda28d226d6ce2a87e8e69244d306da07e6fcad5715d8e12fa1a8b13e463bb95b6b0141ef39023cc21f1641bfb26c5721555
|
data/README.md
CHANGED
@@ -61,6 +61,19 @@ url = "https://www.theguardian.com/world/rss"
|
|
61
61
|
RSSFeed.options_feed(url, :title, :link, :content)
|
62
62
|
```
|
63
63
|
|
64
|
+
## Resolving URL
|
65
|
+
|
66
|
+
The best way to avoid errors when parsing RSS feeds is having the correct URL.
|
67
|
+
ResolveURL will help with this, by following the redirects.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
url = 'http://www.newyorktimes.com'
|
71
|
+
ResolveURL.resolve(url)
|
72
|
+
```
|
73
|
+
|
74
|
+
This code is mostly from [here](https://ruby-doc.org/stdlib-2.3.2/libdoc/net/http/rdoc/Net/HTTP.html#class-Net::HTTP-label-Following+Redirection).
|
75
|
+
|
76
|
+
This will raise exception after 10 redirects.
|
64
77
|
|
65
78
|
## OPML Import
|
66
79
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class ResolveURL
|
2
|
+
|
3
|
+
def self.resolve(uri_str, limit = 10)
|
4
|
+
raise ArgumentError, 'Too many redirects!' if limit == 0
|
5
|
+
|
6
|
+
response = Net::HTTP.get_response(URI(uri_str))
|
7
|
+
|
8
|
+
case response
|
9
|
+
when Net::HTTPSuccess then
|
10
|
+
uri_str
|
11
|
+
when Net::HTTPRedirection then
|
12
|
+
location = response['location']
|
13
|
+
resolve(location, limit - 1)
|
14
|
+
else
|
15
|
+
uri_str
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/argh_ss/version.rb
CHANGED
data/lib/argh_ss.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: argh_ss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toby Holmes
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- bin/setup
|
71
71
|
- lib/argh_ss.rb
|
72
72
|
- lib/argh_ss/opml_import.rb
|
73
|
+
- lib/argh_ss/resolve_url.rb
|
73
74
|
- lib/argh_ss/rss_feed.rb
|
74
75
|
- lib/argh_ss/version.rb
|
75
76
|
homepage: https://github.com/tobyond/argh_ss
|