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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/pluto/models/site.rb', line 51
def deep_update_from_hash!( config, opts={} )
logger = LogUtils::Logger.root
site_attribs = {
title: config['title'] || config['name'], url: config['source'] || config['url'], author: config['author'] || config['owner'],
email: config['email'],
updated: Time.now, }
site_key = config['key'] || config['slug']
site_attribs[:key] = site_key if site_key
logger.debug "site_attribs: #{site_attribs.inspect}"
if new_record?
Activity.create!( text: "new site >#{key}< - #{title}" )
end
update!( site_attribs )
logger.debug "before site.subscriptions.delete_all - count: #{subscriptions.count}"
subscriptions.destroy_all
logger.debug "after site.subscriptions.delete_all - count: #{subscriptions.count}"
config.each do |k, v|
next if ['key','slug',
'title','name','name2','title2','subtitle',
'source', 'url',
'include','includes','exclude','excludes',
'feeds',
'author', 'owner', 'email',
'planet','defaults'].include?( k )
feed_key = k.to_s.dup
feed_hash = v
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' ],
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'],
location: feed_hash[ 'location' ],
github: feed_hash[ 'github' ],
twitter: feed_hash[ 'twitter' ],
rubygems: feed_hash[ 'rubygems' ],
meetup: feed_hash[ 'meetup' ], }
feed_attribs[:encoding] = feed_hash['encoding']||feed_hash['charset'] if feed_hash['encoding']||feed_hash['charset']
if feed_hash['meetup']
feed_attribs[:url] = "http://www.meetup.com/#{feed_hash['meetup']}" if feed_attribs[:url].nil?
feed_attribs[:feed_url] = "http://www.meetup.com/#{feed_hash['meetup']}/events/rss/#{feed_hash['meetup']}/" if feed_attribs[:feed_url].nil?
end
if feed_hash['googlegroups']
feed_attribs[:url] = "https://groups.google.com/group/#{feed_hash['googlegroups']}" if feed_attribs[:url].nil?
feed_attribs[:feed_url] = "https://groups.google.com/forum/feed//#{feed_hash['googlegroups']}/topics/atom.xml?num=15" if feed_attribs[:feed_url].nil?
end
if feed_hash['github'] && feed_hash['github'].index('/')
feed_attribs[:url] = "https://github.com/#{feed_hash['github']}" if feed_attribs[:url].nil?
feed_attribs[:feed_url] = "https://github.com/#{feed_hash['github']}/commits/master.atom" if feed_attribs[:feed_url].nil?
end
if feed_hash['rubygems'] && feed_attribs[:url].nil? && feed_attribs[:feed_url].nil?
feed_attribs[:url] = "http://rubygems.org/gems/#{feed_hash['rubygems']}" if feed_attribs[:url].nil?
feed_attribs[:feed_url] = "http://rubygems.org/gems/#{feed_hash['rubygems']}/versions.atom" if feed_attribs[:feed_url].nil?
end
logger.info "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!( feed_attribs )
subscriptions.create!( feed_id: feed_rec.id )
end
end
|