Class: Trelloid::Bot
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #add_task(task) ⇒ Object
- #behaviour(&blk) ⇒ Object
- #find_task(title) ⇒ Object
-
#initialize(api_key, token, options = {}) ⇒ Bot
constructor
A new instance of Bot.
- #run ⇒ Object
- #start_polling ⇒ Object
- #task(name, &blk) ⇒ Object
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, = {}) @api_key = api_key @token = token @tasks = [] @interval = .delete(:interval) || 30 @task_runners = TaskRunner.pool @client = Trello::Client.new( developer_public_key: @api_key, member_token: @token ) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
12 13 14 |
# File 'lib/trelloid.rb', line 12 def api_key @api_key end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
12 13 14 |
# File 'lib/trelloid.rb', line 12 def interval @interval end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
12 13 14 |
# File 'lib/trelloid.rb', line 12 def tasks @tasks end |
#token ⇒ Object (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 |
#run ⇒ Object
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_polling ⇒ Object
51 52 53 54 |
# File 'lib/trelloid.rb', line 51 def start_polling @poller = every(interval){poll} @poller.fire end |