lib/ghn.rb in ghn-0.0.1 vs lib/ghn.rb in ghn-0.0.2
- old
+ new
@@ -1,19 +1,34 @@
-require "ghn/version"
+require 'ghn/version'
+require 'ghn/token'
+require 'ghn/options'
+require 'ghn/command'
require 'github_api'
class Ghn
- attr_accessor :open_browser, :mark_as_read
- alias_method :open_browser?, :open_browser
- alias_method :mark_as_read?, :mark_as_read
+ def initialize(token, command, options)
+ @token = token
+ @command = command
+ @options = options
+ end
- def initialize(access_token)
- @access_token = access_token
+ def run
+ send(@command.command, *@command.args)
end
+ def run_print
+ run.each do |notification|
+ if @options.open_browser?
+ system "open #{notification}"
+ else
+ puts notification
+ end
+ end
+ end
+
def client
- @client ||= Github.new(oauth_token: @access_token)
+ @client ||= Github.new(oauth_token: @token.token)
end
def list(target = nil)
params = {}
unless target.nil?
@@ -25,10 +40,10 @@
type, number = if notification.subject.url.match(/pulls/)
['pull', notification.subject.url.match(/[^\/]+\z/).to_a.first]
else
['issues', notification.subject.url.match(/[^\/]+\z/).to_a.first]
end
- if mark_as_read?
+ if @options.mark_as_read?
self.mark(notification.id)
"[x] https://github.com/#{repo}/#{type}/#{number}"
else
"https://github.com/#{repo}/#{type}/#{number}"
end