Class: Cinch::Plugins::GithubNotifications::Checker
- Inherits:
-
Object
- Object
- Cinch::Plugins::GithubNotifications::Checker
- Defined in:
- lib/cinch/plugins/github_notifications/checker.rb
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Checker
constructor
A new instance of Checker.
- #start ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Checker
Returns a new instance of Checker.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cinch/plugins/github_notifications/checker.rb', line 13 def initialize(args = {}) raise RuntimeError, "args[:bot] must be a cinch bot" unless args[:bot].is_a?(Cinch::Bot) @cinch_bot = args[:bot] @sequence = args[:sequence] || "cinch-github-event.seq" if args[:github_enterprise] $stdout.puts "Using github enterprise at #{args[:github_enterprise]}" Octokit.configure do |c| c.api_endpoint = URI.join(args[:github_enterprise],"api/v3").to_s c.web_endpoint = args[:github_enterprise] end else p args end @octoclient ||= Octokit::Client.new(args[:github_credentials] || {}) end |
Instance Method Details
#start ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cinch/plugins/github_notifications/checker.rb', line 31 def start @thread = Thread.new do begin loop do # Get the latest public events, and @octoclient.public_events.reverse.each do |gh_event| if gh_event['id'].to_i > get_seq @cinch_bot.handlers.dispatch(:github_event, nil, gh_event) set_seq(gh_event['id']) end end sleep 60 end rescue Octokit:: => e $stderr.puts "Github credentials are incorrect." end end @thread.abort_on_exception = true end |