simple_rss_parser 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_rss_parser.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jalendra Bhanarkar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # SimpleRssParser
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'simple_rss_parser'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install simple_rss_parser
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,145 @@
1
+ require "simple_rss_parser/version"
2
+ require 'net/http'
3
+ require 'sax-machine'
4
+
5
+ module SimpleRssParser
6
+ class MediaContent
7
+ include SAXMachine
8
+ attribute :url
9
+ end
10
+
11
+ class HrefTag
12
+ include SAXMachine
13
+ attribute :href, as: :url
14
+ end
15
+
16
+ class FeedImage
17
+ include SAXMachine
18
+ element :title
19
+ element :url
20
+ element :link
21
+ end
22
+
23
+ # Class for parsing an atom entry out of a feedburner atom feed
24
+ class FeedEntry
25
+ include SAXMachine
26
+ attr_accessor :media_image
27
+ #Title
28
+ element :title
29
+
30
+ #Author
31
+ element :author, :as => :author
32
+ element :"dc:creator" , :as => :author
33
+ element :name, :as => :author
34
+ element :"im:name", :as => :author
35
+ element :"itunes:author", :as => :author
36
+
37
+ # Description
38
+ element :summary, :as => :description
39
+ element :description, :as => :description
40
+ element :content, :as => :description
41
+ element :"itunes:summary", :as => :description
42
+
43
+ # link
44
+ element :link
45
+ element :"feedburner:origLink", :as => :link
46
+ element :link, :value => :href, :as => :link, :with => {:type => "text/html"}
47
+ element :link, :value=> :href, :as=> :link
48
+
49
+ # Published date
50
+ element :published, :as => :published
51
+ element :pubDate, :as => :published
52
+ element :pubdate, :as => :published
53
+ element :updated, :as => :published
54
+ element :issued, :as => :published
55
+ element :created, :as => :published
56
+ element :"dc:date", :as => :published
57
+ element :"dc:Date", :as => :published
58
+ element :"dcterms:created", :as => :published
59
+
60
+ # Media conetent
61
+ element :"media:content", :value=> :url, :as => :media_content#, :class => MediaContent
62
+ element :"media:thumbnail", :value=> :url, :as => :media_content
63
+ element :enclosure, :value=> :url, :as => :media_content#, :with=>{:type=>"image"}
64
+ element :"im:image", :as => :media_content
65
+ element :"itms:coverArt", :as => :media_content
66
+ element :"g:image_link", :as => :media_content
67
+ element :link, :value=> :href, :as => :media_content, :with => {:rel=>"enclosure"}
68
+
69
+ # Media Description
70
+ element :"media:description", :as => :media_description
71
+ element :"media:credit", :as => :media_credit
72
+
73
+ elements :"media:keywords", :as => :categories
74
+ elements :keywords, :as => :categories
75
+ elements :category, :as => :categories
76
+ elements :"itunes:keywords", :as => :categories
77
+
78
+ element :guid, :as => :entry_id
79
+ element :id, :as=> :entry_id
80
+
81
+ def media_image
82
+ (@media_content && @media_content =~ /.(jpg|jpeg|tiff|png)/i) ? @media_content : nil
83
+ end
84
+ end
85
+
86
+ # Class for parsing Atom feeds
87
+ class RssFeed
88
+ include SAXMachine
89
+
90
+ # Title
91
+ element :title
92
+
93
+ # Description
94
+ element :"itunes:summary", :as => :description
95
+ element :description, as: "description"
96
+ element :subtitle, :as => :description
97
+
98
+ # Language
99
+ element :language, as: "lang"
100
+
101
+ # link
102
+ element :link, :value => :href, :as => :link, :with => {:type => "text/html"}
103
+ element :link, :value => :href, :as => :link, :with => {:type => "application/atom+xml"}
104
+
105
+ # Keywords
106
+ elements :"itunes:keywords", :as => :keywords
107
+ elements :"itunes:category", :as => :keywords, :value => :text
108
+ elements :keywords
109
+
110
+ # Entries
111
+ elements :item, :as => :entries, :class => FeedEntry
112
+ elements :entry, :as => :entries, :class => FeedEntry
113
+
114
+ # Image
115
+ element :image, class: FeedImage
116
+ element :"itunes:image", :as => "image", class: HrefTag
117
+
118
+ def self.parse_rss_url(url)
119
+ xml = Net::HTTP.get(URI.parse(url))
120
+ if able_to_parse?(xml)
121
+ parse(xml)
122
+ else
123
+ begin
124
+ xml = open(url).read
125
+ able_to_parse?(xml) ? parse(xml) : nil
126
+ rescue Exception => e
127
+ nil
128
+ end
129
+ end
130
+ end
131
+
132
+ def self.able_to_parse?(xml)
133
+ # google
134
+ #%r{<id>https?://docs.google.com/.*\</id\>} =~ xml
135
+ # Atom and feedburner
136
+ # (/Atom/ =~ xml) && (/feedburner/ =~ xml)
137
+ # Itune
138
+ #/xmlns:itunes=\"http:\/\/www.itunes.com\/dtds\/podcast-1.0.dtd\"/i =~ xml
139
+ #Feedburner
140
+ #(/\<rss|\<rdf/ =~ xml) && (/feedburner/ =~ xml)
141
+ (/\<rss|\<rdf|\<feed/ =~ xml) || (%r{<id>https?://docs.google.com/.*\</id\>} =~ xml) || (/Atom/ =~ xml) || (/feedburner/ =~ xml) || (/xmlns:itunes=\"http:\/\/www.itunes.com\/dtds\/podcast-1.0.dtd\"/i =~ xml)
142
+ end
143
+
144
+ end
145
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleRssParser
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_rss_parser/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "simple_rss_parser"
8
+ gem.version = SimpleRssParser::VERSION
9
+ gem.authors = ["Jalendra Bhanarkar"]
10
+ gem.email = ["jbmyid@gmail.com"]
11
+ gem.description = "Parse almost all rss feeds"
12
+ gem.summary = "Used to parse rss feeds by specifying just url"
13
+ gem.homepage = "https://github.com/jbmyid/simple_rss_parser"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency "sax-machine"
20
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_rss_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jalendra Bhanarkar
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sax-machine
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Parse almost all rss feeds
31
+ email:
32
+ - jbmyid@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - lib/simple_rss_parser.rb
43
+ - lib/simple_rss_parser/version.rb
44
+ - simple_rss_parser.gemspec
45
+ homepage: https://github.com/jbmyid/simple_rss_parser
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Used to parse rss feeds by specifying just url
69
+ test_files: []