Sha256: 33b8d9abaebddfda905b7c1068a12b512b6b374ab0b74d0223551ef6f772d985

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'eventmachine'
require 'em-http-request'
require 'yajl'

require "scamp/version"
require 'scamp/connection'
require 'scamp/channels'
require 'scamp/users'
require 'scamp/matcher'
require 'scamp/action'

class Scamp
  include Connection
  include Channels
  include Users
  
  attr_accessor :channels, :user_cache, :channel_cache
  attr :matchers, :api_key

  def initialize(options = {})
    options ||= {}
    raise ArgumentError, "You must pass an API key" unless options[:api_key]
    
    @api_key = options[:api_key]
    @channels = {}
    @user_cache = {}
    @channel_cache = {}
    @matchers ||= []
  end
  
  def behaviour &block
    instance_eval &block
  end
  
  def connect!(channel_list)
    connect(api_key, channel_list)
  end
  
  private
  
  def match trigger, params={}, &block
    params ||= {}
    matchers << Matcher.new(self, {:trigger => trigger, :action => block, :conditions => params[:conditions]})
  end
  
  def process_message(msg)
    matchers.each do |matcher|
      matcher.attempt(msg)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scamp-0.0.1 lib/scamp.rb