24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/pluto/update/subscriber.rb', line 24
def update_subscriptions_for( site_key, config, opts={} )
site_attribs = {
title: config['title'] || config['name'], url: config['source'] || config['url'], author: config['author'] || config['owner'],
email: config['email'],
updated: Time.now, }
logger.debug "site_attribs: #{site_attribs.inspect}"
site_rec = Site.find_by_key( site_key )
if site_rec.nil?
site_rec = Site.new
site_attribs[ :key ] = site_key
Activity.create!( text: "new site >#{site_key}< - #{site_attribs[ :title ]}" )
end
site_rec.update_attributes!( site_attribs )
Activity.create!( text: "update subscriptions >#{site_key}<" )
logger.debug "before site.subscriptions.delete_all - count: #{site_rec.subscriptions.count}"
site_rec.subscriptions.destroy_all logger.debug "after site.subscriptions.delete_all - count: #{site_rec.subscriptions.count}"
config.each do |key, value|
next if ['title','name','name2','title2','subtitle',
'source', 'url',
'include','includes','exclude','excludes',
'feeds',
'author', 'owner', 'email',
'planet','defaults'].include?( key )
feed_key = key.to_s.dup
feed_hash = value
feed_attribs = {
feed_url: feed_hash[ 'feed' ] || feed_hash[ 'feed_url' ] || feed_hash[ 'xml_url' ],
url: feed_hash[ 'link' ] || feed_hash[ 'url' ] || feed_hash[ 'html_url' ],
title: feed_hash[ 'title' ] || feed_hash[ 'name' ],
title2: feed_hash[ 'title2' ] || feed_hash[ 'name2' ] || feed_hash[ 'subtitle'],
includes: feed_hash[ 'includes' ] || feed_hash[ 'include' ],
excludes: feed_hash[ 'excludes' ] || feed_hash[ 'exclude' ],
author: feed_hash[ 'author' ] || feed_hash[ 'owner' ],
email: feed_hash[ 'email' ],
avatar: feed_hash[ 'avatar' ] || feed_hash[ 'face'],
github: feed_hash[ 'github' ],
twitter: feed_hash[ 'twitter' ],
meetup: feed_hash[ 'meetup' ],
}
feed_attribs[:encoding] = feed_hash['encoding']||feed_hash['charset'] if feed_hash['encoding']||feed_hash['charset']
puts "Updating feed subscription >#{feed_key}< - >#{feed_attribs[:feed_url]}<..."
feed_rec = Feed.find_by_key( feed_key )
if feed_rec.nil?
feed_rec = Feed.new
feed_attribs[:key] = feed_key
Activity.create!( text: "new feed >#{feed_key}< - #{feed_attribs[:title]}" )
end
feed_rec.update_attributes!( feed_attribs )
site_rec.subscriptions.create!( feed_id: feed_rec.id )
end
end
|