Class: Pluto::Subscriber
- Inherits:
-
Object
- Object
- Pluto::Subscriber
- Includes:
- LogUtils::Logging, Models
- Defined in:
- lib/pluto/update/subscriber.rb
Instance Method Summary collapse
- #debug=(value) ⇒ Object
- #debug? ⇒ Boolean
- #update_subscriptions(config, opts = {}) ⇒ Object
- #update_subscriptions_for(site_key, config, opts = {}) ⇒ Object
Instance Method Details
#debug=(value) ⇒ Object
12 |
# File 'lib/pluto/update/subscriber.rb', line 12 def debug=(value) @debug = value; end |
#debug? ⇒ Boolean
13 |
# File 'lib/pluto/update/subscriber.rb', line 13 def debug?() @debug || false; end |
#update_subscriptions(config, opts = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/pluto/update/subscriber.rb', line 16 def update_subscriptions( config, opts={} ) # !!!! -- depreciated API - remove - do NOT use anymore puts "*** warn - [Pluto::Subscriber] depreciated API -- use update_subscriptions_for( site_key )" update_subscriptions_for( 'planet', config, opts ) # default to planet site_key end |
#update_subscriptions_for(site_key, config, opts = {}) ⇒ Object
23 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 |
# File 'lib/pluto/update/subscriber.rb', line 23 def update_subscriptions_for( site_key, config, opts={} ) site_attribs = { title: config['title'] || config['name'], # support either title or name url: config['source'] || config['url'] # support source or url for source url for auto-update (optional) } 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 ## use object_id: site.id and object_type: Site ## change - model/table/schema!!! Activity.create!( text: "new site >#{site_key}< - #{site_attribs[ :title ]}" ) end site_rec.update_attributes!( site_attribs ) # -- log update activity Activity.create!( text: "update subscriptions >#{site_key}<" ) # clean out subscriptions and add again logger.debug "before site.subscriptions.delete_all - count: #{site_rec.subscriptions.count}" site_rec.subscriptions.destroy_all # note: use destroy_all NOT delete_all (delete_all tries by default only nullify) logger.debug "after site.subscriptions.delete_all - count: #{site_rec.subscriptions.count}" config.each do |key, value| ## todo: downcase key - why ??? why not??? # skip "top-level" feed keys e.g. title, etc. or planet planet sections (e.g. planet,defaults) next if ['title','title2','name', 'source', 'url', 'include','includes','exclude','excludes', 'feeds', 'planet','defaults'].include?( key ) ### todo/check: ## check value - must be hash # check if url or feed_url present # that is, check for required props/key-value pairs feed_key = key.to_s.dup feed_hash = value # todo/fix: use title from feed? # e.g. fill up auto_title, auto_url, etc. feed_attribs = { feed_url: feed_hash[ 'feed' ] || feed_hash[ 'feed_url' ], url: feed_hash[ 'link' ] || feed_hash[ 'url' ], title: feed_hash[ 'title' ] || feed_hash[ 'name' ], title2: feed_hash[ 'title2' ], includes: feed_hash[ 'includes' ] || feed_hash[ 'include' ], excludes: feed_hash[ 'excludes' ] || feed_hash[ 'exclude' ], ## todo/future: add option for adding encoding - might not always be utf8 !!!! ## encoding: feed_hash[ 'encoding' ] || feed_hash[ 'charset' ] || 'utf8', ## default to utf8 } 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 ## use object_id: feed.id and object_type: Feed ## change - model/table/schema!!! ## todo: add parent_action_id - why? why not? Activity.create!( text: "new feed >#{feed_key}< - #{feed_attribs[ :title ]}" ) end feed_rec.update_attributes!( feed_attribs ) # add subscription record # note: subscriptions get cleaned out on update first (see above) site_rec.subscriptions.create!( feed_id: feed_rec.id ) end end |