Class: Scamp

Inherits:
Object
  • Object
show all
Includes:
Connection, Messages, Rooms, Users
Defined in:
lib/scamp/action.rb,
lib/scamp.rb,
lib/scamp/rooms.rb,
lib/scamp/users.rb,
lib/scamp/matcher.rb,
lib/scamp/version.rb,
lib/scamp/messages.rb,
lib/scamp/connection.rb

Overview

:created_at=>“2011/09/10 00:23:19 +0000”, :body=>“something”, :id=>408089344, :user_id=>774016, :type=>“TextMessage”

Defined Under Namespace

Modules: Connection, Messages, Rooms, Users Classes: Action, Matcher

Constant Summary collapse

VERSION =
"0.2.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Messages

#paste, #play, #say

Methods included from Users

#is_me?, #username_for

Methods included from Rooms

#join, #room_id, #room_name_for, #upload

Constructor Details

#initialize(options = {}) ⇒ Scamp

Returns a new instance of Scamp.

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/scamp.rb', line 24

def initialize(options = {})
  options ||= {}
  raise ArgumentError, "You must pass an API key" unless options[:api_key]
  raise ArgumentError, "You must pass a subdomain" unless options[:subdomain]

  options.each do |k,v|
    s = "#{k}="
    if respond_to?(s)
      send(s, v)
    else
      logger.warn "Scamp initialized with #{k.inspect} => #{v.inspect} but NO UNDERSTAND!"
    end
  end
  
  @rooms_to_join = []
  @rooms = {}
  @user_cache = {}
  @room_cache = {}
  @matchers ||= []
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



20
21
22
# File 'lib/scamp.rb', line 20

def api_key
  @api_key
end

#first_match_onlyObject

Returns the value of attribute first_match_only.



20
21
22
# File 'lib/scamp.rb', line 20

def first_match_only
  @first_match_only
end

#ignore_selfObject

Returns the value of attribute ignore_self.



20
21
22
# File 'lib/scamp.rb', line 20

def ignore_self
  @ignore_self
end

#loggerObject

Returns the value of attribute logger.



20
21
22
# File 'lib/scamp.rb', line 20

def logger
  @logger
end

#matchersObject

Returns the value of attribute matchers.



20
21
22
# File 'lib/scamp.rb', line 20

def matchers
  @matchers
end

#required_prefixObject

Returns the value of attribute required_prefix.



20
21
22
# File 'lib/scamp.rb', line 20

def required_prefix
  @required_prefix
end

#room_cacheObject

Returns the value of attribute room_cache.



20
21
22
# File 'lib/scamp.rb', line 20

def room_cache
  @room_cache
end

#roomsObject

Returns the value of attribute rooms.



20
21
22
# File 'lib/scamp.rb', line 20

def rooms
  @rooms
end

#rooms_to_joinObject

Returns the value of attribute rooms_to_join.



20
21
22
# File 'lib/scamp.rb', line 20

def rooms_to_join
  @rooms_to_join
end

#subdomainObject

Returns the value of attribute subdomain.



20
21
22
# File 'lib/scamp.rb', line 20

def subdomain
  @subdomain
end

#user_cacheObject

Returns the value of attribute user_cache.



20
21
22
# File 'lib/scamp.rb', line 20

def user_cache
  @user_cache
end

#verboseObject

Returns the value of attribute verbose.



20
21
22
# File 'lib/scamp.rb', line 20

def verbose
  @verbose
end

Instance Method Details

#behaviour(&block) ⇒ Object



45
46
47
# File 'lib/scamp.rb', line 45

def behaviour &block
  instance_eval &block
end

#command_listObject



54
55
56
# File 'lib/scamp.rb', line 54

def command_list
  matchers.map{|m| [m.trigger, m.conditions] }
end

#connect!(room_list) ⇒ Object



49
50
51
52
# File 'lib/scamp.rb', line 49

def connect!(room_list)
  logger.info "Starting up"
  connect(api_key, room_list)
end