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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b1dbd19a7036b3dad1815590b9208d50453a988
4
- data.tar.gz: 51a8b19ccc870a2e758b8cec1fdbe52ea7cf5e7c
3
+ metadata.gz: 5c85f92f9910ab64973fc4c3d1d19cd2e8b4f16d
4
+ data.tar.gz: bb1b101f138a9ce3afe6258914d446e29ce8c7aa
5
5
  SHA512:
6
- metadata.gz: 1953a3775265edb1bd92a54edb62b54a8ae2f7327060fc93a81084dfb16e703d59c171acdcd8360392b2efce4d6aca62c0cf15a74c601453ea6f53a2c94ff127
7
- data.tar.gz: f58c53f2c3ed546d2a25904fe8627edb4e664fbd055b83e72abd95e0fb78dcc8dade9c0e7a8a24747b4ececa638e7ae83751716f17b2e6cd4d4cdc111b639b45
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
- There are currently 2 basic functionalities, reading a feed and outputting the feed to a hash as "title": "url" eg.
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
@@ -1,7 +1,3 @@
1
- require 'rss'
2
- require 'open-uri'
3
- require 'nokogiri'
4
-
5
1
  class OPMLImport
6
2
  attr_reader :opml ,:to_hash
7
3
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ArghSs
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/argh_ss.rb CHANGED
@@ -3,6 +3,8 @@ require "argh_ss/rss_feed"
3
3
  require "argh_ss/opml_import"
4
4
  require 'rss'
5
5
  require 'open-uri'
6
+ require 'nokogiri'
7
+
6
8
 
7
9
  module ArghSs
8
10
  # Your code goes here...
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.1.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-14 00:00:00.000000000 Z
11
+ date: 2016-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler