Class: Trelloid::Bot

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/trelloid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, token, options = {}) ⇒ Bot

Returns a new instance of Bot.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/trelloid.rb', line 14

def initialize(api_key, token, options = {})
  @api_key = api_key
  @token = token
  @tasks = []
  @interval = options.delete(:interval) || 30
  @task_runners = TaskRunner.pool
  @client = Trello::Client.new(
    developer_public_key: @api_key,
    member_token: @token
  )
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



12
13
14
# File 'lib/trelloid.rb', line 12

def api_key
  @api_key
end

#intervalObject (readonly)

Returns the value of attribute interval.



12
13
14
# File 'lib/trelloid.rb', line 12

def interval
  @interval
end

#tasksObject (readonly)

Returns the value of attribute tasks.



12
13
14
# File 'lib/trelloid.rb', line 12

def tasks
  @tasks
end

#tokenObject (readonly)

Returns the value of attribute token.



12
13
14
# File 'lib/trelloid.rb', line 12

def token
  @token
end

Instance Method Details

#add_task(task) ⇒ Object



43
44
45
# File 'lib/trelloid.rb', line 43

def add_task(task)
  @tasks << task
end

#behaviour(&blk) ⇒ Object



35
36
37
# File 'lib/trelloid.rb', line 35

def behaviour(&blk)
  instance_eval(&blk)
end

#find_task(title) ⇒ Object



47
48
49
# File 'lib/trelloid.rb', line 47

def find_task(title)
 tasks.select{|t| t.match? title}.first
end

#runObject



26
27
28
29
30
31
32
33
# File 'lib/trelloid.rb', line 26

def run
  interrupted = false
  start_polling
  trap('INT'){interrupted = true}
  while !interrupted
    sleep 1
  end
end

#start_pollingObject



51
52
53
54
# File 'lib/trelloid.rb', line 51

def start_polling
  @poller = every(interval){poll}
  @poller.fire
end

#task(name, &blk) ⇒ Object



39
40
41
# File 'lib/trelloid.rb', line 39

def task(name, &blk)
  add_task(Task.new(name, &blk))
end