arssene 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CHANGE_LOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +184 -0
- data/Rakefile +6 -0
- data/arssene.gemspec +44 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/arssene.rb +10 -0
- data/lib/arssene/lib/rss.rb +175 -0
- data/lib/arssene/version.rb +3 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 204b4d985ba3c67aaf3d0e477b55916195a033730570b7e35e4591d66fcfaedd
|
4
|
+
data.tar.gz: 04614420d84d52b54a4718e219cca9c060f8203db4c41c303b7b7267793e5eae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 596c6c43e7dd6a6b91d0f8d039d3745475e4884ae8b434f8c586cdfa01de332425e2dd3ca1391e5f46335a70e72fd1481e1450ebeceb1f6d6b7eb2c71079f11c
|
7
|
+
data.tar.gz: 9a402d8a71cc895b82d66a27750c1d89d7a04dd62ae84ebf3b8ad635f27f118fc4c9227ba40bbcb2d4fbe5511ee1ccec3555a045708d01cf225e51093c216615
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGE_LOG.md
ADDED
File without changes
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at carrasco.vic@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
arssene (0.1.0)
|
5
|
+
mechanize
|
6
|
+
sanitize
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
connection_pool (2.2.2)
|
12
|
+
crass (1.0.4)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
domain_name (0.5.20180417)
|
15
|
+
unf (>= 0.0.5, < 1.0.0)
|
16
|
+
http-cookie (1.0.3)
|
17
|
+
domain_name (~> 0.5)
|
18
|
+
mechanize (2.7.6)
|
19
|
+
domain_name (~> 0.5, >= 0.5.1)
|
20
|
+
http-cookie (~> 1.0)
|
21
|
+
mime-types (>= 1.17.2)
|
22
|
+
net-http-digest_auth (~> 1.1, >= 1.1.1)
|
23
|
+
net-http-persistent (>= 2.5.2)
|
24
|
+
nokogiri (~> 1.6)
|
25
|
+
ntlm-http (~> 0.1, >= 0.1.1)
|
26
|
+
webrobots (>= 0.0.9, < 0.2)
|
27
|
+
mime-types (3.2.2)
|
28
|
+
mime-types-data (~> 3.2015)
|
29
|
+
mime-types-data (3.2019.0331)
|
30
|
+
mini_portile2 (2.4.0)
|
31
|
+
net-http-digest_auth (1.4.1)
|
32
|
+
net-http-persistent (3.0.1)
|
33
|
+
connection_pool (~> 2.2)
|
34
|
+
nokogiri (1.10.3)
|
35
|
+
mini_portile2 (~> 2.4.0)
|
36
|
+
nokogumbo (2.0.1)
|
37
|
+
nokogiri (~> 1.8, >= 1.8.4)
|
38
|
+
ntlm-http (0.1.1)
|
39
|
+
rake (10.5.0)
|
40
|
+
rspec (3.8.0)
|
41
|
+
rspec-core (~> 3.8.0)
|
42
|
+
rspec-expectations (~> 3.8.0)
|
43
|
+
rspec-mocks (~> 3.8.0)
|
44
|
+
rspec-core (3.8.0)
|
45
|
+
rspec-support (~> 3.8.0)
|
46
|
+
rspec-expectations (3.8.3)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.8.0)
|
49
|
+
rspec-mocks (3.8.0)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.8.0)
|
52
|
+
rspec-support (3.8.0)
|
53
|
+
sanitize (5.0.0)
|
54
|
+
crass (~> 1.0.2)
|
55
|
+
nokogiri (>= 1.8.0)
|
56
|
+
nokogumbo (~> 2.0)
|
57
|
+
unf (0.1.4)
|
58
|
+
unf_ext
|
59
|
+
unf_ext (0.0.7.6)
|
60
|
+
webrobots (0.1.2)
|
61
|
+
|
62
|
+
PLATFORMS
|
63
|
+
ruby
|
64
|
+
|
65
|
+
DEPENDENCIES
|
66
|
+
arssene!
|
67
|
+
bundler (~> 2.0)
|
68
|
+
rake (~> 10.0)
|
69
|
+
rspec (~> 3.0)
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Vic Carrasco
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
# Arssene
|
2
|
+
|
3
|
+
Simple RSS solution for rails.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'arssene'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install arssene
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Ping a website
|
24
|
+
To obtain the rss feed of a website, first you should ping the website.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
url = "https://www.theonion.com/"
|
28
|
+
rss = Arssene::Feed.ping(url)
|
29
|
+
|
30
|
+
puts rss
|
31
|
+
# => [ {:feed => "https://www.theonion.com/rss"} ]
|
32
|
+
```
|
33
|
+
|
34
|
+
You can also send an array of urls, but keep in mind performance, as each website will be pinged individually.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
urls = ["http://www.lifehacker.com", "http://www.deadspin.com", "https://www.kotaku.com"]
|
38
|
+
rss = Arssene::Feed.ping(urls)
|
39
|
+
puts rss
|
40
|
+
# =>
|
41
|
+
# [
|
42
|
+
# { :feed => "https://www.lifehacker.com/rss" },
|
43
|
+
# { :feed => "http://www.deadspin.com/rss" },
|
44
|
+
# { :feed => "http://www.kotaku.com/rss"}
|
45
|
+
# ]
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
If no valid feed was found, the result will be an empty array. If there's an error with the website or its feed, a response with an error will be issued.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
url = "http://www.anime-town.com"
|
53
|
+
rss = Arssene::Feed.ping(url)
|
54
|
+
puts rss
|
55
|
+
|
56
|
+
# =>
|
57
|
+
# [
|
58
|
+
# {
|
59
|
+
# :error=> 500 => Net::HTTPInternalServerError for http://www.anime-town.com/
|
60
|
+
# }
|
61
|
+
# ]
|
62
|
+
```
|
63
|
+
|
64
|
+
If you send an array of websites that are mixed (valid/invalid) the result will be like so:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
urls = ["http://www.lifehacker.com", "http://www.anime-town.com"]
|
68
|
+
rss = Arssene::Feed.ping(urls)
|
69
|
+
puts rss
|
70
|
+
|
71
|
+
# =>
|
72
|
+
# [
|
73
|
+
# { :feed => "https://lifehacker.com/rss" } ,
|
74
|
+
# { :error => 500 => Net::HTTPInternalServerError for http://www.anime-town.com/ }
|
75
|
+
# ]
|
76
|
+
```
|
77
|
+
|
78
|
+
## Request
|
79
|
+
|
80
|
+
Once you have the correct URL for the feed, you can request the website's feed. You can also pass an array of urls such as like in the ping method.
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
url = "https://www.lifehacker.com/rss"
|
84
|
+
rss = Arssene::Feed.request(url)
|
85
|
+
# =>
|
86
|
+
# {
|
87
|
+
# :feed => "https://www.lifehacker.com/rss",
|
88
|
+
# :channel => <Arssene::Channel:0x00007f0dbc011500>
|
89
|
+
# }
|
90
|
+
|
91
|
+
# Where if your feed is rss[:channel], you could:
|
92
|
+
feed = rss[:channel]
|
93
|
+
|
94
|
+
puts rss.title
|
95
|
+
# => Lifehacker
|
96
|
+
|
97
|
+
puts rss.link
|
98
|
+
# => https://www.lifehacker.com
|
99
|
+
|
100
|
+
puts rss.feed_type
|
101
|
+
# => rss
|
102
|
+
|
103
|
+
puts rss.feed_version
|
104
|
+
# => 2.0
|
105
|
+
|
106
|
+
puts rss.description
|
107
|
+
# => Do everything better
|
108
|
+
|
109
|
+
puts rss.language
|
110
|
+
# => en
|
111
|
+
|
112
|
+
puts rss.relevant
|
113
|
+
# => true
|
114
|
+
|
115
|
+
puts rss.entries[0] # Array of type Entry
|
116
|
+
# =>
|
117
|
+
# title: RAVPower Struck a 61 Watt Blow In the USB-C GaN Wars
|
118
|
+
# link: https://theinventory.com/ravpower-struck-a-61-watt-blow-in-the-usb-c-gan-wars-1834586407
|
119
|
+
# description: <p> Description in html </p>
|
120
|
+
# publication_date: 2019-05-13 16:15:00.000000000 +00:00
|
121
|
+
# author:
|
122
|
+
# content:
|
123
|
+
```
|
124
|
+
|
125
|
+
## Options
|
126
|
+
You can send an additional parameter to the request method with a hash of options to filter the response of the feed.
|
127
|
+
|
128
|
+
### :ignore parameter
|
129
|
+
If you'd like to filter feeds that include the following words in the title, you can by doing the following:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
ignore = ["comment", "comments", "store", "corporate"]
|
133
|
+
|
134
|
+
url = "https://ignore-feed-website.com/rss"
|
135
|
+
rss = Arssene::Feed.request(url, { :ignore => ignore })
|
136
|
+
```
|
137
|
+
If Arssene finds that the feed is not relevant according to your parameters it will result in a change the 'relevant' property to false. Otherwise, by default all feeds return true for the 'relevant' property.
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
feed = rss[:channel]
|
141
|
+
puts feed.relevant
|
142
|
+
|
143
|
+
# => false
|
144
|
+
```
|
145
|
+
|
146
|
+
### :from_date parameter
|
147
|
+
You can specify the date from which you'd like to include entries. The :from_date parameter does NOT include the entries of the date sent.
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
last_days = DateTime.now - 2
|
151
|
+
# => 2019-05-12T15:45:49+02:00
|
152
|
+
|
153
|
+
url = "https://www.kotaku.com/rss"
|
154
|
+
rss = Arssene::Feed.request(url, { :from_date => last_days })
|
155
|
+
```
|
156
|
+
Entries will include only from the date specifed all the way up to the newest. If you'd like to include the day you need, you can send an aditional day to the :from_date parmeter.
|
157
|
+
|
158
|
+
### :limit parameter
|
159
|
+
You can also specify a limit of entries that you'd like to receive for a given result.
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
url = "https://www.kotaku.com/rss"
|
163
|
+
rss = Arssene::Feed.request(url, { :limit => 5 })
|
164
|
+
|
165
|
+
feed = rss[:channel]
|
166
|
+
|
167
|
+
# Should be the latest 5
|
168
|
+
puts feed.entries.length
|
169
|
+
# => 5
|
170
|
+
```
|
171
|
+
|
172
|
+
You can also combine any of the three specified parameters to suit your request.
|
173
|
+
|
174
|
+
## Contributing
|
175
|
+
|
176
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/viccarrasco/arssene. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
177
|
+
|
178
|
+
## License
|
179
|
+
|
180
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
181
|
+
|
182
|
+
## Code of Conduct
|
183
|
+
|
184
|
+
Everyone interacting in the Arssene project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/viccarrasco/arssene/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/arssene.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "arssene/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "arssene"
|
8
|
+
spec.version = Arssene::VERSION
|
9
|
+
spec.authors = ["Vic Carrasco"]
|
10
|
+
spec.email = ["vic@viccarrasco.com"]
|
11
|
+
|
12
|
+
spec.summary = "Simple RSS solution for rails"
|
13
|
+
spec.description = "Gem for retrieving entries from RSS feeds given the URL of a feed or website"
|
14
|
+
spec.homepage = "https://github.com/viccarrasco/arssene"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/viccarrasco/arssene"
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/viccarrasco/arssene/blob/master/CHANGE_LOG.md"
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
42
|
+
spec.add_dependency "mechanize", "~> 0"
|
43
|
+
spec.add_dependency "sanitize", "~> 0"
|
44
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "arssene"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/arssene.rb
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
module Arssene
|
2
|
+
class Channel
|
3
|
+
attr_accessor :title
|
4
|
+
attr_accessor :link
|
5
|
+
attr_accessor :host
|
6
|
+
attr_accessor :feed_type
|
7
|
+
attr_accessor :feed_version
|
8
|
+
attr_accessor :description
|
9
|
+
attr_accessor :publication_date
|
10
|
+
attr_accessor :language
|
11
|
+
attr_accessor :copyright
|
12
|
+
attr_accessor :entries
|
13
|
+
attr_accessor :meta
|
14
|
+
attr_accessor :relevant
|
15
|
+
end
|
16
|
+
|
17
|
+
class Entry
|
18
|
+
attr_accessor :title
|
19
|
+
attr_accessor :link
|
20
|
+
attr_accessor :description
|
21
|
+
attr_accessor :content
|
22
|
+
attr_accessor :publication_date
|
23
|
+
attr_accessor :author
|
24
|
+
end
|
25
|
+
|
26
|
+
class Feed
|
27
|
+
def self.ping(uri)
|
28
|
+
response = []
|
29
|
+
begin
|
30
|
+
if uri.is_a?(String)
|
31
|
+
feed_uris = Feed.retrieve(uri)
|
32
|
+
if feed_uris
|
33
|
+
feed_uris.each do |feed|
|
34
|
+
link = (feed.attr('href')).split.join
|
35
|
+
response.push({:feed => link})
|
36
|
+
end
|
37
|
+
end
|
38
|
+
elsif uri.is_a?(Array)
|
39
|
+
uri.each do |url|
|
40
|
+
Thread.new {
|
41
|
+
begin
|
42
|
+
feed_uris = Feed.retrieve(url)
|
43
|
+
if feed_uris
|
44
|
+
feed_uris.each do |feed|
|
45
|
+
link = (feed.attr('href')).split.join
|
46
|
+
response.push({:feed => link})
|
47
|
+
end
|
48
|
+
end
|
49
|
+
rescue => exception
|
50
|
+
response.push({:error => exception})
|
51
|
+
end
|
52
|
+
}.join
|
53
|
+
end
|
54
|
+
else
|
55
|
+
[]
|
56
|
+
end
|
57
|
+
response
|
58
|
+
rescue => exception
|
59
|
+
response.push({:error => exception})
|
60
|
+
end
|
61
|
+
response
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.request(uri, options = {})
|
65
|
+
response = []
|
66
|
+
|
67
|
+
begin
|
68
|
+
if uri.is_a?(String)
|
69
|
+
channel = fetch(uri, options)
|
70
|
+
if (channel.is_a?(Hash) && channel.has_key?(:error))
|
71
|
+
return ({:error => channel[:error]})
|
72
|
+
else
|
73
|
+
channel = self.filter_by_options(channel, options)
|
74
|
+
return ({:feed => uri, :channel => channel})
|
75
|
+
end
|
76
|
+
elsif uri.is_a?(Array)
|
77
|
+
uri.each do |url|
|
78
|
+
Thread.new {
|
79
|
+
channel = fetch(url, options)
|
80
|
+
if (channel.is_a?(Hash) && channel.has_key?(:error))
|
81
|
+
response.push({:error => channel[:error]})
|
82
|
+
else
|
83
|
+
channel = self.filter_by_options(channel, options)
|
84
|
+
response.push({:feed => url, :channel => channel})
|
85
|
+
end
|
86
|
+
}.join
|
87
|
+
end
|
88
|
+
else
|
89
|
+
[]
|
90
|
+
end
|
91
|
+
rescue => exception
|
92
|
+
response.push({:error => exception})
|
93
|
+
end
|
94
|
+
response
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
def self.fetch(uri, options)
|
99
|
+
begin
|
100
|
+
channel = Channel.new
|
101
|
+
open(uri) do |rss|
|
102
|
+
feed = RSS::Parser.parse(rss)
|
103
|
+
uri = URI.parse(feed.channel.link)
|
104
|
+
channel.title = feed.channel.title
|
105
|
+
channel.link = feed.channel.link
|
106
|
+
channel.host = uri.host
|
107
|
+
channel.feed_type = feed.feed_type
|
108
|
+
channel.feed_version= feed.feed_version
|
109
|
+
channel.description = feed.channel.description
|
110
|
+
channel.publication_date = feed.channel.pubDate
|
111
|
+
channel.language = (feed.channel.language) ? feed.channel.language.downcase : nil
|
112
|
+
channel.copyright = feed.channel.copyright
|
113
|
+
channel.entries = extract_items feed
|
114
|
+
channel.meta = feed
|
115
|
+
channel.relevant = true
|
116
|
+
end
|
117
|
+
rescue => exception
|
118
|
+
return ({ :error => exception })
|
119
|
+
end
|
120
|
+
channel
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.filter_by_options(channel, options)
|
124
|
+
if options.has_key?(:ignore)
|
125
|
+
title = channel.title.downcase.split.join
|
126
|
+
ignore = options[:ignore]
|
127
|
+
ignore = (ignore.is_a?(Array)) ? (ignore = ignore.join('|')) : ignore
|
128
|
+
rxp = /.?(#{ignore}).?/
|
129
|
+
|
130
|
+
channel.relevant = (rxp.match(title) == false || rxp.match(title) == nil)
|
131
|
+
end
|
132
|
+
|
133
|
+
if options.has_key?(:from_date)
|
134
|
+
if channel.entries.length > 0
|
135
|
+
index = channel.entries.index {|entry| entry.publication_date == options[:from_date]}
|
136
|
+
channel.entries = (index) ? channel.entries.slice(0..index) : channel.entries
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
if options.has_key?(:limit)
|
141
|
+
limit = (options[:limit]-1)
|
142
|
+
channel.entries = channel.entries.slice(0..limit) if (channel.entries.length > limit)
|
143
|
+
end
|
144
|
+
channel
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.retrieve(uri)
|
148
|
+
agent = Mechanize.new
|
149
|
+
uri = URI.parse(uri)
|
150
|
+
site = agent.get(uri)
|
151
|
+
site.search(".//link[@type='application/rss+xml']")
|
152
|
+
end
|
153
|
+
|
154
|
+
def self.extract_items(feed)
|
155
|
+
items = []
|
156
|
+
feed.items.each do |i|
|
157
|
+
entry = Entry.new
|
158
|
+
entry.title = i.title
|
159
|
+
entry.link = i.link
|
160
|
+
entry.description = i.description
|
161
|
+
entry.publication_date = i.pubDate
|
162
|
+
entry.author = i.author
|
163
|
+
if i.respond_to?("content")
|
164
|
+
entry.content = i.content
|
165
|
+
elsif i.respond_to?("content_encoded")
|
166
|
+
entry.content = i.content_encoded
|
167
|
+
else
|
168
|
+
entry.content = entry.description
|
169
|
+
end
|
170
|
+
items.push(entry)
|
171
|
+
end
|
172
|
+
items
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arssene
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vic Carrasco
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mechanize
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sanitize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Gem for retrieving entries from RSS feeds given the URL of a feed or
|
84
|
+
website
|
85
|
+
email:
|
86
|
+
- vic@viccarrasco.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CHANGE_LOG.md
|
95
|
+
- CODE_OF_CONDUCT.md
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.lock
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- arssene.gemspec
|
102
|
+
- bin/console
|
103
|
+
- bin/setup
|
104
|
+
- lib/arssene.rb
|
105
|
+
- lib/arssene/lib/rss.rb
|
106
|
+
- lib/arssene/version.rb
|
107
|
+
homepage: https://github.com/viccarrasco/arssene
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata:
|
111
|
+
allowed_push_host: https://rubygems.org
|
112
|
+
homepage_uri: https://github.com/viccarrasco/arssene
|
113
|
+
source_code_uri: https://github.com/viccarrasco/arssene
|
114
|
+
changelog_uri: https://github.com/viccarrasco/arssene/blob/master/CHANGE_LOG.md
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.7.7
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Simple RSS solution for rails
|
135
|
+
test_files: []
|