Module: StreamGrabber

Defined in:
lib/stream_grabber.rb,
lib/stream_grabber/github.rb,
lib/stream_grabber/last_fm.rb,
lib/stream_grabber/twitter.rb

Defined Under Namespace

Classes: Engine, Github, LastFm, Twitter

Class Method Summary collapse

Class Method Details

.grab(n) ⇒ Object



40
41
42
# File 'lib/stream_grabber.rb', line 40

def grab(n)
  mux_stream.first(n)
end

.grab_allObject



36
37
38
# File 'lib/stream_grabber.rb', line 36

def grab_all
  mux_stream
end

.mux_streamObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stream_grabber.rb', line 22

def mux_stream
  messages = {}
  StreamGrabber.constants.each do |klass|
    k = StreamGrabber.const_get(klass)
    if k.instance_of?(Class) and k.method_defined?('last_five')
      name = k.name.partition('::').last.underscore.downcase
      user_name = set_config[name.to_sym]["username"]
      api_key = set_config[name.to_sym]["api_key"]
      messages.merge!(k.new(user_name, api_key).send(:last_five))
    end
  end
  arr = messages.sort.reverse
end

.set_configObject



16
17
18
19
20
# File 'lib/stream_grabber.rb', line 16

def set_config
  raw_config = File.read(Rails.root.to_s + "/config/stream_grabber.yml")
  @app_config ||= YAML.load(raw_config)
  @app_config
end