Class: Heathrow::Sources::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/heathrow/sources/base.rb

Direct Known Subclasses

Instagram, Messenger, RSS, Webpage, Weechat

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config, db) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
# File 'lib/heathrow/sources/base.rb', line 6

def initialize(name, config, db)
  @name = name
  @config = config
  @db = db
  @type = self.class.name.split('::').last.downcase
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/heathrow/sources/base.rb', line 4

def config
  @config
end

#dbObject (readonly)

Returns the value of attribute db.



4
5
6
# File 'lib/heathrow/sources/base.rb', line 4

def db
  @db
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/heathrow/sources/base.rb', line 4

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/heathrow/sources/base.rb', line 4

def type
  @type
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/heathrow/sources/base.rb', line 21

def enabled?
  @config['enabled'] != false
end

#fetchObject

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/heathrow/sources/base.rb', line 13

def fetch
  raise NotImplementedError, "#{self.class} must implement #fetch"
end

#last_fetchObject



25
26
27
# File 'lib/heathrow/sources/base.rb', line 25

def last_fetch
  @config['last_fetch']
end

#poll_intervalObject



17
18
19
# File 'lib/heathrow/sources/base.rb', line 17

def poll_interval
  @config['poll_interval'] || 300
end

#save_configObject



34
35
36
37
38
39
40
# File 'lib/heathrow/sources/base.rb', line 34

def save_config
  source = @db.get_source_by_name(@name)
  if source
    sid = source['id'] || source[:id]
    @db.update_source(sid, config: @config.to_json) if sid
  end
end

#update_last_fetch(time = Time.now) ⇒ Object



29
30
31
32
# File 'lib/heathrow/sources/base.rb', line 29

def update_last_fetch(time = Time.now)
  @config['last_fetch'] = time.to_i
  save_config
end