argh_ss 0.1.0 → 0.2.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 +31 -1
- data/lib/argh_ss/opml_import.rb +0 -4
- data/lib/argh_ss/rss_feed.rb +57 -3
- data/lib/argh_ss/version.rb +1 -1
- data/lib/argh_ss.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c85f92f9910ab64973fc4c3d1d19cd2e8b4f16d
|
4
|
+
data.tar.gz: bb1b101f138a9ce3afe6258914d446e29ce8c7aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67a64711e219e0eafd7f4b8117b81e5146f25236bd06b6570d0635fd3686faa0129549e14d6c55f2fbd15b483375dbae7a5c2c5d1eae36ad089d1237b861239b
|
7
|
+
data.tar.gz: 0114ab67718fdcb780176b342dff39fb861cda80a30be0b267e8e1d2a433bea53dd5f92ccde5886268c880d6fc6d3551210a1a327833bc5b36af65763abe2469
|
data/README.md
CHANGED
@@ -21,7 +21,9 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## RSS Feeds
|
23
23
|
|
24
|
-
|
24
|
+
2 options for RSS feeds, RSSFeed.feed and RSSFeed.feed_options
|
25
|
+
|
26
|
+
To output a simple hash with the feed title and feed url:
|
25
27
|
|
26
28
|
```ruby
|
27
29
|
{"Article Title"=>"https://www.article.com/feed_url"}
|
@@ -33,6 +35,33 @@ url = "https://www.theguardian.com/world/rss"
|
|
33
35
|
RSSFeed.feed(url)
|
34
36
|
```
|
35
37
|
|
38
|
+
To give you more options you can output an array with a hash of your options:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
[
|
42
|
+
{
|
43
|
+
:title => "Headline here",
|
44
|
+
:link => "http://my_url.here",
|
45
|
+
:content => "All of the posted articles RSS content here",
|
46
|
+
:published => "date object from feed here"
|
47
|
+
}
|
48
|
+
]
|
49
|
+
```
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
url = "https://www.theguardian.com/world/rss"
|
53
|
+
RSSFeed.feed_options(url)
|
54
|
+
```
|
55
|
+
|
56
|
+
By default, the options will give you: :title, :link, :content, :published.
|
57
|
+
But, you can choose your options. For example, if you only wanted the title, link and content, you would do the following:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
url = "https://www.theguardian.com/world/rss"
|
61
|
+
RSSFeed.feed_options(url, :title, :link, :content)
|
62
|
+
```
|
63
|
+
|
64
|
+
|
36
65
|
## OPML Import
|
37
66
|
|
38
67
|
For OPML import it will once again output a hash as "title": "url"
|
@@ -42,6 +71,7 @@ file = "./my_important.opml"
|
|
42
71
|
OPMLImport.new(file).to_hash
|
43
72
|
```
|
44
73
|
|
74
|
+
Note, opml import will be in perpetual alpha due to low use
|
45
75
|
The gem is designed to skip over errors, so if you have an RSS feed url that isn't standard, or an OPML file that doesn't proprly parse with nokogiri, it will fail quietly and move on.
|
46
76
|
|
47
77
|
## License
|
data/lib/argh_ss/opml_import.rb
CHANGED
data/lib/argh_ss/rss_feed.rb
CHANGED
@@ -1,8 +1,42 @@
|
|
1
|
-
require 'rss'
|
2
|
-
require 'open-uri'
|
3
|
-
|
4
1
|
class RSSFeed
|
5
2
|
|
3
|
+
DEFAULT_OPTIONS = [:title, :link, :content, :published]
|
4
|
+
|
5
|
+
def self.options_feed(url, *args)
|
6
|
+
raise ArgumentError, "Incorrect options" unless args & DEFAULT_OPTIONS == args
|
7
|
+
args = DEFAULT_OPTIONS if args.empty?
|
8
|
+
|
9
|
+
[].tap do |result|
|
10
|
+
open(url) do |rss|
|
11
|
+
begin
|
12
|
+
feed = RSS::Parser.parse(rss)
|
13
|
+
case feed.feed_type
|
14
|
+
when 'rss'
|
15
|
+
feed.items.each do |item|
|
16
|
+
hash = {}
|
17
|
+
args.each do |content|
|
18
|
+
hash[content] = item.send(rss_hash[content])
|
19
|
+
end
|
20
|
+
result << hash
|
21
|
+
end
|
22
|
+
when 'atom'
|
23
|
+
feed.entries.each do |entry|
|
24
|
+
hash = {}
|
25
|
+
args.each do |content|
|
26
|
+
args_array = atom_hash[content]
|
27
|
+
hash[content] = entry.send(args_array[0]).send(args_array[1])
|
28
|
+
end
|
29
|
+
result << hash
|
30
|
+
end
|
31
|
+
end
|
32
|
+
rescue
|
33
|
+
next
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
6
40
|
def self.feed(url)
|
7
41
|
{}.tap do |result|
|
8
42
|
open(url) do |rss|
|
@@ -21,4 +55,24 @@ class RSSFeed
|
|
21
55
|
end
|
22
56
|
end
|
23
57
|
|
58
|
+
private
|
59
|
+
|
60
|
+
def self.rss_hash
|
61
|
+
{
|
62
|
+
:title => "title",
|
63
|
+
:link => "link",
|
64
|
+
:content => "description",
|
65
|
+
:published => "pubDate"
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.atom_hash
|
70
|
+
{
|
71
|
+
:title => ["title", "content"],
|
72
|
+
:link => ["link", "href"],
|
73
|
+
:content => ["summary", "content"],
|
74
|
+
:published => ["published", "content"]
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
24
78
|
end
|
data/lib/argh_ss/version.rb
CHANGED
data/lib/argh_ss.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: argh_ss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toby Holmes
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|