pluto-update 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +0 -2
- data/Rakefile +1 -1
- data/lib/pluto/update.rb +0 -1
- data/lib/pluto/update/feed_refresher.rb +3 -12
- data/lib/pluto/update/site_refresher.rb +2 -9
- data/lib/pluto/update/version.rb +1 -1
- data/test/test_refresh.rb +1 -2
- metadata +4 -7
- data/lib/pluto/update/site_updater.rb +0 -162
- data/test/test_site.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cab5151cc7be3216603e278be99cf277f8272e3
|
4
|
+
data.tar.gz: f263272dc082e8711c86b35b483d5c728ae3e84b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9f15b1922b07931ced857ae9da048cce89d13fe3bde2fdec09600869752aaa9424fca3dd1e42d6f2ae159b59e797c8fc8cc5cdc6533bbab0d70cb0c0776855d
|
7
|
+
data.tar.gz: 2d3a986e53d7d81a8817753ed9272056b0fe59cf7835af224237d9fc595de2be3fd0f4770b4b042ec03ddd16a4aa8b27577225f8ffc8c0e1fac17c6700a579e4
|
data/Manifest.txt
CHANGED
@@ -6,9 +6,7 @@ lib/pluto/update.rb
|
|
6
6
|
lib/pluto/update/feed_refresher.rb
|
7
7
|
lib/pluto/update/site_fetcher.rb
|
8
8
|
lib/pluto/update/site_refresher.rb
|
9
|
-
lib/pluto/update/site_updater.rb
|
10
9
|
lib/pluto/update/version.rb
|
11
10
|
test/data/ruby.ini
|
12
11
|
test/helper.rb
|
13
12
|
test/test_refresh.rb
|
14
|
-
test/test_site.rb
|
data/Rakefile
CHANGED
data/lib/pluto/update.rb
CHANGED
@@ -69,7 +69,7 @@ private
|
|
69
69
|
# on error or if http-not modified etc. skip update/processing
|
70
70
|
return if feed_xml.nil?
|
71
71
|
|
72
|
-
feed =
|
72
|
+
feed = FeedParser::Parser.parse( feed_xml )
|
73
73
|
|
74
74
|
## fix/todo: reload feed_red - fetched date updated etc.
|
75
75
|
## check if needed for access to fetched date
|
@@ -93,17 +93,8 @@ private
|
|
93
93
|
|
94
94
|
## fix/todo: pass debug flag as opts - debug: true|false !!!!!!
|
95
95
|
# fix/todo: find a better name - why? why not?? => use update_from_struct!
|
96
|
-
feed_rec.
|
97
|
-
|
98
|
-
# update cached value last published for item
|
99
|
-
last_item_rec = feed_rec.items.latest.limit(1).first # note limit(1) will return relation/arrar - use first to get first element or nil from ary
|
100
|
-
if last_item_rec.present?
|
101
|
-
if last_item_rec.published?
|
102
|
-
feed_rec.update_attributes!( last_published: last_item_rec.published )
|
103
|
-
else # try touched
|
104
|
-
feed_rec.update_attributes!( last_published: last_item_rec.touched )
|
105
|
-
end
|
106
|
-
end
|
96
|
+
feed_rec.deep_update_from_struct!( feed )
|
97
|
+
|
107
98
|
end # method refresh_feed_worker
|
108
99
|
|
109
100
|
end # class FeedRefresher
|
@@ -50,15 +50,8 @@ private
|
|
50
50
|
|
51
51
|
site_config = INI.load( site_text )
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
### todo/fix:
|
57
|
-
## allow passing in as first arg database rec!!!
|
58
|
-
## - if passed in database rec - do NOT lookup record by site_config.key!!!
|
59
|
-
## use existing key (lets you change/update key without creating a new duplicate site entry, for example)
|
60
|
-
## - or use a new method (instead of overloading arg) ?? - why? why not??
|
61
|
-
site_updater.update_subscriptions_for( site_rec.key, site_config )
|
53
|
+
### site_rec.debug = debug? ? true : false # pass along debug flag
|
54
|
+
site_rec.deep_update_from_hash!( site_config )
|
62
55
|
end
|
63
56
|
|
64
57
|
end # class SiteRefresher
|
data/lib/pluto/update/version.rb
CHANGED
data/test/test_refresh.rb
CHANGED
@@ -19,8 +19,7 @@ class TestRefresh < MiniTest::Test
|
|
19
19
|
site_text = File.read( "#{PlutoUpdate.root}/test/data/ruby.ini")
|
20
20
|
site_config = INI.load( site_text )
|
21
21
|
|
22
|
-
|
23
|
-
site_updater.update_subscriptions_for( 'ruby', site_config )
|
22
|
+
Site.deep_create_or_update_from_hash!( 'ruby', site_config )
|
24
23
|
end
|
25
24
|
|
26
25
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluto-update
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pluto-models
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.4.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.4.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pluto-feedfetcher
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,12 +112,10 @@ files:
|
|
112
112
|
- lib/pluto/update/feed_refresher.rb
|
113
113
|
- lib/pluto/update/site_fetcher.rb
|
114
114
|
- lib/pluto/update/site_refresher.rb
|
115
|
-
- lib/pluto/update/site_updater.rb
|
116
115
|
- lib/pluto/update/version.rb
|
117
116
|
- test/data/ruby.ini
|
118
117
|
- test/helper.rb
|
119
118
|
- test/test_refresh.rb
|
120
|
-
- test/test_site.rb
|
121
119
|
homepage: https://github.com/feedreader/pluto.update
|
122
120
|
licenses:
|
123
121
|
- Public Domain
|
@@ -145,5 +143,4 @@ signing_key:
|
|
145
143
|
specification_version: 4
|
146
144
|
summary: pluto-update - planet feed 'n' subscription updater
|
147
145
|
test_files:
|
148
|
-
- test/test_site.rb
|
149
146
|
- test/test_refresh.rb
|
@@ -1,162 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
module Pluto
|
5
|
-
|
6
|
-
class SiteUpdater
|
7
|
-
|
8
|
-
include LogUtils::Logging
|
9
|
-
include Models
|
10
|
-
|
11
|
-
def debug=(value) @debug = value; end
|
12
|
-
def debug?() @debug || false; end
|
13
|
-
|
14
|
-
|
15
|
-
def update_subscriptions_for( name, config, opts={} )
|
16
|
-
|
17
|
-
## note: allow (optional) config of site key too
|
18
|
-
site_key = config['key'] || config['slug']
|
19
|
-
if site_key.nil?
|
20
|
-
## if no key configured; use (file)name; remove -_ chars
|
21
|
-
## e.g. jekyll-meta becomes jekyllmeta etc.
|
22
|
-
site_key = name.downcase.gsub( /[\-_]/, '' )
|
23
|
-
end
|
24
|
-
|
25
|
-
site_attribs = {
|
26
|
-
title: config['title'] || config['name'], # support either title or name
|
27
|
-
url: config['source'] || config['url'], # support source or url for source url for auto-update (optional)
|
28
|
-
author: config['author'] || config['owner'],
|
29
|
-
email: config['email'],
|
30
|
-
updated: Time.now, ## track last_update via pluto (w/ update_subscription_for fn)
|
31
|
-
}
|
32
|
-
|
33
|
-
logger.debug "site_attribs: #{site_attribs.inspect}"
|
34
|
-
|
35
|
-
site_rec = Site.find_by_key( site_key )
|
36
|
-
if site_rec.nil?
|
37
|
-
site_rec = Site.new
|
38
|
-
site_attribs[ :key ] = site_key
|
39
|
-
|
40
|
-
## use object_id: site.id and object_type: Site
|
41
|
-
## change - model/table/schema!!!
|
42
|
-
Activity.create!( text: "new site >#{site_key}< - #{site_attribs[ :title ]}" )
|
43
|
-
end
|
44
|
-
site_rec.update_attributes!( site_attribs )
|
45
|
-
|
46
|
-
# -- log update activity
|
47
|
-
Activity.create!( text: "update subscriptions for site >#{site_key}<" )
|
48
|
-
|
49
|
-
#### todo/fix:
|
50
|
-
## double check - how to handle delete
|
51
|
-
## feeds might get referenced by other sites
|
52
|
-
## cannot just delete feeds; only save to delete join table (subscriptions)
|
53
|
-
## check if feed "lingers" on with no reference (to site)???
|
54
|
-
|
55
|
-
# clean out subscriptions and add again
|
56
|
-
logger.debug "before site.subscriptions.delete_all - count: #{site_rec.subscriptions.count}"
|
57
|
-
site_rec.subscriptions.destroy_all # note: use destroy_all NOT delete_all (delete_all tries by default only nullify)
|
58
|
-
logger.debug "after site.subscriptions.delete_all - count: #{site_rec.subscriptions.count}"
|
59
|
-
|
60
|
-
config.each do |key, value|
|
61
|
-
|
62
|
-
## todo: downcase key - why ??? why not???
|
63
|
-
|
64
|
-
# skip "top-level" feed keys e.g. title, etc. or planet planet sections (e.g. planet,defaults)
|
65
|
-
next if ['key','slug',
|
66
|
-
'title','name','name2','title2','subtitle',
|
67
|
-
'source', 'url',
|
68
|
-
'include','includes','exclude','excludes',
|
69
|
-
'feeds',
|
70
|
-
'author', 'owner', 'email',
|
71
|
-
'planet','defaults'].include?( key )
|
72
|
-
|
73
|
-
### todo/check:
|
74
|
-
## check value - must be hash
|
75
|
-
# check if url or feed_url present
|
76
|
-
# that is, check for required props/key-value pairs
|
77
|
-
|
78
|
-
feed_key = key.to_s.dup
|
79
|
-
feed_hash = value
|
80
|
-
|
81
|
-
# todo/fix: use title from feed?
|
82
|
-
# e.g. fill up auto_title, auto_url, etc.
|
83
|
-
|
84
|
-
feed_attribs = {
|
85
|
-
feed_url: feed_hash[ 'feed' ] || feed_hash[ 'feed_url' ] || feed_hash[ 'xml_url' ],
|
86
|
-
url: feed_hash[ 'link' ] || feed_hash[ 'url' ] || feed_hash[ 'html_url' ],
|
87
|
-
title: feed_hash[ 'title' ] || feed_hash[ 'name' ],
|
88
|
-
title2: feed_hash[ 'title2' ] || feed_hash[ 'name2' ] || feed_hash[ 'subtitle'],
|
89
|
-
includes: feed_hash[ 'includes' ] || feed_hash[ 'include' ],
|
90
|
-
excludes: feed_hash[ 'excludes' ] || feed_hash[ 'exclude' ],
|
91
|
-
author: feed_hash[ 'author' ] || feed_hash[ 'owner' ],
|
92
|
-
email: feed_hash[ 'email' ],
|
93
|
-
avatar: feed_hash[ 'avatar' ] || feed_hash[ 'face'],
|
94
|
-
github: feed_hash[ 'github' ],
|
95
|
-
twitter: feed_hash[ 'twitter' ],
|
96
|
-
## meetup: feed_hash[ 'meetup' ], -- remove from schema - virtual attrib ?? - why? why not??
|
97
|
-
}
|
98
|
-
feed_attribs[:encoding] = feed_hash['encoding']||feed_hash['charset'] if feed_hash['encoding']||feed_hash['charset']
|
99
|
-
|
100
|
-
#####
|
101
|
-
##
|
102
|
-
# auto-fill; convenience helpers
|
103
|
-
|
104
|
-
if feed_hash['meetup']
|
105
|
-
## link/url = http://www.meetup.com/vienna-rb
|
106
|
-
## feed/feed_url = http://www.meetup.com/vienna-rb/events/rss/vienna.rb/
|
107
|
-
|
108
|
-
feed_attribs[:url] = "http://www.meetup.com/#{feed_hash['meetup']}" if feed_attribs[:url].nil?
|
109
|
-
feed_attribs[:feed_url] = "http://www.meetup.com/#{feed_hash['meetup']}/events/rss/#{feed_hash['meetup']}/" if feed_attribs[:feed_url].nil?
|
110
|
-
end
|
111
|
-
|
112
|
-
if feed_hash['googlegroups']
|
113
|
-
## link/url = https://groups.google.com/group/beerdb or
|
114
|
-
## https://groups.google.com/forum/#!forum/beerdb
|
115
|
-
## feed/feed_url = https://groups.google.com/forum/feed/beerdb/topics/atom.xml?num=15
|
116
|
-
|
117
|
-
feed_attribs[:url] = "https://groups.google.com/group/#{feed_hash['googlegroups']}" if feed_attribs[:url].nil?
|
118
|
-
feed_attribs[:feed_url] = "https://groups.google.com/forum/feed//#{feed_hash['googlegroups']}/topics/atom.xml?num=15" if feed_attribs[:feed_url].nil?
|
119
|
-
end
|
120
|
-
|
121
|
-
if feed_hash['github'] && feed_hash['github'].index('/') ## e.g. jekyll/jekyll
|
122
|
-
## link/url = https://github.com/jekyll/jekyll
|
123
|
-
## feed/feed_url = https://github.com/jekyll/jekyll/commits/master.atom
|
124
|
-
|
125
|
-
feed_attribs[:url] = "https://github.com/#{feed_hash['github']}" if feed_attribs[:url].nil?
|
126
|
-
feed_attribs[:feed_url] = "https://github.com/#{feed_hash['github']}/commits/master.atom" if feed_attribs[:feed_url].nil?
|
127
|
-
end
|
128
|
-
|
129
|
-
if feed_hash['rubygems']
|
130
|
-
## link/url = http://rubygems.org/gems/jekyll
|
131
|
-
## feed/feed_url = http://rubygems.org/gems/jekyll/versions.atom
|
132
|
-
|
133
|
-
feed_attribs[:url] = "http://rubygems.org/gems/#{feed_hash['rubygems']}" if feed_attribs[:url].nil?
|
134
|
-
feed_attribs[:feed_url] = "http://rubygems.org/gems/#{feed_hash['rubygems']}/versions.atom" if feed_attribs[:feed_url].nil?
|
135
|
-
end
|
136
|
-
|
137
|
-
|
138
|
-
puts "Updating feed subscription >#{feed_key}< - >#{feed_attribs[:feed_url]}<..."
|
139
|
-
|
140
|
-
feed_rec = Feed.find_by_key( feed_key )
|
141
|
-
if feed_rec.nil?
|
142
|
-
feed_rec = Feed.new
|
143
|
-
feed_attribs[:key] = feed_key
|
144
|
-
|
145
|
-
## use object_id: feed.id and object_type: Feed
|
146
|
-
## change - model/table/schema!!!
|
147
|
-
## todo: add parent_action_id - why? why not?
|
148
|
-
Activity.create!( text: "new feed >#{feed_key}< - #{feed_attribs[:title]}" )
|
149
|
-
end
|
150
|
-
|
151
|
-
feed_rec.update_attributes!( feed_attribs )
|
152
|
-
|
153
|
-
# add subscription record
|
154
|
-
# note: subscriptions get cleaned out on update first (see above)
|
155
|
-
site_rec.subscriptions.create!( feed_id: feed_rec.id )
|
156
|
-
end
|
157
|
-
|
158
|
-
end # method update_subscriptions_for
|
159
|
-
|
160
|
-
end # class SiteUpdater
|
161
|
-
|
162
|
-
end # module Pluto
|
data/test/test_site.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_site.rb
|
6
|
-
# or better
|
7
|
-
# rake test
|
8
|
-
|
9
|
-
require 'helper'
|
10
|
-
|
11
|
-
class TestSite < MiniTest::Test
|
12
|
-
|
13
|
-
def setup
|
14
|
-
Site.delete_all
|
15
|
-
Feed.delete_all
|
16
|
-
Item.delete_all
|
17
|
-
Subscription.delete_all
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
def test_site_updater
|
22
|
-
site_text = File.read( "#{PlutoUpdate.root}/test/data/ruby.ini")
|
23
|
-
site_config = INI.load( site_text )
|
24
|
-
pp site_config
|
25
|
-
|
26
|
-
assert_equal 0, Site.count
|
27
|
-
assert_equal 0, Feed.count
|
28
|
-
|
29
|
-
site_updater = Pluto::SiteUpdater.new
|
30
|
-
site_updater.update_subscriptions_for( 'ruby', site_config )
|
31
|
-
|
32
|
-
assert_equal 1, Site.count
|
33
|
-
assert_equal 3, Feed.count
|
34
|
-
|
35
|
-
ruby = Site.find_by_key!( 'ruby' )
|
36
|
-
assert_equal 'Planet Ruby', ruby.title
|
37
|
-
assert_equal 3, ruby.subscriptions.count
|
38
|
-
assert_equal 3, ruby.feeds.count
|
39
|
-
|
40
|
-
rubylang = Feed.find_by_key!( 'rubylang' )
|
41
|
-
assert_equal 'Ruby Lang News', rubylang.title
|
42
|
-
assert_equal 'http://www.ruby-lang.org/en/news', rubylang.url
|
43
|
-
assert_equal 'http://www.ruby-lang.org/en/feeds/news.rss', rubylang.feed_url
|
44
|
-
end
|
45
|
-
|
46
|
-
end # class TestSite
|
47
|
-
|