argh_ss 0.2.2 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5998a9239fc2d95047ee97a6f8c025d3dc521217
4
- data.tar.gz: a3f1a20884ce466082741da88b556d215051c2ba
3
+ metadata.gz: e6c677377b4509e88a84daec6bd878144278d40c
4
+ data.tar.gz: '0513209f985af376a7f075555bc00bd83d67f86b'
5
5
  SHA512:
6
- metadata.gz: e7484ae37f7bc71c190f87f6748bc2f0079065d3c443e7c95989fbe44da719201b5467df7dd8d85827666683fd5c26653f3c0ee2b3704fcf6a1b79b7427a1e31
7
- data.tar.gz: 438de64dc6a32609ed5692d1c5f60dd4cf9be2620238500c31d8ebaa71b6cc15935202af4ff1eae63713e9b758c64f8ed5a5d7ef4f19c93e4b6d8be96a571bc6
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
@@ -1,3 +1,3 @@
1
1
  module ArghSs
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/argh_ss.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require "argh_ss/version"
2
2
  require "argh_ss/rss_feed"
3
+ require "argh_ss/resolve_url"
3
4
  require "argh_ss/opml_import"
4
5
  require 'rss'
5
6
  require 'open-uri'
6
7
  require 'nokogiri'
7
-
8
+ require 'net/http'
8
9
 
9
10
  module ArghSs
10
11
  # Your code goes here...
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.2.2
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